コード例 #1
0
        static AchievementHarmony()
        {
            AchievementsMMD = ModLister.GetActiveModWithIdentifier(modIdentifier);

            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            CurrentVersion = $"{version.Major}.{version.Minor}.{version.Build}";
            Log.Message($"{AchievementPointManager.AchievementTag} version {CurrentVersion}");

            AchievementPointManager.OnStartUp();
            var harmony = new Harmony(modIdentifier);

            if (UtilityMethods.BaseModActive)
            {
                File.WriteAllText(VersionDir, CurrentVersion);

                harmony.PatchAll();
                /// <summary>
                /// Automated Patches by allowing user to specify MethodInfo.
                /// Solely for organization regarding Trackers
                /// </summary>
                foreach (TrackerBase tracker in AchievementPointManager.TrackersGenerated)
                {
                    if (tracker.MethodHook != null && tracker.PatchMethod != null)
                    {
                        if (TryRegisterPatch(tracker.MethodHook, tracker.PatchMethod))
                        {
                            switch (tracker.PatchType)
                            {
                            case PatchType.Prefix:
                                harmony.Patch(original: tracker.MethodHook,
                                              prefix: new HarmonyMethod(tracker.PatchMethod));
                                break;

                            case PatchType.Postfix:
                                harmony.Patch(original: tracker.MethodHook,
                                              postfix: new HarmonyMethod(tracker.PatchMethod));
                                break;

                            case PatchType.Transpiler:
                                harmony.Patch(original: tracker.MethodHook,
                                              transpiler: new HarmonyMethod(tracker.PatchMethod));
                                break;

                            case PatchType.Finalizer:
                                harmony.Patch(original: tracker.MethodHook,
                                              finalizer: new HarmonyMethod(tracker.PatchMethod));
                                break;
                            }
                        }
                    }
                }

                /* Additional Event Catches */
                harmony.Patch(original: AccessTools.Method(typeof(Thing), nameof(Thing.Kill)),
                              prefix: new HarmonyMethod(typeof(AchievementHarmony),
                                                        nameof(KillThing)));
                harmony.Patch(original: AccessTools.Method(typeof(Pawn_RecordsTracker), nameof(Pawn_RecordsTracker.AddTo)),
                              postfix: new HarmonyMethod(typeof(AchievementHarmony),
                                                         nameof(RecordAddToEvent)));

                /* Event thrown every Long Tick */
                harmony.Patch(original: AccessTools.Method(typeof(TickManager), nameof(TickManager.DoSingleTick)),
                              postfix: new HarmonyMethod(typeof(AchievementHarmony),
                                                         nameof(SingleLongTickTracker)));

                /* Debug Actions register in menu */
                harmony.Patch(original: AccessTools.Method(typeof(Dialog_DebugActionsMenu), "GenerateCacheForMethod"),
                              prefix: new HarmonyMethod(typeof(DebugActionsSetup),
                                                        nameof(DebugActionsSetup.GenerateCacheForVAEDebugActions)));
                harmony.Patch(original: AccessTools.Constructor(typeof(Dialog_DebugActionsMenu)),
                              prefix: new HarmonyMethod(typeof(DebugActionsSetup),
                                                        nameof(DebugActionsSetup.ClearCachedActions)));

                /* Debugging */
                //harmony.Patch(original: AccessTools.Method(typeof(DebugLoadIDsSavingErrorsChecker), nameof(DebugLoadIDsSavingErrorsChecker.RegisterDeepSaved)),
                //    prefix: new HarmonyMethod(typeof(AchievementHarmony),
                //    nameof(DebugTest)));
            }
        }