Esempio n. 1
0
        static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            Main.modEntry = modEntry;
            if (enabled == value)
            {
                return(true);
            }
            enabled = value;

            if (enabled)
            {
                harmonyInstance = HarmonyInstance.Create(modEntry.Info.Id);
                harmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
                if (settingsGUI == null)
                {
                    settingsGUI = ModMenu.Instance.gameObject.AddComponent <SettingsGUI>();
                }
            }
            else
            {
                harmonyInstance.UnpatchAll(harmonyInstance.Id);
                settingsGUI = null;
                UnityEngine.Object.Destroy(ModMenu.Instance.gameObject.GetComponent <SettingsGUI>());
            }
            return(true);
        }
Esempio n. 2
0
        static bool Load(UnityModManager.ModEntry modEntry)
        {
            Main.modEntry      = modEntry;
            settings           = UnityModManager.ModSettings.Load <Settings>(modEntry);
            settingsGUI        = ModMenu.Instance.gameObject.AddComponent <SettingsGUI>();
            modEntry.OnSaveGUI = OnSaveGUI;
            modEntry.OnToggle  = OnToggle;

            // load presets
            var serializer = new XmlSerializer(typeof(Preset));

            string[] filePaths = Directory.GetFiles(modEntry.Path, "*.preset.xml");
            foreach (var filePath in filePaths)
            {
                try {
                    var stream = File.OpenRead(filePath);
                    var result = (Preset)serializer.Deserialize(stream);
                    presets.Add(result.name, result);
                    if (!settings.presetOrder.Contains(result.name))
                    {
                        settings.presetOrder.Add(result.name);
                    }
                    stream.Close();
                    log("preset: " + result.name + " loaded");
                }
                catch (Exception e) {
                    log($"ex: {e}");
                }
            }
            foreach (var presetName in settings.presetOrder.ToArray())
            {
                if (!presets.ContainsKey(presetName))
                {
                    settings.presetOrder.Remove(presetName);
                }
            }
            // apply them?
            return(true);
        }