Exemplo n.º 1
0
 public void Initialise(Type subType)
 {
     EnabledRefAccess =
         AccessTools.StaticFieldRefAccess <bool>(subType.GetField("Enabled",
                                                                  BindingFlags.Public | BindingFlags.Static));
     if (EnabledRefAccess == null)
     {
         ThreadSafeLogger.Error("Add an 'Enabled' field you bloody muppet");
     }
 }
        private static void DelayedPatch()
        {
            // Launching the shuttle
            var type = AccessTools.TypeByName("SRTS.CompLaunchableSRTS");

            caravanField    = AccessTools.FieldRefAccess <Caravan>(type, "carr");
            tryLaunchMethod = AccessTools.Method(type, "TryLaunch");

            MpCompat.harmony.Patch(tryLaunchMethod, prefix: new HarmonyMethod(typeof(SRTSExpanded), nameof(PreTryLaunch)));
            MP.RegisterSyncMethod(typeof(SRTSExpanded), nameof(SyncedLaunch)).ExposeParameter(2);
        }
Exemplo n.º 3
0
        public ChoiceOfPsycastsCompat(ModContentPack mod)
        {
            var type = learnPsycastsType = AccessTools.TypeByName("RimWorld.ChoiceOfPsycasts.LearnPsycasts");

            MpCompat.RegisterLambdaDelegate(type, "Choice", 1);
            MpCompat.RegisterLambdaDelegate(type, "ChoiceCustom", 1);

            levelField = AccessTools.FieldRefAccess<int>(type, "Level");
            parentField = AccessTools.FieldRefAccess<Pawn>(type, "Parent");
            MP.RegisterSyncWorker<Command_Action>(SyncLearnPsycasts, type);
        }
Exemplo n.º 4
0
        static SpawnPmcPatch()
        {
            targetInterface = PatcherConstants.TargetAssembly
                              .GetTypes()
                              .Single(IsTargetInterface);
            targetType = PatcherConstants.TargetAssembly
                         .GetTypes()
                         .Single(IsTargetType);

            wildSpawnTypeField = AccessTools.FieldRefAccess <WildSpawnType>(targetType, "Type");
            botDifficultyField = AccessTools.FieldRefAccess <BotDifficulty>(targetType, "BotDifficulty");
        }
Exemplo n.º 5
0
        public VanillaGeneticsExpanded(ModContentPack mod)
        {
            // Sync worker
            {
                var type = AccessTools.TypeByName("GeneticRim.Command_SetGenomeList");

                setGenomeListMap      = AccessTools.FieldRefAccess <Map>(type, "map");
                setGenomeListBuilding = AccessTools.FieldRefAccess <Building>(type, "building");

                MP.RegisterSyncWorker <Command>(SyncCommand, type, shouldConstruct: true);
            }

            // RNG
            {
                var constructors = new[]
                {
                    "GeneticRim.CompExploder",
                    "GeneticRim.HediffComp_PeriodicWounds",
                };

                PatchingUtilities.PatchSystemRandCtor(constructors, false);
            }

            // Gizmos
            {
                // Archocentipide former - start and (dev) finish gizmos
                MpCompat.RegisterLambdaMethod("GeneticRim.Building_ArchocentipedeFormer", "GetGizmos", 0, 1)[1].SetDebugOnly();

                // Archowomb - awaken confirmation and (dev) finish gizmo
                MpCompat.RegisterLambdaMethod("GeneticRim.Building_ArchoWomb", "GetGizmos", 1, 2)[1].SetDebugOnly();

                // Mechahybridizer - (dev) finish gizmo
                MpCompat.RegisterLambdaMethod("GeneticRim.Building_Mechahybridizer", "GetGizmos", 0).SetDebugOnly();

                // Age related disease dev gizmo
                MpCompat.RegisterLambdaMethod("GeneticRim.CompApplyAgeDiseases", "GetGizmos", 0).SetDebugOnly();

                // DNA storage bank and mechahybridizer gizmos
                var type = AccessTools.TypeByName("GeneticRim.ArchotechExtractableAnimals_MapComponent");
                MP.RegisterSyncMethod(type, "AddAnimalToCarry");
                MP.RegisterSyncMethod(type, "AddParagonToCarry");

                // DNA storage bank gizmo
                MpCompat.RegisterLambdaDelegate("GeneticRim.Command_SetGenomeList", "ProcessInput", 2);
            }

            // Float menu
            {
                MpCompat.RegisterLambdaDelegate("GeneticRim.CompArchotechGrowthCell", "CompFloatMenuOptions", 0);
            }

            LongEventHandler.ExecuteWhenFinished(LatePatch);
        }
        private static void LatePatch()
        {
            // BuildingAltar continuation
            {
                // TempleCardUtility is used for UI drawing, called from BuildingAltar
                var type = AccessTools.TypeByName("Corruption.Worship.TempleCardUtility");
                MP.RegisterSyncDelegate(type, "<>c__DisplayClass4_1", "<OpenDedicationSelectMenu>b__1");
                // We patch the modded method to intercept some of their calls that will need syncing and call them through our methods,
                // as syncing the actual methods themselves will sync way too much (methods might/will be called often)
                MpCompat.harmony.Patch(AccessTools.Method(type, "DrawSermonTemplate"),
                                       prefix: new HarmonyMethod(typeof(CorruptionWorship), nameof(DrawSermonTemplatePrefix)),
                                       postfix: new HarmonyMethod(typeof(CorruptionWorship), nameof(DrawSermonTemplatePostfix)),
                                       transpiler: new HarmonyMethod(typeof(CorruptionWorship), nameof(PatchDrawSermonTemplate)));

                // The previous inner class (<>c__DisplayClass4_1) needs the following one to be synced too, but this one uses sermon
                // which requires a bit more data to sync, so we make SyncWorker manually instead of using RegisterSyncDelegate
                var inner = AccessTools.Inner(type, "<>c__DisplayClass4_0");
                templeCardUtilityInnerAltarField  = AccessTools.FieldRefAccess <Building>(inner, "altar");
                templeCardUtilityInnerSermonField = AccessTools.FieldRefAccess <object>(inner, "template");

                MP.RegisterSyncMethod(typeof(CorruptionWorship), nameof(SyncedInterceptedReceiveMemo));
                MP.RegisterSyncMethod(typeof(CorruptionWorship), nameof(SyncedInterceptedEndSermon));
                MP.RegisterSyncMethod(typeof(CorruptionWorship), nameof(SyncedTryStartSermon)).SetDebugOnly();
                MP.RegisterSyncMethod(typeof(CorruptionWorship), nameof(SyncSimpleSermonData));
            }

            // Dialog_ReligiousRiot, opened when there's enough pawns of different religion
            // Should open for all players, so we assume we can get it/sync it using Find.WindowStack
            {
                religiousRiotType = AccessTools.TypeByName("Corruption.Worship.Dialog_ReligiousRiot");
                MP.RegisterSyncMethod(religiousRiotType, "ChooseNewReligion");
                MP.RegisterSyncMethod(religiousRiotType, "PreserveReligion");
                MP.RegisterSyncWorker <Window>(SyncReligiousRiotDialog, religiousRiotType);
            }

            // Other stuff
            {
                // Rotating worship statue
                var type = AccessTools.TypeByName("Corruption.Worship.Building_WorshipStatue");
                MpCompat.RegisterLambdaMethod(type, "GetGizmos", 0);

                // Debug ring the bell
                type = AccessTools.TypeByName("Corruption.Worship.CompBellTower");
                MpCompat.RegisterLambdaMethod(type, "CompGetGizmosExtra", 0).SetDebugOnly();

                // Drop effigy
                type = AccessTools.TypeByName("Corruption.Worship.CompShrine");
                MP.RegisterSyncMethod(type, "DropEffigy");
            }
        }
        static RemoveUsedBotProfilePatch()
        {
            // compile-time check
            _ = nameof(BotData.ChooseProfile);

            targetInterface = PatcherConstants.TargetAssembly
                              .GetTypes()
                              .Single(IsTargetInterface);
            targetType = PatcherConstants.TargetAssembly
                         .GetTypes()
                         .Single(IsTargetType);

            profilesField = AccessTools.FieldRefAccess <List <Profile> >(targetType, "list_0");
        }
Exemplo n.º 8
0
        public RimFridgeCompat(ModContentPack mod)
        {
            // Several Gizmos
            {
                MpCompat.RegisterLambdaDelegate("RimFridge.CompRefrigerator", "CompGetGizmosExtra", 1, 2, 3, 4, 5);
                MpCompat.RegisterLambdaMethod("RimFridge.CompToggleGlower", "CompGetGizmosExtra", 0);

                dialogType  = AccessTools.TypeByName("RimFridge.Dialog_RenameFridge");
                fridgeField = AccessTools.FieldRefAccess <ThingComp>(dialogType, "fridge");

                MP.RegisterSyncWorker <Dialog_Rename>(SyncFridgeName, dialogType);
                MP.RegisterSyncMethod(dialogType, "SetName");
            }
        }
Exemplo n.º 9
0
        private static void ReduceToCapacity(BattleLog __instance)
        {
            int num = battles(__instance).Count((Battle btl) => btl.AbsorbedBy == null);

            while (num > 20 && battles(__instance)[battles(__instance).Count - 1].LastEntryTimestamp + Mathf.Max(420000, 5000) < Find.TickManager.TicksGame)
            {
                if (battles(__instance)[battles(__instance).Count - 1].AbsorbedBy == null)
                {
                    num--;
                }

                battles(__instance).RemoveAt(battles(__instance).Count - 1);
                activeEntries = null;
            }
        }
Exemplo n.º 10
0
        public SmartFarming(ModContentPack mod)
        {
            var type = AccessTools.TypeByName("SmartFarming.Mod_SmartFarming");

            compCache = AccessTools.StaticFieldRefAccess <IDictionary>(type, "compCache");

            type = AccessTools.TypeByName("SmartFarming.MapComponent_SmartFarming");
            growZoneRegistryField = AccessTools.FieldRefAccess <IDictionary>(type, "growZoneRegistry");

            type = AccessTools.TypeByName("SmartFarming.ZoneData");
            MpCompat.RegisterLambdaDelegate(type, "Init", 3, 4).SetContext(SyncContext.CurrentMap); // Toggle no petty jobs, force harvest now
            MP.RegisterSyncMethod(type, "SwitchSowMode");                                           // Called from two places
            MP.RegisterSyncMethod(type, "SwitchPriority");                                          // Called from two places
            MP.RegisterSyncWorker <object>(SyncZoneData, type);
        }
Exemplo n.º 11
0
        public VanillaFactionsAncients(ModContentPack mod)
        {
            // Supply slingshot launch gizmo (after 2 possible confirmation)
            MP.RegisterSyncMethod(AccessTools.TypeByName("VFEAncients.CompSupplySlingshot"), "TryLaunch");

            // VFEAncients.CompGeneTailoringPod:StartOperation requires SyncWorker for Operation
            // (Method inside of LatePatch)
            var type = AccessTools.TypeByName("VFEAncients.Operation");

            operationPodField = AccessTools.FieldRefAccess <ThingComp>(type, "Pod");
            MP.RegisterSyncWorker <object>(SyncOperation, type, true);

            MP.RegisterPauseLock(ShouldPause);

            LongEventHandler.ExecuteWhenFinished(LatePatch);
        }
Exemplo n.º 12
0
        public CorruptionPsykers(ModContentPack mod)
        {
            // Window_PsykerDiscipline
            psykerDisciplineWindowType             = AccessTools.TypeByName("Corruption.Psykers.Window_PsykerDiscipline");
            psykerDisciplineWindowCompField        = AccessTools.FieldRefAccess <ThingComp>(psykerDisciplineWindowType, "comp");
            psykerDisciplineWindowSelectedDefField = AccessTools.FieldRefAccess <Def>(psykerDisciplineWindowType, "selectedDef");
            MP.RegisterSyncMethod(psykerDisciplineWindowType, "ChoosePower");
            MP.RegisterSyncWorker <object>(SyncPsykerDisciplineWindow, psykerDisciplineWindowType);


            psykerDisciplineMinorWindowType = AccessTools.TypeByName("Corruption.Psykers.Window_PsykerDisciplineMinor");
            MP.RegisterSyncMethod(psykerDisciplineMinorWindowType, "ChoosePower");
            MP.RegisterSyncWorker <object>(SyncPsykerDisciplineMinorWindow, psykerDisciplineMinorWindowType);


            LongEventHandler.ExecuteWhenFinished(LatePatch);
        }
Exemplo n.º 13
0
        public static void ApplyCompat(HarmonyLib.Harmony harm)
        {
            if (ModLister.HasActiveModWithName("RunAndGun") && Base.Features.EnabledAtAll)
            {
                Log.Message("[MVCF] Applying RunAndGun compatibility patch");
                harm.Patch(AccessTools.Method(Type.GetType("RunAndGun.Harmony.Verb_TryCastNextBurstShot, RunAndGun"),
                                              "SetStanceRunAndGun"),
                           transpiler: new HarmonyMethod(typeof(Compat), "RunAndGunSetStance"));
                harm.Patch(AccessTools.Method(Type.GetType("RunAndGun.Harmony.Verb_TryStartCastOn, RunAndGun"),
                                              "Prefix"),
                           new HarmonyMethod(typeof(Compat), "RunAndGunVerbCast"));
                harm.Patch(Type.GetType("RunAndGun.Extensions, RunAndGun")
                           ?.GetMethod("HasRangedWeapon"),
                           postfix: new HarmonyMethod(typeof(Compat), "RunAndGunHasRangedWeapon"));
            }

            if (ModLister.HasActiveModWithName("Dual Wield") && Base.Features.HumanoidVerbs)
            {
                Log.Message("[MVCF] Applying Dual Wield compatibility patch");
                RotationTrackerPawn = AccessTools
                                      .FieldRefAccess <Pawn_RotationTracker, Pawn>("pawn");
                RendererPawn          = AccessTools.FieldRefAccess <PawnRenderer, Pawn>("pawn");
                GetStancesOffHandInfo = AccessTools.Method(Type.GetType(
                                                               "DualWield.Ext_Pawn, DualWield"), "GetStancesOffHand");
                IsOffHand = AccessTools.Method(Type.GetType(
                                                   "DualWield.Ext_ThingWithComps, DualWield"), "IsOffHand")
                            .CreateDelegate(typeof(Func <ThingWithComps, bool>));

                harm.Patch(
                    Type.GetType("DualWield.Harmony.Pawn_RotationTracker_UpdateRotation, DualWield")
                    ?.GetMethod("Postfix", BindingFlags.NonPublic | BindingFlags.Static),
                    transpiler: new HarmonyMethod(typeof(Compat), "UpdateRotationTranspile"));
                harm.Patch(
                    Type.GetType("DualWield.Harmony.PawnRenderer_RenderPawnAt, DualWield")
                    ?.GetMethod("Postfix", BindingFlags.NonPublic | BindingFlags.Static),
                    transpiler: new HarmonyMethod(typeof(Compat), "RenderPawnAtTranspile"));
            }

            var type = AccessTools.TypeByName("CompToggleFireMode.CompToggleFireMode");

            if (type != null)
            {
                GetToggleComp = AccessTools.Method(typeof(ThingCompUtility), "TryGetComp")
                                .MakeGenericMethod(type);
            }
        }
        public HealerMechSerumChoice(ModContentPack mod)
        {
            MP.RegisterSyncMethod(typeof(HealerMechSerumChoice), nameof(SyncedSetHediff));

            // Dialog
            hediffSelectionDialogType = AccessTools.TypeByName("HMSChoice.Dialog_HediffSelection");

            dialogSelectedHediffField = AccessTools.FieldRefAccess <Hediff>(hediffSelectionDialogType, "SelectedHediff");
            MP.RegisterSyncMethod(AccessTools.Method(hediffSelectionDialogType, "Close", new[] { typeof(Hediff) }));
            MP.RegisterSyncWorker <Window>(SyncHediffDialog, hediffSelectionDialogType);
            MpCompat.harmony.Patch(AccessTools.Method(hediffSelectionDialogType, nameof(Window.DoWindowContents)),
                                   prefix: new HarmonyMethod(typeof(HealerMechSerumChoice), nameof(PreDoWindowContents)),
                                   postfix: new HarmonyMethod(typeof(HealerMechSerumChoice), nameof(PostDoWindowContents)));
            MpCompat.harmony.Patch(AccessTools.Constructor(hediffSelectionDialogType, new[] { typeof(string), typeof(List <Hediff>), typeof(Action <Hediff>) }),
                                   postfix: new HarmonyMethod(typeof(HealerMechSerumChoice), nameof(PostDialogConstructor)));

            MP.RegisterPauseLock(PauseWhenDialogOpen);
        }
Exemplo n.º 15
0
        public AlphaBiomes(ModContentPack mod)
        {
            var type = AccessTools.TypeByName("AlphaBiomes.Command_SetStoneType");

            buildingField = AccessTools.FieldRefAccess <Building>(type, "building");
            // SyncWorker needed as the <ProcessInput> methods require syncing of the `building` field
            MP.RegisterSyncWorker <Command>(SyncSetStoneType, type, shouldConstruct: true);
            MpCompat.RegisterLambdaMethod(type, "ProcessInput", Enumerable.Range(0, 6).ToArray());

            var rngFixMethods = new[]
            {
                "AlphaBiomes.CompGasProducer:CompTick",
                "AlphaBiomes.TarSprayer:SteamSprayerTick",
                "AlphaBiomes.GameCondition_AcidRain:DoCellSteadyEffects",
            };

            PatchingUtilities.PatchSystemRand(AccessTools.Constructor(AccessTools.TypeByName("AlphaBiomes.CompGasProducer")), false);
            PatchingUtilities.PatchPushPopRand(rngFixMethods);
        }
        public VanillaFishingExpanded(ModContentPack mod)
        {
            // RNG fix
            {
                PatchingUtilities.PatchSystemRandCtor("VCE_Fishing.JobDriver_Fish", false);
                PatchingUtilities.PatchPushPopRand("VCE_Fishing.JobDriver_Fish:SelectFishToCatch");
            }

            // Gizmo (select fish size to catch)
            {
                commandType      = AccessTools.TypeByName("VCE_Fishing.Command_SetFishList");
                mapField         = AccessTools.FieldRefAccess <Map>(commandType, "map");
                fishingZoneField = AccessTools.FieldRefAccess <Zone>(commandType, "zone");

                MpCompat.RegisterLambdaMethod(commandType, "ProcessInput", Enumerable.Range(0, 3).ToArray());
                MP.RegisterSyncWorker <Command>(SyncFishingZoneChange, commandType, shouldConstruct: false);

                MpCompat.RegisterLambdaMethod(AccessTools.TypeByName("VCE_Fishing.Zone_Fishing"), "GetGizmos", 1);
            }
        }
Exemplo n.º 17
0
        public Pharmacist(ModContentPack mod)
        {
            var type  = AccessTools.TypeByName("Pharmacist.PharmacistSettings");
            var outer = type;

            setDefaultsMethod = AccessTools.MethodDelegate <SetDefaults>(AccessTools.Method(type, "SetDefaults"));
            medicalCareField  = AccessTools.StaticFieldRefAccess <object>(AccessTools.Field(type, "medicalCare"));

            type = AccessTools.Inner(outer, "MedicalCare");
            diseaseMarginField        = MP.RegisterSyncField(type, "_diseaseMargin");
            minorWoundsThresholdField = MP.RegisterSyncField(type, "_minorWoundsThreshold");
            diseaseThresholdField     = MP.RegisterSyncField(type, "_diseaseThreshold");
            MP.RegisterSyncWorker <object>(SyncMedicalCare, type);

            type = AccessTools.TypeByName("Pharmacist.MainTabWindow_Pharmacist");
            MpCompat.RegisterLambdaDelegate(type, "DrawCareSelectors", 0, 1, 2);
            MpCompat.harmony.Patch(AccessTools.Method(type, "DrawOptions"),
                                   prefix: new HarmonyMethod(typeof(Pharmacist), nameof(PreDrawOptions)),
                                   postfix: new HarmonyMethod(typeof(Pharmacist), nameof(PostDrawOptions)));
        }
Exemplo n.º 18
0
        public static bool Add(BattleLog __instance, LogEntry entry)
        {
            lock (addLogEntryLock) {
                Battle battle = null;
                foreach (Pawn concern in entry.GetConcerns())
                {
                    Battle battleActive = concern.records.BattleActive;
                    if (battle == null)
                    {
                        battle = battleActive;
                    }
                    else if (battleActive != null)
                    {
                        battle = ((battle.Importance > battleActive.Importance) ? battle : battleActive);
                    }
                }

                if (battle == null)
                {
                    battle = Battle.Create();
                    battles(__instance).Insert(0, battle);
                }

                foreach (Pawn concern2 in entry.GetConcerns())
                {
                    Battle battleActive2 = concern2.records.BattleActive;
                    if (battleActive2 != null && battleActive2 != battle)
                    {
                        battle.Absorb(battleActive2);
                        battles(__instance).Remove(battleActive2);
                    }

                    concern2.records.EnterBattle(battle);
                }

                battle.Add(entry);
                activeEntries = null;
                ReduceToCapacity(__instance);
            }
            return(false);
        }
Exemplo n.º 19
0
        internal static void Install()
        {
            Type patchProcessorType = typeof(PatchProcessor);
            Type patchShieldType    = typeof(PatchShield);

            PatchProcessor_OriginalRef = AccessTools.FieldRefAccess <MethodBase>(patchProcessorType, "original");

            try
            {
                Core.HarmonyInstance.Patch(
                    AccessTools.Method("HarmonyLib.PatchFunctions:ReversePatch"),
                    AccessTools.Method(patchShieldType, "PatchMethod_PatchFunctions_ReversePatch").ToNewHarmonyMethod()
                    );
            }
            catch (Exception ex) { LogException(ex); }

            try
            {
                HarmonyMethod unpatchMethod = AccessTools.Method(patchShieldType, "PatchMethod_PatchProcessor_Unpatch").ToNewHarmonyMethod();
                foreach (MethodInfo method in patchProcessorType.GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(x => x.Name.Equals("Unpatch")))
                {
                    Core.HarmonyInstance.Patch(method, unpatchMethod);
                }
            }
            catch (Exception ex) { LogException(ex); }

            try
            {
                Core.HarmonyInstance.Patch(AccessTools.Method(patchProcessorType, "Patch"),
                                           AccessTools.Method(patchShieldType, "PatchMethod_PatchProcessor_Patch").ToNewHarmonyMethod()
                                           );
            }
            catch (Exception ex) { LogException(ex); }

            Hook.OnDetour   += (detour, originalMethod, patchMethod, delegateTarget) => MethodCheck(originalMethod);
            ILHook.OnDetour += (detour, originalMethod, ilmanipulator) => MethodCheck(originalMethod);
            Detour.OnDetour += (detour, originalMethod, patchMethod) => MethodCheck(originalMethod);
        }
Exemplo n.º 20
0
        public PathAvoidCompat(ModContentPack mod)
        {
            pathAvoidDefType = AccessTools.TypeByName("PathAvoid.PathAvoidDef");
            levelField       = AccessTools.FieldRefAccess <int>(pathAvoidDefType, "level");

            designator_PathAvoidType = AccessTools.TypeByName("PathAvoid.Designator_PathAvoid");
            pathAvoidDefField        = AccessTools.FieldRefAccess <Def>(designator_PathAvoidType, "def");

            MP.RegisterSyncWorker <Designator>(PathAvoidDesignatorSyncWorker, designator_PathAvoidType);

            var type = AccessTools.TypeByName("PathAvoid.MapSettingsDialog");

            selectedTerrainDefField           = AccessTools.FieldRefAccess <TerrainDef>(type, "selectedTerrainDef");
            selectedPathAvoidDefField         = AccessTools.FieldRefAccess <Def>(type, "selectedPathAvoidDef");
            selectedPathAvoidDefForResetField = AccessTools.FieldRefAccess <Def>(type, "selectedPathAvoidDefForReset");
            MpCompat.harmony.Patch(AccessTools.Method(type, nameof(Window.DoWindowContents)),
                                   transpiler: new HarmonyMethod(typeof(PathAvoidCompat), nameof(ReplaceAcceptButtons)));

            pathAvoidGridType           = AccessTools.TypeByName("PathAvoid.PathAvoidGrid");
            pathAvoidGridSetValueMethod = AccessTools.Method(pathAvoidGridType, "SetValue", new[] { typeof(int), typeof(byte) });

            MP.RegisterSyncMethod(typeof(PathAvoidCompat), nameof(SyncedSetAllToDef));
        }
        public VanillaExpandedFrameworkReferenced(ModContentPack mod)
        {
            // Outposts
            {
                // Create dialog
                MpCompat.harmony.Patch(AccessTools.Method(typeof(Dialog_CreateCamp), nameof(Dialog_CreateCamp.DoOutpostDisplay)),
                                       prefix: new HarmonyMethod(typeof(VanillaExpandedFrameworkReferenced), nameof(PreDoOutpostDisplay)));
                MP.RegisterSyncMethod(typeof(VanillaExpandedFrameworkReferenced), nameof(SyncedCreateOutpost));

                // Rename dialog
                MP.RegisterSyncWorker <Dialog_RenameOutpost>(SyncRenameOutpostDialog, typeof(Dialog_RenameOutpost));
                MP.RegisterSyncMethod(typeof(Dialog_RenameOutpost), nameof(Dialog_RenameOutpost.SetName));

                // Take items dialog
                MpCompat.harmony.Patch(AccessTools.Method(typeof(Dialog_TakeItems), nameof(Dialog_TakeItems.DoBottomButtons)),
                                       prefix: new HarmonyMethod(typeof(VanillaExpandedFrameworkReferenced), nameof(PreDoBottomButtons)));
                MP.RegisterSyncMethod(typeof(VanillaExpandedFrameworkReferenced), nameof(SyncedTakeItems));

                // Generic outpost
                // Stop packing (0), pack (1), and (dev) produce now (5)
                MpCompat.RegisterLambdaMethod(typeof(Outpost), nameof(Outpost.GetGizmos), 0, 1, 5, 6, 7, 8).Skip(2).SetDebugOnly();
                // Remove pawn from outpost/create caravan (delegate, 4)
                // We need a slight workaround, as the gizmo itself won't work - the pawn is inaccessible for syncing
                var innerType = AccessTools.Inner(typeof(Outpost), "<>c__DisplayClass58_0");
                outpostsInnerClassThisField = AccessTools.FieldRefAccess <Outpost>(innerType, "<>4__this");
                outpostsInnerClassPawnField = AccessTools.FieldRefAccess <Pawn>(innerType, "p");
                MpCompat.harmony.Patch(AccessTools.Method(innerType, "<GetGizmos>b__4"),
                                       prefix: new HarmonyMethod(typeof(VanillaExpandedFrameworkReferenced), nameof(PreRemoveFromOutpost)));
                MP.RegisterSyncMethod(typeof(VanillaExpandedFrameworkReferenced), nameof(SyncedRemoveFromOutpost));
                MP.RegisterSyncWorker <ResultOption>(SyncResultOption);
                // Add pawn to outpost
                MpCompat.RegisterLambdaDelegate(typeof(Outpost), nameof(Outpost.GetCaravanGizmos), 2);

                // Outpost with results you can choose from
                MpCompat.RegisterLambdaDelegate("Outposts.Outpost_ChooseResult", "GetGizmos", 2);
            }
        }
Exemplo n.º 22
0
        public SmartStockpileCreation(ModContentPack mod)
        {
            // Create Stockpile from Thing
            {
                designatorType = AccessTools.TypeByName("SmartStockpileCreation.RimObjs.SmartStockpile.SmartStockpileDesignator");

                allowedThingsGetter        = MethodInvoker.GetHandler(AccessTools.PropertyGetter(designatorType, "AllowedThings"));
                specialThingFilterDefLabel = AccessTools.FieldRefAccess <SpecialThingFilterDef>(designatorType, "_specialThingFilterDef");
                priorityLabel = AccessTools.FieldRefAccess <StoragePriority>(designatorType, "_priority");
                contentsLabel = AccessTools.FieldRefAccess <string>(designatorType, "_stockpileContentsLabel");

                MP.RegisterSyncWorker <Designator_ZoneAddStockpile>(SmartStockpileDesignatorWorker, designatorType);
            }

            // Reallow Thing in Stockpile
            {
                reallowGizmoType = AccessTools.TypeByName("SmartStockpileCreation.RimObjs.DisallowInStockpile.ReallowInStockpileGizmo");

                thingDefLabel      = AccessTools.FieldRefAccess <ThingDef>(reallowGizmoType, "_thingDef");
                zoneStockpileLabel = AccessTools.FieldRefAccess <Zone_Stockpile>(reallowGizmoType, "_zoneStockpile");
                categoryLabel      = AccessTools.FieldRefAccess <ThingCategoryDef>(reallowGizmoType, "_category");

                MP.RegisterSyncMethod(AccessTools.Method(reallowGizmoType, "ProcessInput")).SetContext(SyncContext.MapSelected);
                MP.RegisterSyncWorker <Command>(ReallowInStockpileGizmoWorker, reallowGizmoType);
            }

            // Disallow Thing in Stockpile
            {
                disallowGizmoType = AccessTools.TypeByName("SmartStockpileCreation.RimObjs.DisallowInStockpile.RemoveFromStockpileGizmo");

                thingLabel = AccessTools.FieldRefAccess <Thing>(disallowGizmoType, "_thing");

                MP.RegisterSyncMethod(AccessTools.Method(disallowGizmoType, "Process")).SetContext(SyncContext.MapSelected);
                MP.RegisterSyncWorker <Command>(RemoveFromStockpileGizmoWorker, disallowGizmoType);
            }
        }
Exemplo n.º 23
0
        public CorruptionCore(ModContentPack mod)
        {
            // ITab_Pawn_Soul - checkboxes to allow praying and show prayers
            var type = AccessTools.TypeByName("Corruption.Core.Soul.ITab_Pawn_Soul");

            pawnSoulITabSoulToShowGetter = MethodInvoker.GetHandler(AccessTools.PropertyGetter(type, "SoulToShow"));
            MP.RegisterSyncMethod(typeof(CorruptionCore), nameof(SyncFavourValue));
            MpCompat.harmony.Patch(AccessTools.Method(type, "FillTab"),
                                   prefix: new HarmonyMethod(typeof(CorruptionCore), nameof(PreFillTab)),
                                   postfix: new HarmonyMethod(typeof(CorruptionCore), nameof(PostFillTab)));

            type = AccessTools.TypeByName("Corruption.Core.Soul.CompSoul");
            compSoulFavourTrackerField = AccessTools.FieldRefAccess <object>(type, "FavourTracker");
            compSoulPrayerTrackerField = AccessTools.FieldRefAccess <object>(type, "PrayerTracker");

            type = AccessTools.TypeByName("Corruption.Core.Dialog_SetPawnPantheon");
            setPawnPantheonDialogConstructor = AccessTools.DeclaredConstructor(type);
            setPawnPantheonDialogSoulField   = AccessTools.FieldRefAccess <ThingComp>(type, "soul");
            MP.RegisterSyncMethod(type, "SelectionChanged");
            MP.RegisterSyncWorker <object>(SyncDialogSetPawnPantheon, type);

            type = AccessTools.TypeByName("Corruption.Core.Soul.Soul_FavourTracker");
            soulFavourTrackerFavoursField = AccessTools.FieldRefAccess <IList>(type, "Favours");

            type = AccessTools.TypeByName("Corruption.Core.Gods.Pawn_PrayerTracker");
            prayerTrackerCompSoulField    = AccessTools.FieldRefAccess <ThingComp>(type, "compSoul");
            prayerTrackerAllowPrayingSync = MP.RegisterSyncField(type, "AllowPraying");
            prayerTrackerShowPrayerSync   = MP.RegisterSyncField(type, "ShowPrayer");
            MP.RegisterSyncWorker <object>(SyncPawnPrayerTracker, type);
            MpCompat.harmony.Patch(AccessTools.Method(type, "AdvancePrayer"),
                                   prefix: new HarmonyMethod(typeof(CorruptionCore), nameof(PreAdvancePrayer)),
                                   postfix: new HarmonyMethod(typeof(CorruptionCore), nameof(PostAdvancePrayer)));

            type = AccessTools.TypeByName("Corruption.Core.Soul.FavourProgress");
            favourProgressFavourValueField = AccessTools.FieldRefAccess <float>(type, "favourValue");
        }
Exemplo n.º 24
0
 public static void Initialize()
 {
     FR_stationId     = AccessTools.FieldRefAccess <int>(typeof(UIStationWindow), "_stationId");
     FR_storageUIs    = AccessTools.FieldRefAccess <UIStationStorage[]>(typeof(UIStationWindow), "storageUIs");
     MI_RefreshValues = AccessTools.Method(typeof(UIStationStorage), "RefreshValues");
 }
 static bool Prepare()
 {
     m_DescriptionRef = Accessors.CreateFieldRef<GlobalMapRandomEncounterController, TextMeshProUGUI>("m_Description");
     return true;
 }
Exemplo n.º 26
0
        public VanillaFactionsPirates(ModContentPack mod)
        {
            // Gizmos
            {
                // Enable/disable siege mode
                MpCompat.RegisterLambdaMethod("VFEPirates.Ability_SiegeMode", "GetGizmo", 0, 2);
                // Trigger flight towards tile (right now, the TransportPodsArrivalAction parameter is always null)
                MP.RegisterSyncMethod(AccessTools.TypeByName("VFEPirates.Ability_BlastOff"), "TryLaunch").ExposeParameter(1);
            }

            // Warcasket dialog
            {
                // Dialog_WarcasketCustomization
                warcasketDialogType         = AccessTools.TypeByName("VFEPirates.Buildings.Dialog_WarcasketCustomization");
                notifySettingsChangedMethod = AccessTools.Method(warcasketDialogType, "Notify_SettingsChanged");
                warcasketProjectField       = AccessTools.FieldRefAccess <object>(warcasketDialogType, "project");

                MP.RegisterSyncWorker <Window>(SyncWarcasketCustomizationDialog, warcasketDialogType);

                MP.RegisterSyncMethod(warcasketDialogType, "OnAcceptKeyPressed");
                MP.RegisterSyncMethod(warcasketDialogType, "OnCancelKeyPressed");

                MpCompat.RegisterLambdaMethod(warcasketDialogType, "DoWindowContents", 0, 1, 2);

                MpCompat.harmony.Patch(AccessTools.Method(warcasketDialogType, "DoWindowContents"),
                                       prefix: new HarmonyMethod(typeof(VanillaFactionsPirates), nameof(PreDoWindowContents)),
                                       postfix: new HarmonyMethod(typeof(VanillaFactionsPirates), nameof(PostDoWindowContents)));

                // WarcasketProject
                var type = AccessTools.TypeByName("VFEPirates.WarcasketProject");

                helmetColorField       = AccessTools.FieldRefAccess <Color>(type, "colorHelmet");
                shoulderPadsColorField = AccessTools.FieldRefAccess <Color>(type, "colorShoulderPads");
                armorColorField        = AccessTools.FieldRefAccess <Color>(type, "colorArmor");

                MP.RegisterSyncMethod(typeof(VanillaFactionsPirates), nameof(SyncedSetColors));
                MP.RegisterPauseLock(PauseIfDialogOpen);
            }

            // Curse window
            {
                // Page_ChooseCurses
                MP.RegisterSyncMethod(typeof(VanillaFactionsPirates), nameof(SyncedSetCurse));
                MpCompat.harmony.Patch(AccessTools.Method("VFEPirates.Page_ChooseCurses:DoCurse"),
                                       transpiler: new HarmonyMethod(typeof(VanillaFactionsPirates), nameof(ReplaceButton)));

                // GameComponent_CurseManager
                var type = AccessTools.TypeByName("VFEPirates.GameComponent_CurseManager");

                curseManagerInstanceField = AccessTools.StaticFieldRefAccess <GameComponent>(AccessTools.Field(type, "Instance"));
                activeCurseDefsField      = AccessTools.FieldRefAccess <IEnumerable>(type, "activeCurseDefs");
                removeCurseMethod         = AccessTools.Method(type, "Remove");
                addCurseMethod            = AccessTools.Method(type, "Add");

                // CurseDef
                curseDefWorkerGetter = AccessTools.PropertyGetter(AccessTools.TypeByName("VFEPirates.CurseDef"), "Worker");

                // CurseWorker
                type = AccessTools.TypeByName("VFEPirates.CurseWorker");

                curseWorkerDisactivateMethod = AccessTools.Method(type, "Disactivate");
                curseWorkerStartMethod       = AccessTools.Method(type, "Start");
            }
        }
Exemplo n.º 27
0
 public ClassFieldRefTestCase(AccessTools.FieldRef <T, F> fieldRef)
 {
     this.fieldRef = fieldRef;
 }
        public VanillaPowerExpanded(ModContentPack mod)
        {
            Type type;

            // Gizmos
            // Debug fill/empty
            {
                type = AccessTools.TypeByName("GasNetwork.CompGasStorage");
                // Both these methods are calling (basically) the same method,
                // but that method also has other callers that don't need syncing
                MpCompat.RegisterLambdaMethod(type, "CompGetGizmosExtra", 0, 1).SetDebugOnly();
            }

            // Order to or cancel plugging the hole (method names shared by both types)
            {
                var types = new[]
                {
                    "VanillaPowerExpanded.Building_ChemfuelPond",
                    "VanillaPowerExpanded.Building_GasGeyser",
                };
                foreach (var typeName in types)
                {
                    type = AccessTools.TypeByName(typeName);
                    MP.RegisterSyncMethod(type, "SetHoleForPlugging");
                    MP.RegisterSyncMethod(type, "CancelHoleForPlugging");
                }
            }

            // Violence generator
            {
                type = AccessTools.TypeByName("VanillaPowerExpanded.CompSoulsPowerPlant");
                MpCompat.RegisterLambdaMethod(type, "CompGetGizmosExtra", 1); // Toggle on/off
            }

            // RNG Fix
            {
                // Patch GasNetwork.MapComponent_WindDirection ctor
                PatchingUtilities.PatchSystemRand(AccessTools.Constructor(AccessTools.TypeByName("GasNetwork.MapComponent_WindDirection"), new Type[] { typeof(Map) }), false);

                var methods = new[]
                {
                    "VanillaPowerExpanded.Building_SmallBattery:Tick",
                    "VanillaPowerExpanded.Building_SmallBattery:PostApplyDamage",
                    "VanillaPowerExpanded.WeatherEvent_CustomLightningStrike:FireEvent",
                    "VanillaPowerExpanded.MapComponentExtender:doMapSpawns",
                    "VanillaPowerExpanded.CompPlantHarmRadiusIfBroken:CompTick",
                    // HarmRandomPlantInRadius is only called by CompPlantHarmRadiusIfBroken:CompTick, no need for patching
                    // CompPowerPlantNuclear:AffectCell is only calling a seeded random
                    "VanillaPowerExpanded.IntermittentGasSprayer:SteamSprayerTick",
                    // IntermittentGasSprayer - NewBaseAirPuff is only called by ThrowAirPuffUp which is called by SteamSprayerTick, no need for patching
                    // Building_GasGeyser:StartSpray is assigned to IntermittentGasSprayer:startSprayCallback, which is called from SteamSprayerTick
                    "GasNetwork.GasNet:GasNetTick",
                    "GasNetwork.MapComponent_WindDirection:MapGenerated",
                    // PipeNetGrid pushes and pops all Rand calls, no need to patch
                    // CompPowerAdvancedWater:RebuildCache is only calling a seeded random
                };

                // These methods are loading resources in their .ctor, must be patched later
                var methodsForLater = new[]
                {
                    "VanillaPowerExpanded.CompPowerAdvancedWater:PostSpawnSetup",
                    "VanillaPowerExpanded.CompPowerAdvancedWind:PostSpawnSetup",
                };

                PatchingUtilities.PatchPushPopRand(methods);
                LongEventHandler.ExecuteWhenFinished(() => PatchingUtilities.PatchPushPopRand(methodsForLater));

                // Wind map comp
                windDirectionField = AccessTools.FieldRefAccess <float>(AccessTools.TypeByName("GasNetwork.MapComponent_WindDirection"), "windDirection");
                MpCompat.harmony.Patch(AccessTools.Method("GasNetwork.MapComponent_WindDirection:MapComponentTick"),
                                       prefix: new HarmonyMethod(typeof(VanillaPowerExpanded), nameof(ReplaceWindMapComponentTick)));

                // GasNet utilities
                MpCompat.harmony.Patch(AccessTools.Method("GasNetwork.Utilities:HashOffsetTicks"),
                                       prefix: new HarmonyMethod(typeof(VanillaPowerExpanded), nameof(ReplaceHashOffsetTicks)));
            }
        }
Exemplo n.º 29
0
 // AccessTools2.FieldRefAccess
 // Note: This can't have generic class constraint since there are some FieldRefAccess methods that work with struct static fields.
 static IATestCase <T, F> ATestCase <T, F>(AccessTools.FieldRef <T, F> fieldRef) where T : class
 {
     return(new ClassFieldRefTestCase <T, F>(fieldRef));
 }
Exemplo n.º 30
0
 static SpawnPmcPatch()
 {
     targetType         = typeof(BotSpawner);
     wildSpawnTypeField = AccessTools.FieldRefAccess <WildSpawnType>(targetType, "Type");
     botDifficultyField = AccessTools.FieldRefAccess <BotDifficulty>(targetType, "BotDifficulty");
 }