Ejemplo n.º 1
0
 static ReflectionSettingsTarget()
 {
     JsonSettings = new JsonSerializerSettings();
     JsonSettings.Converters.Add(new StringEnumConverter());
     JsonSettings.AddMutagenConverters();
     JsonSettings.ObjectCreationHandling = ObjectCreationHandling.Replace;
 }
Ejemplo n.º 2
0
        public static void RunPatch(IPatcherState <ISkyrimMod, ISkyrimModGetter> state)
        {
            PatcherSettings settings = Settings.Value;

            PatcherSettings outputSettings = new PatcherSettings(); // only used if Mode == SettingsGen

            Dictionary <ModKey, string> PluginDirectoryDict = initPluginDirectoryDict(settings, state);

            getWarningsToSuppress(settings, state);
            getPathstoIgnore(settings, state);

            if (settings.AssetOutputDirectory != "" && Directory.Exists(settings.AssetOutputDirectory) && settings.ClearAssetOutputDirectory && settings.Mode != Mode.SettingsGen)
            {
                clearOuptutDir(settings);
            }

            if (settings.Mode == Mode.SettingsGen)
            {
                string settingsDirName = "NPC Settings";
                outputSettings.AssetOutputDirectory      = settings.AssetOutputDirectory;
                outputSettings.ClearAssetOutputDirectory = settings.ClearAssetOutputDirectory;
                outputSettings.CopyExtraAssets           = settings.CopyExtraAssets;
                outputSettings.MO2DataPath = settings.MO2DataPath;
                outputSettings.Mode        = Mode.Deep;
                outputSettings.SuppressKnownMissingFileWarnings = settings.SuppressKnownMissingFileWarnings;

                int counter = 0;
                foreach (var npcCO in state.LoadOrder.PriorityOrder.Npc().WinningContextOverrides())
                {
                    if (npcCO.Record.FaceMorph == null)
                    {
                        continue; // skip creatures
                    }
                    generateSettingsForNPC(npcCO, settings, outputSettings, PluginDirectoryDict, state);
                    counter++;
                    if (counter % 100 == 0)
                    {
                        Console.WriteLine("Processed {0} humanoid NPCs", counter++);
                    }
                }

                // write output settings here

                var jsonSettings = new JsonSerializerSettings();
                jsonSettings.Converters.Add(new StringEnumConverter());
                jsonSettings.AddMutagenConverters();
                jsonSettings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                jsonSettings.Formatting             = Formatting.Indented;

                var outputPath = Path.Combine(settings.AssetOutputDirectory, settingsDirName, string.Format("settings_{0:yyyy-MM-dd_hh-mm-ss-tt}.json", DateTime.Now));
                try
                {
                    if (Directory.Exists(settings.AssetOutputDirectory) == false)
                    {
                        Directory.CreateDirectory(settings.AssetOutputDirectory);
                    }
                    if (Directory.Exists(Path.Combine(settings.AssetOutputDirectory, settingsDirName)) == false)
                    {
                        Directory.CreateDirectory(Path.Combine(settings.AssetOutputDirectory, settingsDirName));
                    }

                    string jsonStr = JsonConvert.SerializeObject(outputSettings, jsonSettings);
                    File.WriteAllText(outputPath, jsonStr);
                    Console.WriteLine("Wrote current settings to {0}. Use this file as a backup of your current settings by renaming it to \"settings.json\" and placing it into your Synthesis\\Data\\NPC-Plugin-Chooser folder.", outputPath);
                }
                catch
                {
                    throw new Exception("Could not write the generated settings object to " + outputPath);
                }
            }

            else
            {
                foreach (var PPS in settings.PluginsToForward)
                {
                    Console.WriteLine("Processing {0}", PPS.Plugin.ToString());

                    if (PluginDirectoryDict.ContainsKey(PPS.Plugin) == false)
                    {
                        throw new Exception("Plugin -> Folder dictionary does not contain an entry for plugin " + PPS.Plugin.ToString());
                    }
                    string currentDataDir = PluginDirectoryDict[PPS.Plugin];

                    state.LoadOrder.TryGetValue(PPS.Plugin, out var currentModContext);
                    if (currentModContext != null && currentModContext.Mod != null)
                    {
                        foreach (var npc in currentModContext.Mod.Npcs)
                        {
                            if ((PPS.InvertSelection == false && PPS.NPCs.Contains(npc.AsLinkGetter())) || (PPS.InvertSelection == true && !PPS.NPCs.Contains(npc.AsLinkGetter())))
                            {
                                string NPCdispStr = npc.Name + " | " + npc.EditorID + " | " + npc.FormKey.ToString();
                                Console.WriteLine("Forwarding appearance of {0}", NPCdispStr);
                                if (faceGenExists(npc.FormKey, currentModContext.ModKey, currentDataDir, PPS.ExtraDataDirectories, settings.HandleBSAFiles_Patching, state, out var BSAfiles) == false)
                                {
                                    if (settings.AbortIfMissingFaceGen)
                                    {
                                        throw new Exception("Missing expected FaceGen for NPC " + NPCdispStr + " in folder " + currentDataDir + " (obtained based on plugin " + PPS.Plugin.ToString() + ")");
                                    }
                                    else
                                    {
                                        Console.WriteLine("WARNING: " + "Missing expected FaceGen for NPC " + NPCdispStr + " in folder " + currentDataDir + " (obtained based on plugin " + PPS.Plugin.ToString() + ")");
                                    }
                                }

                                var NPCoverride = addNPCtoPatch(npc, settings, state);
                                copyAssets(NPCoverride, currentModContext.ModKey, settings, currentDataDir, PPS, state);
                            }
                        }
                    }

                    //remap dependencies
                    if (settings.BaseGamePlugins.Contains(PPS.Plugin) == false)
                    {
                        Console.WriteLine("Remapping Dependencies from {0}.", PPS.Plugin.ToString());
                        state.PatchMod.DuplicateFromOnlyReferenced(state.LinkCache, PPS.Plugin, out var _);
                    }
                }
            }
        }