Пример #1
0
        // We don't want one patch failure to take down the entire mod, so they're applied individually.
        //
        // Also, in general the return value should be ignored. If a patch fails, we still want to create
        // blueprints, otherwise the save won't load. Better to have something be non-functional.
        internal static bool ApplyPatch(Type type, String featureName)
        {
            try
            {
                if (typesPatched.ContainsKey(type))
                {
                    return(typesPatched[type]);
                }

                var patchInfo = Harmony12.HarmonyMethodExtensions.GetHarmonyMethods(type);
                if (patchInfo == null || patchInfo.Count() == 0)
                {
                    Log.Error($"Failed to apply patch {type}: could not find Harmony attributes");
                    failedPatches.Add(featureName);
                    typesPatched.Add(type, false);
                    return(false);
                }
                var processor = new Harmony12.PatchProcessor(harmonyInstance, type, Harmony12.HarmonyMethod.Merge(patchInfo));
                var patch     = processor.Patch().FirstOrDefault();
                if (patch == null)
                {
                    Log.Error($"Failed to apply patch {type}: no dynamic method generated");
                    failedPatches.Add(featureName);
                    typesPatched.Add(type, false);
                    return(false);
                }
                typesPatched.Add(type, true);
                return(true);
            }
            catch (Exception e)
            {
                Log.Error($"Failed to apply patch {type}: {e}");
                failedPatches.Add(featureName);
                typesPatched.Add(type, false);
                return(false);
            }
        }
Пример #2
0
        // We don't want one patch failure to take down the entire mod, so they're applied individually.
        //
        // Also, in general the return value should be ignored. If a patch fails, we still want to create
        // blueprints, otherwise the save won't load. Better to have something be non-functional.
        internal static bool ApplyPatch(Type type, String featureName)
        {
            try
            {
                if (typesPatched.ContainsKey(type))
                {
                    return(typesPatched[type]);
                }

                var patchInfo = Harmony12.HarmonyMethodExtensions.GetHarmonyMethods(type);
                if (patchInfo == null || patchInfo.Count() == 0)
                {
                    Log.Error(string.Format(RES.applyPathHarmony_error, type));
                    failedPatches.Add(featureName);
                    typesPatched.Add(type, false);
                    return(false);
                }
                var processor = new Harmony12.PatchProcessor(harmonyInstance, type, Harmony12.HarmonyMethod.Merge(patchInfo));
                var patch     = processor.Patch().FirstOrDefault();
                if (patch == null)
                {
                    Log.Error(string.Format(RES.applyPathMethod, type));
                    failedPatches.Add(featureName);
                    typesPatched.Add(type, false);
                    return(false);
                }
                typesPatched.Add(type, true);
                return(true);
            }
            catch (Exception e)
            {
                Log.Error(string.Format(RES.applyPatch_error, type, e));
                failedPatches.Add(featureName);
                typesPatched.Add(type, false);
                return(false);
            }
        }