radj307_Actor-Edge-Glow-Remover/RemoveEdgeGlow/Program.cs
using System;
using System.Threading.Tasks;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Plugins.Records;
using Mutagen.Bethesda.Skyrim;
using Mutagen.Bethesda.Synthesis;
using RemoveEdgeGlow.Settings;

namespace RemoveEdgeGlow
{
    public static class Program
    {
        internal static Lazy<TopSettings> _lazySettings = null!;
        internal static TopSettings Settings => _lazySettings.Value;

        // Main
        public static async Task<int> Main(string[] args)
        {
            return await SynthesisPipeline.Instance
                .AddPatch<ISkyrimMod, ISkyrimModGetter>(RunPatch)
                .SetAutogeneratedSettings("Settings", "settings.json", out _lazySettings)
                .SetTypicalOpen(GameRelease.SkyrimSE, "RemoveEdgeGlow.esp")
                .Run(args)
                .ConfigureAwait(false);
        }

        // PatchMain
        public static void RunPatch(IPatcherState<ISkyrimMod, ISkyrimModGetter> state)
        {
            if ( Settings.PrintSettings )
                LogHelper.PrintSettings(Settings);

            Console.WriteLine("\nInitialization Complete.\nBeginning Process...\n");

            int changes = 0; // count modified records

            // iterate through all art objects
            foreach ( var arto in state.LoadOrder.PriorityOrder.ArtObject().WinningContextOverrides() )
            {
                if ( !Settings.IsValidPatcherTarget(arto.Record) || arto.Record.EditorID == null || ( Settings.Plugin.IsWhitelistedPlugin(arto.ModKey) && !Settings.Plugin.IsBlacklistedPlugin(arto.ModKey) ) )
                    continue;

                ArtObject? artoCopy = arto.Record.DeepCopy();

                if ( Settings.ApplySettingsTo(ref artoCopy) )
                {
                    //++changes;
                    state.PatchMod.ArtObjects.Set(artoCopy);
                    Console.WriteLine($"[{++changes}]\tSet {arto.Record.EditorID}{(Settings.PrintFormKeys ? $" ({arto.Record.FormKey})" : "")} model filepath to {Settings.ArtObject.EmptyEffectModel}");
                }
            }
            // iterate through all effect shaders
            foreach ( var efsh in state.LoadOrder.PriorityOrder.EffectShader().WinningContextOverrides() )
            {
                if ( !Settings.IsValidPatcherTarget(efsh.Record) || efsh.Record.EditorID == null || ( Settings.Plugin.IsWhitelistedPlugin(efsh.ModKey) && !Settings.Plugin.IsBlacklistedPlugin(efsh.ModKey) ) )
                    continue;

                EffectShader? efshCopy = efsh.Record.DeepCopy();

                if ( Settings.ApplySettingsTo(ref efshCopy, out int subrecordChangeCount) && subrecordChangeCount > 0 )
                {
                    state.PatchMod.EffectShaders.Set(efshCopy);
                    Console.WriteLine($"[{++changes}]\tModified {subrecordChangeCount} value{( subrecordChangeCount > 1 ? "s" : "" )} in {efsh.Record.EditorID}{( Settings.PrintFormKeys ? $" ({efsh.Record.FormKey})" : "" )}");
                }
            }

            if ( changes == 0 )
                Console.WriteLine("Failed to modify any records! Check your settings!");
            Console.WriteLine($"\nProcess Complete.\nPatched {changes} record{( changes > 1 ? "s" : "" )}.\n");
        }
    }
}
