Beispiel #1
0
        protected override void OnSubModuleLoad()
        {
            SyncObject = (SyncObjectV1)Module.CurrentModule.GetInitialStateOptionWithId(SyncObjectV1.SyncId);
            if (SyncObject == null) // This is the first mod to initialize MBOptionScreen
            {
                try
                {
                    new Harmony("bannerlord.mboptionscreen").PatchAll(typeof(MBOptionScreenSubModule).Assembly);
                }
                catch (Exception ex)
                {
                    // TODO
                }

                // Find the latest implementation among loaded mods
                // as the game seems to be able to load multiple versions of an
                // assembly if it has a strong name
                var version = ApplicationVersionParser.TryParse(Managed.GetVersionStr(), out var v) ? v : default;
                var modOptionsGauntletScreenType = AttributeHelper.Get <ModuleOptionVersionAttribute>(version);
                var fileStorageType     = AttributeHelper.Get <FileStorageVersionAttribute>(version);
                var settingsStorageType = AttributeHelper.Get <SettingsStorageVersionAttribute>(version);

                SyncObject = new SyncObjectV1
                {
                    FileStorage     = (IFileStorage)Activator.CreateInstance(fileStorageType.Type),
                    SettingsStorage = (ISettingsStorage)Activator.CreateInstance(settingsStorageType.Type),
                    ModOptionScreen = modOptionsGauntletScreenType.Type
                };

                Module.CurrentModule.AddInitialStateOption(SyncObject); // Workaround
                Module.CurrentModule.AddInitialStateOption(new InitialStateOption("ModOptionsMenu", new TextObject("{=HiZbHGvYG}Mod Options"), 9990, () =>
                {
                    var screen = (ScreenBase)Activator.CreateInstance(SyncObject.ModOptionScreen);
                    ScreenManager.PushScreen(screen);
                }, false));

                FileDatabase.FileDatabase.Initialize("ModOptions");
            }


            var settingsEnumerable = AppDomain.CurrentDomain.GetAssemblies()
                                     .SelectMany(a => a.DefinedTypes)
                                     .Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(SettingsBase)) && t != typeof(Settings));

            foreach (var settings in settingsEnumerable)
            {
                SettingsDatabase.RegisterSettings((SettingsBase)Activator.CreateInstance(settings));
            }
        }
Beispiel #2
0
 public static ApplicationVersion GameVersion() => TryParse(Managed.GetVersionStr(), out var v) ? v : default;