// Replace the comp props with a new one with different values
        // must replace comp props as comps share props for things of the
        // same class.  We need to make a unique copy for the building.
        public void                         ChangeColor(ColorInt color)
        {
            // Get glower
            var glower = CompGlower;

            // New glower properties
            var newProps = new CompProperties_Glower();

            if (newProps == null)
            {
                CCL_Log.Error("CompColoredLight unable to create new CompProperties!", parent.def.defName);
                return;
            }

            // Set the new properties values
            newProps.compClass  = typeof(CompGlower);
            newProps.glowColor  = color;
            newProps.glowRadius = lightRadius;

            // Initialize comp with new properties
            glower.Initialize(newProps);

            // Update glow grid
            //glower.UpdateLit(); <-- Only works if the light changes state (on<->off)
            Find.GlowGrid.MarkGlowGridDirty(parent.Position);
        }
        public override AcceptanceReport    AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
        {
            var Restrictions = checkingDef.RestrictedPlacement_Properties();

#if DEBUG
            if (Restrictions == null)
            {
                CCL_Log.Error("PlaceWorker_RestrictedCount unable to get properties!", checkingDef.defName);
                return(AcceptanceReport.WasRejected);
            }
#endif

            var thingDef = checkingDef as ThingDef;
#if DEBUG
            if (thingDef == null)
            {
                CCL_Log.Error("PlaceWorker_RestrictedCount unable to get cast BuildableDef to ThingDef!", checkingDef.defName);
                return(AcceptanceReport.WasRejected);
            }
#endif

            // Get the current count of instances and blueprints of
            int count = Find.ListerThings.ThingsOfDef(thingDef).Count
                        + Find.ListerThings.ThingsOfDef(thingDef.blueprintDef).Count;

            return(count < Restrictions.MaxCount
                ? AcceptanceReport.WasAccepted
                    : "MessagePlacementCountRestricted".Translate(Restrictions.MaxCount));
        }
Example #3
0
 public override void ResolveReferences()
 {
     base.ResolveReferences();
     if (category == null)
     {
         CCL_Log.Error("Category resolved to null", "HelpDef :: " + defName);
     }
 }
Example #4
0
        public static bool InitializeHosts(bool preload = false)
        {
            if (preload)
            {
                Controller.Data.MCMHosts.Clear();
            }

            // Get the mods with config menus
            foreach (var mhd in Controller.Data.ModHelperDefs)
            {
                // Create all the menus for it
                if (!mhd.ModConfigurationMenus.NullOrEmpty())
                {
                    foreach (var mcm in mhd.ModConfigurationMenus)
                    {
                        if ( // Filter out preload during non-preload and non-preload during preload
                            (
                                (preload) &&
                                (mcm.preload)
                            ) ||
                            (
                                (!preload) &&
                                (!mcm.preload)
                            )
                            )
                        {
                            var host = Controller.Data.MCMHosts.Find(m => m.worker.InjectionSet == mcm);
                            if (host != null)
                            {   // MCM already created....?
                                CCL_Log.TraceMod(
                                    mhd,
                                    Verbosity.Warnings,
                                    string.Format("{0} - Tried to create an MCM when an MCM already exists", mcm.mcmClass.ToString())
                                    );
                                continue;
                            }
                            host        = new MCMHost();
                            host.Label  = mcm.label;
                            host.worker = (ModConfigurationMenu)Activator.CreateInstance(mcm.mcmClass);
                            if (host.worker == null)
                            {
                                CCL_Log.Error(string.Format("Unable to create instance of {0}", mcm.mcmClass.ToString()));
                                return(false);
                            }
                            else
                            {   // Initialize, add it to the menu list and then load it's data
                                host.worker.InjectionSet = mcm;
                                host.worker.Initialize();
                                Controller.Data.MCMHosts.Add(host);
                                LoadHostData(host);
                            }
                        }
                    }
                }
            }
            return(true);
        }
        public override void PostLoad()
        {
            base.PostLoad();

            if (ModName.NullOrEmpty())
            {
                CCL_Log.Error("ModName resolved to null", "HelpCategoryDef :: " + defName);
            }
        }
Example #6
0
 public static bool                  CaptureBegin(StringBuilder target)
 {
     if (captureTarget == null)
     {
         captureTarget    = target;
         captureVerbosity = Verbosity.Default;
         return(true);
     }
     if (captureTarget == target)
     {
         CCL_Log.Error("Already capturing log", "Log Capture");
         return(true);
     }
     return(false);
 }
Example #7
0
        public override void PostLoad()
        {
            base.PostLoad();

            if (first.NullOrEmpty())
            {
                CCL_Log.Error("Custom name with defName: " + defName + " has no defined first name. It will not be added.", "Backstories");
                return;
            }
            if (last.NullOrEmpty())
            {
                CCL_Log.Error("Custom name with defName: " + defName + " has no defined last name. It will not be added.", "Backstories");
                return;
            }

            PawnNameDatabaseSolid.AddPlayerContentName(Name, genderPossibility);
        }
Example #8
0
        public override void                SpawnSetup()
        {
            base.SpawnSetup();

            // Validate power trade
            if (CompPowerTrader == null)
            {
                CCL_Log.Error("Building_SunLampHeatController requires CompPowerTrader!", def.defName);
                return;
            }

            // Validate temp control
            if (CompTempControl == null)
            {
                CCL_Log.Error("Building_SunLampHeatController requires CompTempControl!", def.defName);
                return;
            }
        }
Example #9
0
        public static bool                  CaptureEnd(StringBuilder target, string status = "")
        {
            if (captureTarget == null)
            {
                CCL_Log.Error("Log isn't being captured, no need to end capture", "Log Capture");
                return(true);
            }
            if (captureTarget != target)
            {
                CCL_Log.Error("Cannot end a capture on a different object", "Log Capture");
                return(false);
            }
            var captureStatus = status + "\n";

            captureTarget.Insert(0, captureStatus);
            captureVerbosity = Verbosity.Default;
            captureTarget    = null;
            return(true);
        }
        public override AcceptanceReport    AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
        {
            var Restrictions = checkingDef.RestrictedPlacement_Properties();

#if DEBUG
            if (Restrictions == null)
            {
                CCL_Log.Error("PlaceWorker_OnlyOnTerrain unable to get properties!", checkingDef.defName);
                return(AcceptanceReport.WasRejected);
            }
#endif

            TerrainDef terrainDef = loc.GetTerrain();
            if (Restrictions.RestrictedTerrain.Contains(terrainDef))
            {
                return(AcceptanceReport.WasAccepted);
            }

            return("MessagePlacementNotOn".Translate(terrainDef.label));
        }
Example #11
0
        public override AcceptanceReport    AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
        {
            var Restrictions = checkingDef.RestrictedPlacement_Properties();

#if DEBUG
            if (Restrictions == null)
            {
                CCL_Log.Error("PlaceWorker_OnlyOnThing unable to get properties!", checkingDef.defName);
                return(AcceptanceReport.WasRejected);
            }
#endif

            foreach (Thing t in loc.GetThingList())
            {
                if (Restrictions.RestrictedThing.Contains(t.def))
                {
                    return(AcceptanceReport.WasAccepted);
                }
            }

            return((AcceptanceReport)("MessagePlacementNotHere".Translate()));
        }
Example #12
0
        public override void ResolveReferences()
        {
            base.ResolveReferences();

            PawnBio bio = new PawnBio();

            bio.gender = this.gender;

            if (!firstName.NullOrEmpty() && !lastName.NullOrEmpty())
            {
                bio.name = new NameTriple(firstName, nickName, lastName);
            }
            else
            {
                CCL_Log.Error("PawnBio with defName: " + defName + " has empty first or last name. It will not be added.", "Backstories");
                return;
            }

            Backstory childhood = BackstoryDatabase.GetWithKey(this.childhoodDef.UniqueSaveKey());

            if (childhood != null)
            {
                bio.childhood             = childhood;
                bio.childhood.shuffleable = false;
                bio.childhood.slot        = BackstorySlot.Childhood;
            }
            else
            {
                CCL_Log.Error("PawnBio with defName: " + defName + " has null childhood. It will not be added.", "Backstories");
                return;
            }

            Backstory adulthood = BackstoryDatabase.GetWithKey(this.adulthoodDef.UniqueSaveKey());

            if (adulthood != null)
            {
                bio.adulthood             = adulthood;
                bio.adulthood.shuffleable = false;
                bio.adulthood.slot        = BackstorySlot.Adulthood;
            }
            else
            {
                CCL_Log.Error("PawnBio with defName: " + defName + " has null adulthood. It will not be added.", "Backstories");
                return;
            }

            bio.name.ResolveMissingPieces();

            bool flag = false;

            foreach (var error in bio.ConfigErrors())
            {
                if (!flag)
                {
                    flag = true;
                    CCL_Log.Error("Config error(s) in PawnBioDef " + this.defName + ". Skipping...", "Backstories");
                }
                CCL_Log.Error(error, "Backstories");
            }
            if (flag)
            {
                return;
            }

            if (!SolidBioDatabase.allBios.Contains(bio))
            {
                SolidBioDatabase.allBios.Add(bio);
            }
        }
        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);
        }
Example #14
0
        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);
        }
Example #15
0
        public override void ResolveReferences()
        {
            base.ResolveReferences();

            if (!this.addToDatabase)
            {
                return;
            }
            if (BackstoryDatabase.allBackstories.ContainsKey(this.UniqueSaveKey()))
            {
                return;
            }

            Backstory b = new Backstory();

            if (!this.title.NullOrEmpty())
            {
                b.title = this.title;
            }
            else
            {
                CCL_Log.Error(defName + " backstory has empty title. Skipping...", "Backstories");
                return;
            }
            if (!titleShort.NullOrEmpty())
            {
                b.titleShort = titleShort;
            }
            else
            {
                b.titleShort = b.title;
            }

            if (!baseDescription.NullOrEmpty())
            {
                b.baseDesc = baseDescription;
            }
            else
            {
                CCL_Log.Message(defName + " backstory has empty description.", "Backstories");
                b.baseDesc = "Empty.";
            }

            b.bodyTypeGlobal = bodyTypeGlobal;
            b.bodyTypeMale   = bodyTypeMale;
            b.bodyTypeFemale = bodyTypeFemale;

            b.slot = slot;

            b.shuffleable = shuffleable;
            if (spawnCategories.NullOrEmpty())
            {
                CCL_Log.Error(defName + " backstory doesn't have any spawn categories defined. Skipping...", "Backstories");
                return;
            }
            else
            {
                b.spawnCategories = spawnCategories;
            }

            if (workAllows.Count > 0)
            {
                foreach (WorkTags current in Enum.GetValues(typeof(WorkTags)))
                {
                    if (!workAllows.Contains(current))
                    {
                        b.workDisables |= current;
                    }
                }
            }
            else if (workDisables.Count > 0)
            {
                foreach (var tag in workDisables)
                {
                    b.workDisables |= tag;
                }
            }
            else
            {
                b.workDisables = WorkTags.None;
            }
            b.skillGains = skillGains.ToDictionary(i => i.defName, i => i.amount);

            if (forcedTraits.Count > 0)
            {
                b.forcedTraits = new List <TraitEntry>();
                foreach (var trait in forcedTraits)
                {
                    var newTrait = new TraitEntry(trait.def, trait.degree);
                    b.forcedTraits.Add(newTrait);
                }
            }

            if (disallowedTraits.Count > 0)
            {
                b.disallowedTraits = new List <TraitEntry>();
                foreach (var trait in disallowedTraits)
                {
                    var newTrait = new TraitEntry(trait.def, trait.degree);
                    b.disallowedTraits.Add(newTrait);
                }
            }

            b.ResolveReferences();
            b.PostLoad();
            b.uniqueSaveKey = this.UniqueSaveKey();

            bool flag = false;

            foreach (var s in b.ConfigErrors(false))
            {
                if (!flag)
                {
                    flag = true;
                    CCL_Log.Error("Errors in custom backstory with defName: " + defName + ", backstory will be skipped.", "Backstories");
                }
                CCL_Log.Error(defName + " error: " + s, "Backstories");
            }
            if (!flag)
            {
                BackstoryDatabase.AddBackstory(b);
                //CCL_Log.Message("Added " + this.UniqueSaveKey() + " backstory", "Backstories");
            }
        }