public static void SaveHostData(MCMHost host) { var filePath = HostFilePath(host); // Open it for writing try { Scribe.InitWriting(filePath, "ModConfigurationData"); if (Scribe.mode == LoadSaveMode.Saving) { // Write this library version as the one saved with string version = Version.Current.ToString(); Scribe_Values.LookValue <string>(ref version, "ccl_version"); // Call the worker scribe Scribe_Deep.LookDeep <MCMHost>(ref host, host.key); } } catch (Exception e) { CCL_Log.Trace( Verbosity.NonFatalErrors, string.Format("Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString()), "Mod Configuration Menu"); } finally { // Finish Scribe.FinalizeWriting(); Scribe.mode = LoadSaveMode.Inactive; Messages.Message("ModConfigurationSaved".Translate(host.Label), MessageSound.Standard); } host.OpenedThisSession = false; }
public void ExposeData() { if (worker == null) { CCL_Log.Trace( Verbosity.FatalErrors, string.Format("worker is null in MCMHost for {0}", Label), "Mod Configuration Menu"); return; } // Call the worker expose data worker.ExposeData(); }
public static Pawn_DrawTracker GetPawnDrawTracker(this Pawn pawn) { if (_GetPawnDrawTracker == null) { _GetPawnDrawTracker = typeof(Pawn).GetField("drawer", BindingFlags.Instance | BindingFlags.NonPublic); if (_GetPawnDrawTracker == null) { CCL_Log.Trace( Verbosity.FatalErrors, "Unable to get 'drawer' in class 'Pawn'", "CommunityCoreLibrary.Detour.JobDriver_SocialRelax"); return(null); } } return((Pawn_DrawTracker)_GetPawnDrawTracker.GetValue(pawn)); }
public static void LoadHostData(MCMHost host) { var filePath = HostFilePath(host); if (!File.Exists(filePath)) { return; } try { // Open it for reading Scribe.InitLoading(filePath); if (Scribe.mode == LoadSaveMode.LoadingVars) { // Version check string version = ""; Scribe_Values.LookValue <string>(ref version, "ccl_version"); bool okToLoad = true; var result = Version.Compare(version); if (result == Version.VersionCompare.GreaterThanMax) { CCL_Log.Trace( Verbosity.NonFatalErrors, string.Format("Data for {0} is newer ({1}) than the version you are using ({2}).", host.Label, version, Version.Current.ToString()), "Mod Configuration Menu"); okToLoad = false; } else if (result == Version.VersionCompare.Invalid) { CCL_Log.Trace( Verbosity.NonFatalErrors, string.Format("Data for {0} is corrupt and will be discarded", host.Label), "Mod Configuration Menu"); okToLoad = false; } if (okToLoad) { // Call the worker scribe var args = new object[] { host.Label, host.worker }; Scribe_Deep.LookDeep <MCMHost>(ref host, host.key, args); } } } catch (Exception e) { CCL_Log.Trace( Verbosity.NonFatalErrors, string.Format("Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString()), "Mod Configuration Menu"); } finally { // Finish Scribe.FinalizeLoading(); Scribe.mode = LoadSaveMode.Inactive; } }
void DrawDisplayArea(Rect rect) { Widgets.DrawMenuSection(rect); if (SelectedHost == null) { return; } if ( (PreviouslySelectedHost != null) && (PreviouslySelectedHost != SelectedHost) ) { PreviouslySelectedHost.worker.PostClose(); } if (PreviouslySelectedHost != SelectedHost) { SelectedHost.OpenedThisSession = true; SelectedHost.worker.PreOpen(); } PreviouslySelectedHost = SelectedHost; Text.Font = GameFont.Medium; Text.WordWrap = false; var titleRect = new Rect(rect.xMin, rect.yMin, rect.width, 60f); Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(titleRect, SelectedHost.Label); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = true; Rect outRect = rect.ContractedBy(Margin); outRect.yMin += 60f; Rect viewRect = outRect; viewRect.width -= 16f; viewRect.height = ContentHeight; GUI.BeginGroup(outRect); Widgets.BeginScrollView(outRect.AtZero(), ref DisplayScrollPos, viewRect.AtZero()); bool userError = false; string userErrorStr = string.Empty; try { ContentHeight = SelectedHost.worker.DoWindowContents(viewRect.AtZero()); } catch (Exception e) { userError = true; userErrorStr = e.ToString(); } Widgets.EndScrollView(); GUI.EndGroup(); if (userError) { CCL_Log.Trace( Verbosity.NonFatalErrors, userErrorStr, "Mod Configuration Menu" ); } }
public override bool Inject() { #if DEVELOPER DumpAllTypesFieldsPropertiesAndMethods(); #endif // Make sure custom doors are region barriers FixDoors(); // Change CompGlower into CompGlowerToggleable FixGlowers(); // Detour Verse.GenSpawn.CanPlaceBlueprintOver MethodInfo Verse_GenSpawn_CanPlaceBlueprintOver = typeof(GenSpawn).GetMethod("CanPlaceBlueprintOver", BindingFlags.Static | BindingFlags.Public); MethodInfo CCL_GenSpawn_CanPlaceBlueprintOver = typeof(Detour._GenSpawn).GetMethod("_CanPlaceBlueprintOver", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_GenSpawn_CanPlaceBlueprintOver, CCL_GenSpawn_CanPlaceBlueprintOver)) { return(false); } // Detour Verse.RegionMaker.CheckRegionableAndProcessNeighbor Detour._RegionMaker._TryMakePortalSpan = typeof(RegionMaker).GetMethod("TryMakePortalSpan", BindingFlags.Static | BindingFlags.NonPublic); #if DEBUG if (Detour._RegionMaker._TryMakePortalSpan == null) { CCL_Log.Error("Unable to find 'Verse.RegionMaker.TryMakePortalScan'"); return(false); } #endif MethodInfo Verse_RegionMaker_CheckRegionableAndProcessNeighbor = typeof(RegionMaker).GetMethod("CheckRegionableAndProcessNeighbor", BindingFlags.Static | BindingFlags.NonPublic, null, new [] { typeof(IntVec3), typeof(Rot4) }, null); MethodInfo CCL_RegionMaker_CheckRegionableAndProcessNeighbor = typeof(Detour._RegionMaker).GetMethod("_CheckRegionableAndProcessNeighbor", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_RegionMaker_CheckRegionableAndProcessNeighbor, CCL_RegionMaker_CheckRegionableAndProcessNeighbor)) { return(false); } // Detour RimWorld.TargetingParameters.CanTarget MethodInfo RimWorld_TargetingParameters_CanTarget = typeof(TargetingParameters).GetMethod("CanTarget", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_TargetingParameters_CanTarget = typeof(Detour._TargetingParameters).GetMethod("_CanTarget", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_TargetingParameters_CanTarget, CCL_TargetingParameters_CanTarget)) { return(false); } // Detour RimWorld.GenPlant.CanEverPlantAt MethodInfo RimWorld_GenPlant_CanEverPlantAt = typeof(GenPlant).GetMethod("CanEverPlantAt", BindingFlags.Static | BindingFlags.Public); MethodInfo CCL_GenPlant_CanEverPlantAt = typeof(Detour._GenPlant).GetMethod("_CanEverPlantAt", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_GenPlant_CanEverPlantAt, CCL_GenPlant_CanEverPlantAt)) { return(false); } // Detour RimWorld.StatWorker.ShouldShowFor MethodInfo RimWorld_StatWorker_ShouldShowFor = typeof(StatWorker).GetMethod("ShouldShowFor", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_StatWorker_ShouldShowFor = typeof(Detour._StatWorker).GetMethod("_ShouldShowFor", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_StatWorker_ShouldShowFor, CCL_StatWorker_ShouldShowFor)) { return(false); } // Detour Verse.SectionLayer_IndoorMask.Regenerate Type Verse_Sectionlayer_IndoorMask = Controller.Data.Assembly_CSharp.GetType("Verse.SectionLayer_IndoorMask"); #if DEBUG if (Verse_Sectionlayer_IndoorMask == null) { CCL_Log.Error("Unable to find 'Verse.Sectionlayer_IndoorMask'"); return(false); } #endif Detour._SectionLayer_IndoorMask._HideRainPrimary = Verse_Sectionlayer_IndoorMask.GetMethod("HideRainPrimary", BindingFlags.Instance | BindingFlags.NonPublic); #if DEBUG if (Detour._SectionLayer_IndoorMask._HideRainPrimary == null) { CCL_Log.Error("Unable to find 'Verse.Sectionlayer_IndoorMask.HideRainPrimary'"); return(false); } #endif MethodInfo Verse_SectionLayer_IndoorMask_Regenerate = Verse_Sectionlayer_IndoorMask.GetMethod("Regenerate", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_SectionLayer_IndoorMask_Regenerate = typeof(Detour._SectionLayer_IndoorMask).GetMethod("_Regenerate", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_SectionLayer_IndoorMask_Regenerate, CCL_SectionLayer_IndoorMask_Regenerate)) { return(false); } // Detour RimWorld.Building_Door.AlignQualityAgainst MethodInfo RimWorld_Building_Door_AlignQualityAgainst = typeof(Building_Door).GetMethod("AlignQualityAgainst", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo CCL_Building_Door_AlignQualityAgainst = typeof(Detour._Building_Door).GetMethod("_AlignQualityAgainst", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_Building_Door_AlignQualityAgainst, CCL_Building_Door_AlignQualityAgainst)) { return(false); } // Detour Verse.GhostDrawer.GhostGraphicFor MethodInfo Verse_GhostDrawer_GhostGraphicFor = typeof(GhostDrawer).GetMethod("GhostGraphicFor", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo CCL_GhostDrawer_GhostGraphicFor = typeof(Detour._GhostDrawer).GetMethod("_GhostGraphicFor", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_GhostDrawer_GhostGraphicFor, CCL_GhostDrawer_GhostGraphicFor)) { return(false); } // Detour Verse.GenPlace.PlaceSpotQualityAt MethodInfo Verse_GenPlace_PlaceSpotQualityAt = typeof(GenPlace).GetMethod("PlaceSpotQualityAt", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo CCL_GenPlace_PlaceSpotQualityAt = typeof(Detour._GenPlace).GetMethod("_PlaceSpotQualityAt", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_GenPlace_PlaceSpotQualityAt, CCL_GenPlace_PlaceSpotQualityAt)) { return(false); } // Detour RimWorld.JobGiver_Binge.DrinkAlcoholJob MethodInfo RimWorld_JobGiver_Binge_DrinkAlcoholJob = typeof(JobGiver_Binge).GetMethod("DrinkAlcoholJob", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo CCL_JobGiver_Binge_DrinkAlcoholJob = typeof(Detour._JobGiver_Binge).GetMethod("_DrinkAlcoholJob", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_JobGiver_Binge_DrinkAlcoholJob, CCL_JobGiver_Binge_DrinkAlcoholJob)) { return(false); } // Detour Verse.BrokenStateWorker_Binging.StateCanOccur MethodInfo Verse_BrokenStateWorker_Binging_StateCanOccur = typeof(MentalStateWorker_Binging).GetMethod("StateCanOccur", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_BrokenStateWorker_Binging_StateCanOccur = typeof(Detour._MentalStateWorker_Binging).GetMethod("_StateCanOccur", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_BrokenStateWorker_Binging_StateCanOccur, CCL_BrokenStateWorker_Binging_StateCanOccur)) { return(false); } // Detour RimWorld.JoyGiver_SocialRelax.TryGiveJobInt MethodInfo RimWorld_JoyGiver_SocialRelax_TryGiveJobInt = typeof(JoyGiver_SocialRelax).GetMethod("TryGiveJobInt", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_JoyGiver_SocialRelax_TryGiveJobInt = typeof(Detour._JoyGiver_SocialRelax).GetMethod("_TryGiveJobInt", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_JoyGiver_SocialRelax_TryGiveJobInt, CCL_JoyGiver_SocialRelax_TryGiveJobInt)) { return(false); } // Detour RimWorld.ThingSelectionUtility.SelectableNow MethodInfo RimWorld_ThingSelectionUtility_SelectableNow = typeof(ThingSelectionUtility).GetMethod("SelectableNow", BindingFlags.Static | BindingFlags.Public); MethodInfo CCL_ThingSelectionUtility_SelectableNow = typeof(Detour._ThingSelectionUtility).GetMethod("_SelectableNow", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_ThingSelectionUtility_SelectableNow, CCL_ThingSelectionUtility_SelectableNow)) { return(false); } // Detour RimWorld.DropCellFinder.TradeDropSpot MethodInfo RimWorld_DropCellFinder_TradeDropSpot = typeof(DropCellFinder).GetMethod("TradeDropSpot", BindingFlags.Static | BindingFlags.Public); MethodInfo CCL_DropCellFinder_TradeDropSpot = typeof(Detour._DropCellFinder).GetMethod("_TradeDropSpot", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_DropCellFinder_TradeDropSpot, CCL_DropCellFinder_TradeDropSpot)) { return(false); } // Detour RimWorld.PassingShip.Depart MethodInfo RimWorld_PassingShop_Depart = typeof(PassingShip).GetMethod("Depart", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_PassingShop_Depart = typeof(Detour._PassingShip).GetMethod("_Depart", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_PassingShop_Depart, CCL_PassingShop_Depart)) { return(false); } // Detour RimWorld.FoodUtility.BestFoodSourceFor MethodInfo RimWorld_FoodUtility_BestFoodSourceFor = typeof(FoodUtility).GetMethod("BestFoodSourceFor", BindingFlags.Static | BindingFlags.Public); MethodInfo CCL_FoodUtility_BestFoodSourceFor = typeof(Detour._FoodUtility).GetMethod("_BestFoodSourceFor", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_FoodUtility_BestFoodSourceFor, CCL_FoodUtility_BestFoodSourceFor)) { return(false); } // Detour RimWorld.FoodUtility.NutritionAvailableFromFor MethodInfo RimWorld_FoodUtility_NutritionAvailableFromFor = typeof(FoodUtility).GetMethod("NutritionAvailableFromFor", BindingFlags.Static | BindingFlags.Public); MethodInfo CCL_FoodUtility_NutritionAvailableFromFor = typeof(Detour._FoodUtility).GetMethod("_NutritionAvailableFromFor", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_FoodUtility_NutritionAvailableFromFor, CCL_FoodUtility_NutritionAvailableFromFor)) { return(false); } // Detour RimWorld.Building_NutrientPasteDispenser.AdjacentReachableHopper MethodInfo RimWorld_Building_NutrientPasteDispenser_AdjacentReachableHopper = typeof(Building_NutrientPasteDispenser).GetMethod("AdjacentReachableHopper", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_Building_NutrientPasteDispenser_AdjacentReachableHopper = typeof(Detour._Building_NutrientPasteDispenser).GetMethod("_AdjacentReachableHopper", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_Building_NutrientPasteDispenser_AdjacentReachableHopper, CCL_Building_NutrientPasteDispenser_AdjacentReachableHopper)) { return(false); } // Detour RimWorld.Building_NutrientPasteDispenser.FindFeedInAnyHopper MethodInfo RimWorld_Building_NutrientPasteDispenser_FindFeedInAnyHopper = typeof(Building_NutrientPasteDispenser).GetMethod("FindFeedInAnyHopper", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_Building_NutrientPasteDispenser_FindFeedInAnyHopper = typeof(Detour._Building_NutrientPasteDispenser).GetMethod("_FindFeedInAnyHopper", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_Building_NutrientPasteDispenser_FindFeedInAnyHopper, CCL_Building_NutrientPasteDispenser_FindFeedInAnyHopper)) { return(false); } // Detour RimWorld.Building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers MethodInfo RimWorld_Building_NutrientPasteDispenser_HasEnoughFeedstockInHoppers = typeof(Building_NutrientPasteDispenser).GetMethod("HasEnoughFeedstockInHoppers", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_Building_NutrientPasteDispenser_HasEnoughFeedstockInHoppers = typeof(Detour._Building_NutrientPasteDispenser).GetMethod("_HasEnoughFeedstockInHoppers", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_Building_NutrientPasteDispenser_HasEnoughFeedstockInHoppers, CCL_Building_NutrientPasteDispenser_HasEnoughFeedstockInHoppers)) { return(false); } // Detour RimWorld.JobDriver_FoodDeliver.MakeNewToils MethodInfo RimWorld_JobDriver_FoodDeliver_MakeNewToils = typeof(JobDriver_FoodDeliver).GetMethod("MakeNewToils", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_JobDriver_FoodDeliver_MakeNewToils = typeof(Detour._JobDriver_FoodDeliver).GetMethod("_MakeNewToils", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_FoodDeliver_MakeNewToils, CCL_JobDriver_FoodDeliver_MakeNewToils)) { return(false); } // Detour RimWorld.JobDriver_FoodFeedPatient.MakeNewToils MethodInfo RimWorld_JobDriver_FoodFeedPatient_MakeNewToils = typeof(JobDriver_FoodFeedPatient).GetMethod("MakeNewToils", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_JobDriver_FoodFeedPatient_MakeNewToils = typeof(Detour._JobDriver_FoodFeedPatient).GetMethod("_MakeNewToils", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_FoodFeedPatient_MakeNewToils, CCL_JobDriver_FoodFeedPatient_MakeNewToils)) { return(false); } // Detour RimWorld.JobDriver_Ingest.MakeNewToils MethodInfo RimWorld_JobDriver_Ingest_MakeNewToils = typeof(JobDriver_Ingest).GetMethod("MakeNewToils", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_JobDriver_Ingest_MakeNewToils = typeof(Detour._JobDriver_Ingest).GetMethod("_MakeNewToils", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_Ingest_MakeNewToils, CCL_JobDriver_Ingest_MakeNewToils)) { return(false); } // Detour RimWorld.JobGiver_GetFood.TryGiveTerminalJob MethodInfo RimWorld_JobGiver_GetFood_TryGiveTerminalJob = typeof(JobGiver_GetFood).GetMethod("TryGiveTerminalJob", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_JobGiver_GetFood_TryGiveTerminalJob = typeof(Detour._JobGiver_GetFood).GetMethod("_TryGiveTerminalJob", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_JobGiver_GetFood_TryGiveTerminalJob, CCL_JobGiver_GetFood_TryGiveTerminalJob)) { return(false); } // Detour RimWorld.JobDriver_SocialRelax.MakeNewToils MethodInfo RimWorld_JobDriver_SocialRelax_MakeNewToils = typeof(JobDriver_SocialRelax).GetMethod("MakeNewToils", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo CCL_JobDriver_SocialRelax_MakeNewToils = typeof(Detour._JobDriver_SocialRelax).GetMethod("_MakeNewToils", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_SocialRelax_MakeNewToils, CCL_JobDriver_SocialRelax_MakeNewToils)) { return(false); } // Detour RimWorld.CompRottable.CompTickRare MethodInfo RimWorld_CompRottable_CompTickRare = typeof(CompRottable).GetMethod("CompTickRare", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_CompRottable_CompTickRare = typeof(Detour._CompRottable).GetMethod("_CompTickRare", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_CompRottable_CompTickRare, CCL_CompRottable_CompTickRare)) { return(false); } // Detour RimWorld.CompRottable.CompInspectStringExtra MethodInfo RimWorld_CompRottable_CompInspectStringExtra = typeof(CompRottable).GetMethod("CompInspectStringExtra", BindingFlags.Instance | BindingFlags.Public); MethodInfo CCL_CompRottable_CompInspectStringExtra = typeof(Detour._CompRottable).GetMethod("_CompInspectStringExtra", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_CompRottable_CompInspectStringExtra, CCL_CompRottable_CompInspectStringExtra)) { return(false); } // Detour Verse.CompHeatPusherPowered.ShouldPushHeatNow PropertyInfo Verse_CompHeatPusherPowered_ShouldPushHeatNow = typeof(CompHeatPusherPowered).GetProperty("ShouldPushHeatNow", BindingFlags.Instance | BindingFlags.NonPublic); #if DEBUG if (Verse_CompHeatPusherPowered_ShouldPushHeatNow == null) { CCL_Log.Error("Unable to find 'Verse.CompHeatPusherPowered.ShouldPushHeatNow'"); return(false); } #endif MethodInfo Verse_CompHeatPusherPowered_ShouldPushHeatNow_Getter = Verse_CompHeatPusherPowered_ShouldPushHeatNow.GetGetMethod(true); MethodInfo CCL_CompHeatPusherPowered_ShouldPushHeatNow = typeof(Detour._CompHeatPusherPowered).GetMethod("_ShouldPushHeatNow", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_CompHeatPusherPowered_ShouldPushHeatNow_Getter, CCL_CompHeatPusherPowered_ShouldPushHeatNow)) { return(false); } // Detour Verse.CompGlower.ShouldBeLitNow PropertyInfo Verse_CompGlower_ShouldBeLitNow = typeof(CompGlower).GetProperty("ShouldBeLitNow", BindingFlags.Instance | BindingFlags.NonPublic); #if DEBUG if (Verse_CompGlower_ShouldBeLitNow == null) { CCL_Log.Error("Unable to find 'Verse.CompGlower.ShouldBeLitNow'"); return(false); } #endif MethodInfo Verse_CompGlower_ShouldBeLitNow_Getter = Verse_CompGlower_ShouldBeLitNow.GetGetMethod(true); MethodInfo CCL_CompGlower_ShouldBeLitNow = typeof(Detour._CompGlower).GetMethod("_ShouldBeLitNow", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(Verse_CompGlower_ShouldBeLitNow_Getter, CCL_CompGlower_ShouldBeLitNow)) { return(false); } // Detour RimWorld.MainTabWindow_Research.DrawLeftRect "NotFinished" predicate function // Use build number to get the correct predicate function var RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name = string.Empty; var RimWorld_Build = RimWorld.VersionControl.CurrentBuild; switch (RimWorld_Build) { case 1135: RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name = "<DrawLeftRect>m__3E9"; break; default: CCL_Log.Trace( Verbosity.Warnings, "CCL needs updating for RimWorld build " + RimWorld_Build.ToString()); break; } if (RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name != string.Empty) { MethodInfo RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished = typeof(RimWorld.MainTabWindow_Research).GetMethod(RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name, BindingFlags.Static | BindingFlags.NonPublic); MethodInfo CCL_MainTabWindow_Research_DrawLeftRect_NotFinishedNotLockedOut = typeof(Detour._MainTabWindow_Research).GetMethod("_NotFinishedNotLockedOut", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished, CCL_MainTabWindow_Research_DrawLeftRect_NotFinishedNotLockedOut)) { return(false); } } // Detour RimWorld.SocialProperness.IsSociallyProper MethodInfo RimWorld_SocialProperness_IsSociallyProper = typeof(SocialProperness).GetMethods().First <MethodInfo>((arg) => ( (arg.Name == "IsSociallyProper") && (arg.GetParameters().Count() == 4) )); MethodInfo CCL_SocialProperness_IsSociallyProper = typeof(Detour._SocialProperness).GetMethod("_IsSociallyProper", BindingFlags.Static | BindingFlags.NonPublic); if (!Detours.TryDetourFromTo(RimWorld_SocialProperness_IsSociallyProper, CCL_SocialProperness_IsSociallyProper)) { return(false); } /* * // Detour * MethodInfo foo = typeof( foo_class ).GetMethod( "foo_method", BindingFlags.Static | BindingFlags.NonPublic ); * MethodInfo CCL_bar = typeof( Detour._bar ).GetMethod( "_bar_method", BindingFlags.Static | BindingFlags.NonPublic ); * if( !Detours.TryDetourFromTo( foo, CCL_bar ) ) * return false; * */ return(true); }
public override bool Inject() { // Change CompGlower into CompGlowerToggleable FixGlowers(); // Change Building_NutrientPasteDispenser into Building_AdvancedPasteDispenser UpgradeNutrientPasteDispensers(); // Detour RimWorld.JoyGiver_SocialRelax.TryGiveJobInt MethodInfo RimWorld_JoyGiver_SocialRelax_TryGiveJobInt = typeof(JoyGiver_SocialRelax).GetMethod("TryGiveJobInt", UniversalBindingFlags); MethodInfo CCL_JoyGiver_SocialRelax_TryGiveJobInt = typeof(Detour._JoyGiver_SocialRelax).GetMethod("_TryGiveJobInt", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JoyGiver_SocialRelax_TryGiveJobInt, CCL_JoyGiver_SocialRelax_TryGiveJobInt)) { return(false); } // Detour RimWorld.ThingSelectionUtility.SelectableNow MethodInfo RimWorld_ThingSelectionUtility_SelectableNow = typeof(ThingSelectionUtility).GetMethod("SelectableNow", UniversalBindingFlags); MethodInfo CCL_ThingSelectionUtility_SelectableNow = typeof(Detour._ThingSelectionUtility).GetMethod("_SelectableNow", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_ThingSelectionUtility_SelectableNow, CCL_ThingSelectionUtility_SelectableNow)) { return(false); } // Detour RimWorld.FoodUtility.GetFoodDef MethodInfo RimWorld_FoodUtility_GetFoodDef = typeof(FoodUtility).GetMethod("GetFoodDef", UniversalBindingFlags); MethodInfo CCL_FoodUtility_GetFoodDef = typeof(Detour._FoodUtility).GetMethod("_GetFoodDef", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_FoodUtility_GetFoodDef, CCL_FoodUtility_GetFoodDef)) { return(false); } // Detour RimWorld.FoodUtility.FoodSourceOptimality MethodInfo RimWorld_FoodUtility_FoodSourceOptimality = typeof(FoodUtility).GetMethod("FoodSourceOptimality", UniversalBindingFlags); MethodInfo CCL_FoodUtility_FoodSourceOptimality = typeof(Detour._FoodUtility).GetMethod("_FoodSourceOptimality", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_FoodUtility_FoodSourceOptimality, CCL_FoodUtility_FoodSourceOptimality)) { return(false); } // Detour RimWorld.FoodUtility.ThoughtsFromIngesting MethodInfo RimWorld_FoodUtility_ThoughtsFromIngesting = typeof(FoodUtility).GetMethod("ThoughtsFromIngesting", UniversalBindingFlags); MethodInfo CCL_FoodUtility_ThoughtsFromIngesting = typeof(Detour._FoodUtility).GetMethod("_ThoughtsFromIngesting", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_FoodUtility_ThoughtsFromIngesting, CCL_FoodUtility_ThoughtsFromIngesting)) { return(false); } // Detour RimWorld.FoodUtility.BestFoodSourceOnMap MethodInfo RimWorld_FoodUtility_BestFoodSourceOnMap = typeof(FoodUtility).GetMethod("BestFoodSourceOnMap", UniversalBindingFlags); MethodInfo CCL_FoodUtility_BestFoodSourceOnMap = typeof(Detour._FoodUtility).GetMethod("_BestFoodSourceOnMap", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_FoodUtility_BestFoodSourceOnMap, CCL_FoodUtility_BestFoodSourceOnMap)) { return(false); } // Detour RimWorld.JobDriver_FoodDeliver.MakeNewToils MethodInfo RimWorld_JobDriver_FoodDeliver_MakeNewToils = typeof(JobDriver_FoodDeliver).GetMethod("MakeNewToils", UniversalBindingFlags); MethodInfo CCL_JobDriver_FoodDeliver_MakeNewToils = typeof(Detour._JobDriver_FoodDeliver).GetMethod("_MakeNewToils", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_FoodDeliver_MakeNewToils, CCL_JobDriver_FoodDeliver_MakeNewToils)) { return(false); } // Detour RimWorld.JobDriver_FoodFeedPatient.MakeNewToils MethodInfo RimWorld_JobDriver_FoodFeedPatient_MakeNewToils = typeof(JobDriver_FoodFeedPatient).GetMethod("MakeNewToils", UniversalBindingFlags); MethodInfo CCL_JobDriver_FoodFeedPatient_MakeNewToils = typeof(Detour._JobDriver_FoodFeedPatient).GetMethod("_MakeNewToils", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_FoodFeedPatient_MakeNewToils, CCL_JobDriver_FoodFeedPatient_MakeNewToils)) { return(false); } // Detour RimWorld.JobDriver_Ingest.UsingNutrientPasteDispenser PropertyInfo RimWorld_JobDriver_Ingest_UsingNutrientPasteDispenser = typeof(JobDriver_Ingest).GetProperty("UsingNutrientPasteDispenser", UniversalBindingFlags); MethodInfo RimWorld_JobDriver_Ingest_UsingNutrientPasteDispenser_get = RimWorld_JobDriver_Ingest_UsingNutrientPasteDispenser.GetGetMethod(true); MethodInfo CCL_JobDriver_Ingest_UsingNutrientPasteDispenser = typeof(Detour._JobDriver_Ingest).GetMethod("_UsingNutrientPasteDispenser", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_Ingest_UsingNutrientPasteDispenser_get, CCL_JobDriver_Ingest_UsingNutrientPasteDispenser)) { return(false); } // Detour RimWorld.JobDriver_Ingest.GetReport MethodInfo RimWorld_JobDriver_Ingest_GetReport = typeof(JobDriver_Ingest).GetMethod("GetReport", UniversalBindingFlags); MethodInfo CCL_JobDriver_Ingest_GetReport = typeof(Detour._JobDriver_Ingest).GetMethod("_GetReport", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_Ingest_GetReport, CCL_JobDriver_Ingest_GetReport)) { return(false); } // Detour RimWorld.JobDriver_Ingest.PrepareToEatToils_Dispenser MethodInfo RimWorld_JobDriver_Ingest_PrepareToEatToils_Dispenser = typeof(JobDriver_Ingest).GetMethod("PrepareToEatToils_Dispenser", UniversalBindingFlags); MethodInfo CCL_JobDriver_Ingest_PrepareToEatToils_Dispenser = typeof(Detour._JobDriver_Ingest).GetMethod("_PrepareToEatToils_Dispenser", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_Ingest_PrepareToEatToils_Dispenser, CCL_JobDriver_Ingest_PrepareToEatToils_Dispenser)) { return(false); } // Detour RimWorld.Toils_Ingest.TakeMealFromDispenser MethodInfo RimWorld_Toils_Ingest_TakeMealFromDispenser = typeof(Toils_Ingest).GetMethod("TakeMealFromDispenser", UniversalBindingFlags); MethodInfo CCL_Toils_Ingest_TakeMealFromDispenser = typeof(Detour._Toils_Ingest).GetMethod("_TakeMealFromDispenser", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_Toils_Ingest_TakeMealFromDispenser, CCL_Toils_Ingest_TakeMealFromDispenser)) { return(false); } // Detour RimWorld.JobGiver_GetFood.TryGiveJob MethodInfo RimWorld_JobGiver_GetFood_TryGiveJob = typeof(JobGiver_GetFood).GetMethod("TryGiveJob", UniversalBindingFlags); MethodInfo CCL_JobGiver_GetFood_TryGiveJob = typeof(Detour._JobGiver_GetFood).GetMethod("_TryGiveJob", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JobGiver_GetFood_TryGiveJob, CCL_JobGiver_GetFood_TryGiveJob)) { return(false); } // Detour RimWorld.JobDriver_SocialRelax.MakeNewToils MethodInfo RimWorld_JobDriver_SocialRelax_MakeNewToils = typeof(JobDriver_SocialRelax).GetMethod("MakeNewToils", UniversalBindingFlags); MethodInfo CCL_JobDriver_SocialRelax_MakeNewToils = typeof(Detour._JobDriver_SocialRelax).GetMethod("_MakeNewToils", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_JobDriver_SocialRelax_MakeNewToils, CCL_JobDriver_SocialRelax_MakeNewToils)) { return(false); } // Detour Verse.MentalStateWorker_BingingAlcohol.StateCanOccur MethodInfo Verse_MentalStateWorker_BingingAlcohol_StateCanOccur = typeof(MentalStateWorker_BingingAlcohol).GetMethod("StateCanOccur", UniversalBindingFlags); MethodInfo CCL_MentalStateWorker_BingingAlcohol_StateCanOccur = typeof(Detour._MentalStateWorker_BingingAlcohol).GetMethod("_StateCanOccur", UniversalBindingFlags); if (!Detours.TryDetourFromTo(Verse_MentalStateWorker_BingingAlcohol_StateCanOccur, CCL_MentalStateWorker_BingingAlcohol_StateCanOccur)) { return(false); } // Detour RimWorld.CompRottable.CompTickRare MethodInfo RimWorld_CompRottable_CompTickRare = typeof(CompRottable).GetMethod("CompTickRare", UniversalBindingFlags); MethodInfo CCL_CompRottable_CompTickRare = typeof(Detour._CompRottable).GetMethod("_CompTickRare", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_CompRottable_CompTickRare, CCL_CompRottable_CompTickRare)) { return(false); } // Detour RimWorld.CompRottable.CompInspectStringExtra MethodInfo RimWorld_CompRottable_CompInspectStringExtra = typeof(CompRottable).GetMethod("CompInspectStringExtra", UniversalBindingFlags); MethodInfo CCL_CompRottable_CompInspectStringExtra = typeof(Detour._CompRottable).GetMethod("_CompInspectStringExtra", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_CompRottable_CompInspectStringExtra, CCL_CompRottable_CompInspectStringExtra)) { return(false); } // Detour Verse.CompHeatPusherPowered.ShouldPushHeatNow PropertyInfo Verse_CompHeatPusherPowered_ShouldPushHeatNow = typeof(CompHeatPusherPowered).GetProperty("ShouldPushHeatNow", UniversalBindingFlags); #if DEBUG if (Verse_CompHeatPusherPowered_ShouldPushHeatNow == null) { CCL_Log.Error("Unable to find 'Verse.CompHeatPusherPowered.ShouldPushHeatNow'"); return(false); } #endif MethodInfo Verse_CompHeatPusherPowered_ShouldPushHeatNow_Getter = Verse_CompHeatPusherPowered_ShouldPushHeatNow.GetGetMethod(true); MethodInfo CCL_CompHeatPusherPowered_ShouldPushHeatNow = typeof(Detour._CompHeatPusherPowered).GetMethod("_ShouldPushHeatNow", UniversalBindingFlags); if (!Detours.TryDetourFromTo(Verse_CompHeatPusherPowered_ShouldPushHeatNow_Getter, CCL_CompHeatPusherPowered_ShouldPushHeatNow)) { return(false); } // Detour Verse.CompGlower.ShouldBeLitNow PropertyInfo Verse_CompGlower_ShouldBeLitNow = typeof(CompGlower).GetProperty("ShouldBeLitNow", UniversalBindingFlags); #if DEBUG if (Verse_CompGlower_ShouldBeLitNow == null) { CCL_Log.Error("Unable to find 'Verse.CompGlower.ShouldBeLitNow'"); return(false); } #endif MethodInfo Verse_CompGlower_ShouldBeLitNow_Getter = Verse_CompGlower_ShouldBeLitNow.GetGetMethod(true); MethodInfo CCL_CompGlower_ShouldBeLitNow = typeof(Detour._CompGlower).GetMethod("_ShouldBeLitNow", UniversalBindingFlags); if (!Detours.TryDetourFromTo(Verse_CompGlower_ShouldBeLitNow_Getter, CCL_CompGlower_ShouldBeLitNow)) { return(false); } // Detour RimWorld.MainTabWindow_Research.DrawLeftRect "NotFinished" predicate function // Use build number to get the correct predicate function var RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name = string.Empty; var RimWorld_Build = RimWorld.VersionControl.CurrentBuild; switch (RimWorld_Build) { case 1220: case 1230: RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name = "<DrawLeftRect>m__460"; break; case 1232: RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name = "<DrawLeftRect>m__45E"; break; case 1234: case 1238: case 1241: case 1249: RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name = "<DrawLeftRect>m__45F"; break; default: CCL_Log.Trace( Verbosity.Warnings, "CCL needs updating for RimWorld build " + RimWorld_Build.ToString()); break; } if (RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name != string.Empty) { MethodInfo RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished = typeof(RimWorld.MainTabWindow_Research).GetMethod(RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished_Name, UniversalBindingFlags); MethodInfo CCL_MainTabWindow_Research_DrawLeftRect_NotFinishedNotLockedOut = typeof(Detour._MainTabWindow_Research).GetMethod("_NotFinishedNotLockedOut", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_MainTabWindow_Research_DrawLeftRect_NotFinished, CCL_MainTabWindow_Research_DrawLeftRect_NotFinishedNotLockedOut)) { return(false); } } // Detour RimWorld.SocialProperness.IsSociallyProper MethodInfo RimWorld_SocialProperness_IsSociallyProper = typeof(SocialProperness).GetMethods().First <MethodInfo>((arg) => ( (arg.Name == "IsSociallyProper") && (arg.GetParameters().Count() == 4) )); MethodInfo CCL_SocialProperness_IsSociallyProper = typeof(Detour._SocialProperness).GetMethod("_IsSociallyProper", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_SocialProperness_IsSociallyProper, CCL_SocialProperness_IsSociallyProper)) { return(false); } // Detour Verse.ThingListGroupHelper.Includes MethodInfo Verse_ThingListGroupHelper_Includes = typeof(ThingListGroupHelper).GetMethod("Includes", UniversalBindingFlags); MethodInfo CCL_ThingListGroupHelper_Includes = typeof(Detour._ThingListGroupHelper).GetMethod("_Includes", UniversalBindingFlags); if (!Detours.TryDetourFromTo(Verse_ThingListGroupHelper_Includes, CCL_ThingListGroupHelper_Includes)) { return(false); } // Detour RimWorld.GenConstruct.CanBuildOnTerrain MethodInfo RimWorld_GenConstruct_CanBuildOnTerrain = typeof(GenConstruct).GetMethod("CanBuildOnTerrain", UniversalBindingFlags); MethodInfo CCL_GenConstruct_CanBuildOnTerrain = typeof(Detour._GenConstruct).GetMethod("_CanBuildOnTerrain", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_GenConstruct_CanBuildOnTerrain, CCL_GenConstruct_CanBuildOnTerrain)) { return(false); } // Detour RimWorld.WorkGiver_Warden_DeliverFood.FoodAvailableInRoomTo MethodInfo RimWorld_WorkGiver_Warden_DeliverFood_FoodAvailableInRoomTo = typeof(WorkGiver_Warden_DeliverFood).GetMethod("FoodAvailableInRoomTo", UniversalBindingFlags); MethodInfo CCL_WorkGiver_Warden_DeliverFood_FoodAvailableInRoomTo = typeof(Detour._WorkGiver_Warden_DeliverFood).GetMethod("_FoodAvailableInRoomTo", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_WorkGiver_Warden_DeliverFood_FoodAvailableInRoomTo, CCL_WorkGiver_Warden_DeliverFood_FoodAvailableInRoomTo)) { return(false); } // Detour Verse.PreLoadUtility.CheckVersionAndLoad MethodInfo Verse_PreLoadUtility_CheckVersionAndLoad = typeof(PreLoadUtility).GetMethod("CheckVersionAndLoad", UniversalBindingFlags); MethodInfo CCL_PreLoadUtility_CheckVersionAndLoad = typeof(Detour._PreLoadUtility).GetMethod("_CheckVersionAndLoad", UniversalBindingFlags); if (!Detours.TryDetourFromTo(Verse_PreLoadUtility_CheckVersionAndLoad, CCL_PreLoadUtility_CheckVersionAndLoad)) { return(false); } // Detour RimWorld.PageUtility.InitGameStart MethodInfo RimWorld_PageUtility_InitGameStart = typeof(PageUtility).GetMethod("InitGameStart", UniversalBindingFlags); MethodInfo CCL_PageUtility_InitGameStart = typeof(Detour._PageUtility).GetMethod("_InitGameStart", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_PageUtility_InitGameStart, CCL_PageUtility_InitGameStart)) { return(false); } // Detour Verse.ModLister.InstalledModsListHash MethodInfo Verse_ModLister_InstalledModsListHash = typeof(ModLister).GetMethod("InstalledModsListHash", UniversalBindingFlags); MethodInfo CCL_ModLister_InstalledModsListHash = typeof(Detour._ModLister).GetMethod("_InstalledModsListHash", UniversalBindingFlags); if (!Detours.TryDetourFromTo(Verse_ModLister_InstalledModsListHash, CCL_ModLister_InstalledModsListHash)) { return(false); } // Detour RimWorld.OutfitDatabase.GenerateStartingOutfits MethodInfo RimWorld_OutfitDatabase_GenerateStartingOutfits = typeof(OutfitDatabase).GetMethod("GenerateStartingOutfits", UniversalBindingFlags); MethodInfo CCL_OutfitDatabase_GenerateStartingOutfits = typeof(Detour._OutfitDatabase).GetMethod("_GenerateStartingOutfits", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_OutfitDatabase_GenerateStartingOutfits, CCL_OutfitDatabase_GenerateStartingOutfits)) { return(false); } // Detour RimWorld.Pawn_RelationsTracker.CompatibilityWith MethodInfo RimWorld_Pawn_RelationsTracker_CompatibilityWith = typeof(Pawn_RelationsTracker).GetMethod("CompatibilityWith", UniversalBindingFlags); MethodInfo CCL_Pawn_RelationsTracker_CompatibilityWith = typeof(Detour._Pawn_RelationsTracker).GetMethod("_CompatibilityWith", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_Pawn_RelationsTracker_CompatibilityWith, CCL_Pawn_RelationsTracker_CompatibilityWith)) { return(false); } // Detour RimWorld.Pawn_RelationsTracker.AttractionTo MethodInfo RimWorld_Pawn_RelationsTracker_AttractionTo = typeof(Pawn_RelationsTracker).GetMethod("AttractionTo", UniversalBindingFlags); MethodInfo CCL_Pawn_RelationsTracker_AttractionTo = typeof(Detour._Pawn_RelationsTracker).GetMethod("_AttractionTo", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_Pawn_RelationsTracker_AttractionTo, CCL_Pawn_RelationsTracker_AttractionTo)) { return(false); } // Detour RimWorld.PlaySettings.ExposeData MethodInfo RimWorld_PlaySetting_ExposeData = typeof(PlaySettings).GetMethod("ExposeData", UniversalBindingFlags); MethodInfo CCL_PlaySetting_ExposeData = typeof(Detour._PlaySettings).GetMethod("_ExposeData", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_PlaySetting_ExposeData, CCL_PlaySetting_ExposeData)) { return(false); } // Detour RimWorld.PlaySettings.DoPlaySettingsGlobalControls MethodInfo RimWorld_PlaySettings_DoPlaySettingsGlobalControls = typeof(PlaySettings).GetMethod("DoPlaySettingsGlobalControls", UniversalBindingFlags); MethodInfo CCL_PlaySettings_DoPlaySettingsGlobalControls = typeof(Detour._PlaySettings).GetMethod("_DoPlaySettingsGlobalControls", UniversalBindingFlags); if (!Detours.TryDetourFromTo(RimWorld_PlaySettings_DoPlaySettingsGlobalControls, CCL_PlaySettings_DoPlaySettingsGlobalControls)) { return(false); } /* * // Detour * MethodInfo foo = typeof( foo_class ).GetMethod( "foo_method", UniversalBindingFlags ); * MethodInfo CCL_bar = typeof( Detour._bar ).GetMethod( "_bar_method", UniversalBindingFlags ); * if( !Detours.TryDetourFromTo( foo, CCL_bar ) ) * return false; * */ return(true); }
/** * This is a basic first implementation of the IL method 'hooks' (detours) made possible by RawCode's work; * https://ludeon.com/forums/index.php?topic=17143.0 * * Performs detours, spits out basic logs and warns if a method is detoured multiple times. **/ public static unsafe bool TryDetourFromTo(MethodInfo source, MethodInfo destination) { // error out on null arguments if (source == null) { CCL_Log.Trace(Verbosity.FatalErrors, "Source MethodInfo is null", "Detours" ); return(false); } if (destination == null) { CCL_Log.Trace(Verbosity.FatalErrors, "Destination MethodInfo is null", "Detours" ); return(false); } // keep track of detours and spit out some messaging string sourceString = source.DeclaringType.FullName + "." + source.Name + " @ 0x" + source.MethodHandle.GetFunctionPointer().ToString("X" + (IntPtr.Size * 2).ToString()); string destinationString = destination.DeclaringType.FullName + "." + destination.Name + " @ 0x" + destination.MethodHandle.GetFunctionPointer().ToString("X" + (IntPtr.Size * 2).ToString()); #if DEBUG if (detoured.Contains(sourceString)) { CCL_Log.Trace(Verbosity.Warnings, "Source method ('" + sourceString + "') is previously detoured to '" + destinations[detoured.IndexOf(sourceString)] + "'", "Detours" ); } CCL_Log.Trace(Verbosity.Injections, "Detouring '" + sourceString + "' to '" + destinationString + "'", "Detours" ); #endif detoured.Add(sourceString); destinations.Add(destinationString); if (IntPtr.Size == sizeof(Int64)) { // 64-bit systems use 64-bit absolute address and jumps // 12 byte destructive // Get function pointers long Source_Base = source.MethodHandle.GetFunctionPointer().ToInt64(); long Destination_Base = destination.MethodHandle.GetFunctionPointer().ToInt64(); // Native source address byte *Pointer_Raw_Source = (byte *)Source_Base; // Pointer to insert jump address into native code long *Pointer_Raw_Address = (long *)(Pointer_Raw_Source + 0x02); // Insert 64-bit absolute jump into native code (address in rax) // mov rax, immediate64 // jmp [rax] *(Pointer_Raw_Source + 0x00) = 0x48; *(Pointer_Raw_Source + 0x01) = 0xB8; *Pointer_Raw_Address = Destination_Base; // ( Pointer_Raw_Source + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 ) *(Pointer_Raw_Source + 0x0A) = 0xFF; *(Pointer_Raw_Source + 0x0B) = 0xE0; } else { // 32-bit systems use 32-bit relative offset and jump // 5 byte destructive // Get function pointers int Source_Base = source.MethodHandle.GetFunctionPointer().ToInt32(); int Destination_Base = destination.MethodHandle.GetFunctionPointer().ToInt32(); // Native source address byte *Pointer_Raw_Source = (byte *)Source_Base; // Pointer to insert jump address into native code int *Pointer_Raw_Address = (int *)(Pointer_Raw_Source + 1); // Jump offset (less instruction size) int offset = (Destination_Base - Source_Base) - 5; // Insert 32-bit relative jump into native code *Pointer_Raw_Source = 0xE9; *Pointer_Raw_Address = offset; } // done! return(true); }