コード例 #1
0
 /// <summary>
 /// Transpiles Place to properly place special buildings.
 /// </summary>
 internal static IEnumerable <CodeInstruction> Transpiler(
     IEnumerable <CodeInstruction> method)
 {
     return(PPatchTools.ReplaceMethodCall(method, PPatchTools.GetMethodSafe(
                                              typeof(BuildingDef), nameof(BuildingDef.Build), false, PPatchTools.
                                              AnyArguments), PPatchTools.GetMethodSafe(typeof(SandboxToolsPatches),
                                                                                       nameof(BuildFixedMaterials), true, PPatchTools.AnyArguments)));
 }
コード例 #2
0
ファイル: OptionsDialog.cs プロジェクト: pether-pg/ONIMods
        /// <summary>
        /// Calls the user OnOptionsChanged handler if present.
        /// </summary>
        /// <param name="options">The updated options object.</param>
        private void TriggerUpdateOptions(object options)
        {
            // Call the user handler
            var onSave = PPatchTools.GetMethodSafe(options.GetType(), nameof(IOptions.
                                                                             OnOptionsChanged), false);

            if (onSave != null)
            {
                try {
                    onSave.Invoke(options, null);
                } catch (TargetInvocationException e) {
                    PUtil.LogException(e.GetBaseException());
                }
            }
            handler.OnSaveOptions(options);
        }
コード例 #3
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);
                }
            }
コード例 #4
0
ファイル: OptionsEntry.cs プロジェクト: pether-pg/ONIMods
        internal static IDictionary <string, OptionsList> AddCustomOptions(object options,
                                                                           IDictionary <string, OptionsList> existing)
        {
            System.Collections.IEnumerable customOptions = null;
            // Call the user handler
            var createOptions = PPatchTools.GetMethodSafe(options.GetType(), nameof(IOptions.
                                                                                    CreateOptions), false);
            var entries = existing;

            if (createOptions != null)
            {
                try {
                    customOptions = createOptions.Invoke(options, null) as System.
                                    Collections.IEnumerable;
                } catch (TargetInvocationException e) {
                    PUtil.LogException(e.GetBaseException());
                }
            }
            if (customOptions != null)
            {
                // Middle-depth copy of the existing categories as it can change on each dialog
                entries = new SortedList <string, OptionsList>(entries.Count);
                foreach (var pair in existing)
                {
                    entries.Add(pair.Key, new List <OptionsEntry>(pair.Value));
                }
                foreach (var value in customOptions)
                {
                    if (value != null)
                    {
                        AddToCategory(entries, DynamicOptionsEntry.Create(value));
                    }
                }
            }
            return(entries);
        }