コード例 #1
0
        internal BetterInfoCardsCompat()
        {
            RegisterMethodFunc addConv = null;

            exportMethod = null;
            try {
                addConv = PPatchTools.GetTypeSafe(BIC_NAMESPACE + "ConverterManager",
                                                  BIC_ASSEMBLY)?.Detour <RegisterMethodFunc>("AddConverterReflect");
                var patchType = PPatchTools.GetTypeSafe(BIC_NAMESPACE + "CollectHoverInfo",
                                                        BIC_ASSEMBLY)?.GetNestedType("GetSelectInfo_Patch", BindingFlags.Static |
                                                                                     BindingFlags.Instance | PPatchTools.BASE_FLAGS);
                if (patchType != null)
                {
                    exportMethod = patchType.Detour <ExportMethodFunc>("Export");
                }
            } catch (AmbiguousMatchException e) {
                PUtil.LogWarning("Exception when loading Better Info Cards compatibility:");
                PUtil.LogExcWarn(e);
            } catch (DetourException e) {
                PUtil.LogWarning("Exception when loading Better Info Cards compatibility:");
                PUtil.LogExcWarn(e);
            }
            if (addConv != null && exportMethod != null)
            {
                try {
                    Register(addConv, EXPORT_THERMAL_MASS, ObjectToFloat, SumThermalMass);
                    Register(addConv, EXPORT_HEAT_ENERGY, ObjectToFloat, SumHeatEnergy);
                    PUtil.LogDebug("Registered Better Info Cards status data handlers");
                } catch (Exception e) {
                    PUtil.LogWarning("Exception when registering Better Info Cards compatibility:");
                    PUtil.LogExcWarn(e.GetBaseException());
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Registers a converter. While this method seems useless, converting the arguments
 /// to the proper Func types for the parameter is required.
 /// </summary>
 /// <param name="registerMethod">The registration method to call.</param>
 /// <param name="title">The title to classify the data exported.</param>
 /// <param name="getValue">The function which converts the exported object to the data type.</param>
 /// <param name="getTextOverride">The function that accepts the original text and
 /// collapsed cards to convert them into the final text.</param>
 /// <typeparam name="T">The type of data that will be converted.</typeparam>
 private static void Register <T>(RegisterMethodFunc registerMethod, string title,
                                  Func <object, T> getValue, Func <string, List <T>, string> getTextOverride)
 {
     registerMethod.Invoke(title, getValue, getTextOverride, null);
 }