private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, MethodBase method)
            {
                var PlayAnim = typeof(GameStateMachine <BaggedStates, BaggedStates.Instance, IStateMachineTarget, BaggedStates.Def> .State).GetMethodSafe("PlayAnim", false, typeof(string), typeof(KAnim.PlayMode));
                var Stub     = typeof(BaggedStates_InitializeStates).GetMethodSafe(nameof(PlayAnimStub), true, PPatchTools.AnyArguments);

                return(PPatchTools.ReplaceMethodCall(instructions, PlayAnim, Stub));
            }
            private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, MethodBase method, ILGenerator IL)
            {
                string methodName     = method.DeclaringType.FullName + "." + method.Name;
                var    SetGasProvider = typeof(OxygenBreather).GetMethodSafe(nameof(OxygenBreather.SetGasProvider), false, PPatchTools.AnyArguments);
                var    Stub           = typeof(ClusterTelescope_ClusterTelescopeWorkable_OnWorkableEvent_Oxygen).GetMethodSafe(nameof(StubSetGasProvider), true, PPatchTools.AnyArguments);

                bool result = false;

                if (SetGasProvider != null && Stub != null)
                {
                    instructions = PPatchTools.ReplaceMethodCall(instructions, SetGasProvider, Stub);
                    result       = true;
                }
                if (!result)
                {
                    PUtil.LogWarning($"Could not apply Transpiler to the '{methodName}'");
                }
#if DEBUG
                else
                {
                    PUtil.LogDebug($"'{methodName}' Transpiler injected");
                }
#endif
                return(instructions);
            }
Esempio n. 3
0
 /// <summary>
 /// Transpiles Place to properly place special buildings.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, typeof(BuildingDef).GetMethodSafe(
                                              nameof(BuildingDef.Build), false, PPatchTools.AnyArguments),
                                          typeof(SandboxToolsPatches).GetMethodSafe(nameof(BuildFixedMaterials),
                                                                                    true, PPatchTools.AnyArguments)));
 }
Esempio n. 4
0
 /// <summary>
 /// Applied before DoStateTransition runs.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, typeof(Util).GetMethodSafe(
                                              nameof(Util.KDestroyGameObject), true, typeof(GameObject)),
                                          typeof(MoreAchievementsPatches).GetMethodSafe(nameof(CheckAndDestroy),
                                                                                        true, typeof(GameObject))));
 }
Esempio n. 5
0
 /// <summary>
 /// Transpiles SetActiveResearch to rip out a Sort call in the middle.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, typeof(List <TechInstance>).
                                          GetMethodSafe("Sort", false, new Type[] {
         typeof(Comparison <TechInstance>)
     })));
 }
Esempio n. 6
0
 /// <summary>
 /// Transpiles RefreshCreatureCount to check the right tile for creatures.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, typeof(Grid).GetMethodSafe(
                                              nameof(Grid.PosToCell), true, typeof(KMonoBehaviour)),
                                          typeof(StockBugsPatches).GetMethodSafe(nameof(PosToCorrectedCell), true,
                                                                                 typeof(KMonoBehaviour))));
 }
Esempio n. 7
0
 /// <summary>
 /// Transpiles SlicedSim1000ms to wrap accumulator calls with our own.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, typeof(Accumulators).
                                          GetMethodSafe(nameof(Accumulators.GetAverageRate), false, typeof(
                                                            IntHandle)), typeof(ResourcesInMotionPatches).GetMethodSafe(nameof(
                                                                                                                            GracefulAccumulate), true, PPatchTools.AnyArguments)));
 }
Esempio n. 8
0
 /// <summary>
 /// Transpiles UpdateOverloadTime to fix round off issues.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, typeof(Wire).GetMethodSafe(
                                              nameof(Wire.GetMaxWattageAsFloat), true, typeof(Wire.WattageRating)),
                                          typeof(StockBugsPatches).GetMethodSafe(nameof(GetRoundedMaxWattage), true,
                                                                                 typeof(Wire.WattageRating))));
 }
Esempio n. 9
0
 public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method,
                                          typeof(MinionStartingStats).GetMethodSafe("Apply", false, typeof(GameObject)),
                                          typeof(NewBaseScreen_SpawnMinions_Transpiler).GetMethodSafe("DoXpGive", true,
                                                                                                      typeof(MinionStartingStats), typeof(GameObject))
                                          ));
 }
Esempio n. 10
0
 internal static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, new Dictionary <MethodInfo, MethodInfo>()
     {
         { typeof(Sim).GetMethodSafe(nameof(Sim.SIM_Initialize), true, PPatchTools.AnyArguments), null },
         { typeof(SimMessages).GetMethodSafe(nameof(SimMessages.CreateSimElementsTable), true, PPatchTools.AnyArguments), null },
         { typeof(SimMessages).GetMethodSafe(nameof(SimMessages.CreateDiseaseTable), true, PPatchTools.AnyArguments), null }
     }));
 }
            internal static TranspiledMethod Transpiler(TranspiledMethod instructions,
                                                        MethodBase original)
            {
                var rtb = typeof(TagBits).MakeByRefType();

                return(PPatchTools.ReplaceMethodCall(instructions, typeof(TagBits).
                                                     GetMethodSafe(nameof(TagBits.Or), false, rtb), typeof(TagBitOps).
                                                     GetMethodSafe(nameof(TagBitOps.Or), true, rtb, rtb)));
            }
Esempio n. 12
0
        /// <summary>
        /// Transpiles AsyncPathProbe to use our job manager instead.
        /// </summary>
        internal static IEnumerable <CodeInstruction> Transpiler(
            IEnumerable <CodeInstruction> instructions)
        {
            var workItemType = typeof(IWorkItemCollection);

            return(PPatchTools.ReplaceMethodCall(instructions, typeof(GlobalJobManager).
                                                 GetMethodSafe(nameof(GlobalJobManager.Run), true, workItemType),
                                                 typeof(PathProbeJobManager).GetMethodSafe(nameof(PathProbeJobManager.RunAsync),
                                                                                           true, workItemType)));
        }
        private static IEnumerable <CodeInstruction> LightBuffer_LateUpdate_Transpile(
            IEnumerable <CodeInstruction> body)
        {
            var target = typeof(Light2D).GetPropertySafe <LightShape>(nameof(Light2D.shape),
                                                                      false)?.GetGetMethod(true);

            return((target == null) ? body : PPatchTools.ReplaceMethodCall(body, target,
                                                                           typeof(PLightManager).GetMethodSafe(nameof(PLightManager.LightShapeToRayShape),
                                                                                                               true, typeof(Light2D))));
        }
Esempio n. 14
0
 /// <summary>
 /// Transpiles DoWorldDamage to destroy tiles more intelligently.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     // There are 2 overloads, so types must be specified
     return(PPatchTools.ReplaceMethodCall(method, typeof(WorldDamage).GetMethodSafe(
                                              nameof(WorldDamage.ApplyDamage), false, typeof(int), typeof(float),
                                              typeof(int), typeof(int), typeof(string), typeof(string)),
                                          typeof(StockBugsPatches).GetMethodSafe(nameof(ApplyRocketDamage), true,
                                                                                 PPatchTools.AnyArguments)));
 }
Esempio n. 15
0
            /// <summary>
            /// Transpiles UpdateFalling to replace Grid.Solid calls with calls that respect
            /// Airlock Door.
            /// </summary>
            internal static IEnumerable <CodeInstruction> Transpiler(
                IEnumerable <CodeInstruction> method)
            {
                // Default indexer (this[]) is hardcode named Item
                // https://docs.microsoft.com/en-us/dotnet/api/system.type.getproperty?view=net-5.0
                var indexer = typeof(Grid.BuildFlagsSolidIndexer).GetPropertyIndexedSafe <bool>(
                    "Item", false, typeof(int))?.GetGetMethod();
                var replacement = typeof(AirlockDoorPatches).GetMethodSafe(nameof(
                                                                               SolidAndNotAirlock), true, typeof(Grid.BuildFlagsSolidIndexer).
                                                                           MakeByRefType(), typeof(int));

                return(PPatchTools.ReplaceMethodCall(method, indexer, replacement));
            }
 /// <summary>
 /// Transpiles LoadDLLs to grab the exception information when a mod fails to load.
 /// </summary>
 private static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, new Dictionary <MethodInfo,
                                                                  MethodInfo>()
     {
         { typeof(HarmonyInstance).GetMethodSafe(nameof(HarmonyInstance.Create),
                                                 true, typeof(string)), typeof(ModLoadHandler).GetMethodSafe(nameof(
                                                                                                                 ModLoadHandler.CreateHarmonyInstance), true, typeof(string)) },
         { typeof(Assembly).GetMethodSafe(nameof(Assembly.LoadFrom), true,
                                          typeof(string)), typeof(ModLoadHandler).GetMethodSafe(nameof(
                                                                                                    ModLoadHandler.LoadAssembly), true, typeof(string)) }
     }));
 }
 /// <summary>
 /// Applied to Steam to avoid dialog spam on startup if many mods are updated or
 /// installed.
 /// </summary>
 private static IEnumerable <CodeInstruction> TranspileUpdateMods(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, new Dictionary <MethodInfo,
                                                                  MethodInfo>()
     {
         { typeof(KMod.Manager).GetMethodSafe(nameof(KMod.Manager.Report), false,
                                              typeof(GameObject)), typeof(QueuedReportManager).GetMethodSafe(nameof(
                                                                                                                 QueuedReportManager.QueueDelayedReport), true, typeof(KMod.Manager),
                                                                                                             typeof(GameObject)) },
         { typeof(KMod.Manager).GetMethodSafe(nameof(KMod.Manager.Sanitize), false,
                                              typeof(GameObject)), typeof(QueuedReportManager).GetMethodSafe(nameof(
                                                                                                                 QueuedReportManager.QueueDelayedSanitize), true, typeof(KMod.Manager),
                                                                                                             typeof(GameObject)) }
     }));
 }
Esempio n. 18
0
            /// <summary>
            /// Transpiles CollectChores to interdict the interrupt priority and set it to
            /// Top Priority's interrupt if the chore itself is yellow alert.
            /// </summary>
            internal static IEnumerable <CodeInstruction> Transpiler(
                IEnumerable <CodeInstruction> method)
            {
                Type argType = typeof(Chore.Precondition.Context), listType = typeof(
                    List <Chore.Precondition.Context>);
                var srcMethod = listType.GetMethodSafe(nameof(List <Chore.Precondition.Context> .
                                                              Add), false, argType);

                if (srcMethod == null)
                {
                    throw new InvalidOperationException("Where is List.Add???");
                }
                return(PPatchTools.ReplaceMethodCall(method, srcMethod,
                                                     typeof(SweepFixPatches).GetMethodSafe(nameof(AddAndFixPriority), true,
                                                                                           listType, argType)));
            }
Esempio n. 19
0
            /*
             * --- var infoDialogScreen = GameScreenManager.Instance.StartScreen(blabla);
             +++ var infoDialogScreen = GameScreenManager.Instance.InstantiateScreen(blabla);
             +++blablablabla;
             +++// и вот это много раз:
             +++if (чтототам)
             +++{
             +++    блаблабла;
             +++---     return;
             +++     goto end:
             +++}
             +++blablablabla;
             +++ end:
             +++ ActivateScreen(this, infoDialogScreen);
             +++return;
             */
            private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, MethodBase method, ILGenerator IL)
            {
                var    instructionsList = instructions.ToList();
                string methodName       = method.DeclaringType.FullName + "." + method.Name;

                var StartScreen       = typeof(GameScreenManager).GetMethodSafe(nameof(GameScreenManager.StartScreen), false, PPatchTools.AnyArguments);
                var InstantiateScreen = typeof(GameScreenManager).GetMethodSafe(nameof(GameScreenManager.InstantiateScreen), false, PPatchTools.AnyArguments);
                var activateScreen    = typeof(LoreBearer_OnClickRead).GetMethodSafe(nameof(ActivateScreen), true, PPatchTools.AnyArguments);

                bool result = false;

                if (StartScreen != null && InstantiateScreen != null && activateScreen != null)
                {
                    instructionsList = PPatchTools.ReplaceMethodCall(instructionsList, StartScreen, InstantiateScreen).ToList();
                    var label = IL.DefineLabel();
                    for (int i = 0; i < instructionsList.Count; i++)
                    {
                        var instruction = instructionsList[i];
                        if (instruction.opcode == OpCodes.Ret)
                        {
                            instruction.opcode  = OpCodes.Br_S;
                            instruction.operand = label;
                        }
                    }
                    var end = new CodeInstruction(OpCodes.Nop);
                    end.labels.Add(label);
                    instructionsList.Add(end);
                    instructionsList.Add(new CodeInstruction(OpCodes.Ldarg_0));
                    instructionsList.Add(new CodeInstruction(OpCodes.Ldloc_0));
                    instructionsList.Add(new CodeInstruction(OpCodes.Call, activateScreen));
                    instructionsList.Add(new CodeInstruction(OpCodes.Ret));
                    result = true;
                }
                if (!result)
                {
                    PUtil.LogWarning($"Could not apply Transpiler to the '{methodName}'");
                }
#if DEBUG
                else
                {
                    PUtil.LogDebug($"'{methodName}' Transpiler injected");
                }
#endif
                return(instructionsList);
            }
Esempio n. 20
0
            /// <summary>
            /// Transpiles EarnDestinationAnalysisPoints to replace the cancel destination call
            /// with our queue call.
            /// </summary>
            internal static IEnumerable <CodeInstruction> Transpiler(
                IEnumerable <CodeInstruction> method)
            {
                var oldMethod = PPatchTools.GetMethodSafe(typeof(SpacecraftManager),
                                                          "SetStarmapAnalysisDestinationID", false, typeof(int));
                var newMethod = PPatchTools.GetMethodSafe(typeof(StarmapQueuePatches),
                                                          nameof(QueueNextDestination), true, typeof(SpacecraftManager), typeof(int));

                if (oldMethod != null && newMethod != null)
                {
                    return(PPatchTools.ReplaceMethodCall(method, oldMethod, newMethod));
                }
                else
                {
                    PUtil.LogWarning("Unable to patch starmap queue: method not found");
                    return(method);
                }
            }
            /// <summary>
            /// Transpiles UpdateMods to postpone the report.
            /// </summary>
            internal static IEnumerable <CodeInstruction> Transpiler(
                IEnumerable <CodeInstruction> method)
            {
#if DEBUG
                DebugLogger.LogDebug("Transpiling Steam.UpdateMods()");
#endif
                return(PPatchTools.ReplaceMethodCall(method, new Dictionary <MethodInfo,
                                                                             MethodInfo>()
                {
                    { typeof(Manager).GetMethodSafe(nameof(Manager.Report), false,
                                                    typeof(GameObject)), typeof(QueuedReportManager).GetMethodSafe(nameof(
                                                                                                                       QueuedReportManager.QueueDelayedReport), true, typeof(Manager),
                                                                                                                   typeof(GameObject)) },
                    { typeof(Manager).GetMethodSafe(nameof(Manager.Sanitize), false,
                                                    typeof(GameObject)), typeof(QueuedReportManager).GetMethodSafe(nameof(
                                                                                                                       QueuedReportManager.QueueDelayedSanitize), true, typeof(Manager),
                                                                                                                   typeof(GameObject)) }
                }));
            }
Esempio n. 22
0
            private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, MethodBase method)
            {
                string methodName         = method.DeclaringType.FullName + "." + method.Name;
                var    fetchList_Add      = typeof(FetchList2).GetMethodSafe(nameof(FetchList2.Add), false, typeof(Tag), typeof(Tag[]), typeof(Tag[]), typeof(float), typeof(FetchOrder2.OperationalRequirement));
                var    injectForbiddenTag = typeof(Constructable_OnSpawn).GetMethodSafe(nameof(InjectForbiddenTag), true, PPatchTools.AnyArguments);

                if (fetchList_Add != null && injectForbiddenTag != null)
                {
                    instructions = PPatchTools.ReplaceMethodCall(instructions, fetchList_Add, injectForbiddenTag);
#if DEBUG
                    PUtil.LogDebug($"'{methodName}' Transpiler injected");
#endif
                }
                else
                {
                    PUtil.LogWarning($"Could not apply Transpiler to the '{methodName}'");
                }
                return(instructions);
            }
Esempio n. 23
0
            private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, MethodBase method)
            {
                string methodName           = method.DeclaringType.FullName + "." + method.Name;
                var    AddOrGetDemolishable = typeof(EntityTemplateExtensions).GetMethodSafe(nameof(EntityTemplateExtensions.AddOrGet), true, typeof(GameObject))?.MakeGenericMethod(typeof(Demolishable));
                var    injectSetLocker      = typeof(PropFacilityDeskConfig_CreatePrefab).GetMethodSafe(nameof(InjectSetLocker), true, PPatchTools.AnyArguments);

                if (AddOrGetDemolishable != null && injectSetLocker != null)
                {
                    instructions = PPatchTools.ReplaceMethodCall(instructions, AddOrGetDemolishable, injectSetLocker);
#if DEBUG
                    PUtil.LogDebug($"'{methodName}' Transpiler injected");
#endif
                }
                else
                {
                    PUtil.LogWarning($"Could not apply Transpiler to the '{methodName}'");
                }
                return(instructions);
            }