示例#1
0
        static void AutoEnableOnce(bool deferred)
        {
            if (deferred)
            {
                Singleton <PluginManager> .instance.eventPluginsChanged -= ActiveAutoEnableOnce;
            }

#if DEBUG
            UnityEngine.Debug.LogError($"[{Versioning.FULL_PACKAGE_NAME}] In Mod.AutoEnableOnce({deferred}) plugins={mainMod != null}\n{(new System.Diagnostics.StackTrace(0, true)).ToString()}");
#endif

            if (mainMod != null)
            {
                bool enabled = false;
                if (!Versioning.IsObsolete(Versioning.Obsolescence.AUTO_MOD_ENABLE, "Auto-Mod Enabling for compatibility with old CitiesHarmony.API"))
                {
                    /* FIXME: When auto-subscribing, the API should also enable the mod.
                     * Older API versions do not enable it, so Enabling self here, for compatibility with old APIs.
                     * After a few updates with this warning, this behaviour should be removed.
                     */

                    {
#if DEBUG
                        UnityEngine.Debug.Log($"[{Versioning.FULL_PACKAGE_NAME}] Found - {mainMod.name} - enabled={mainMod.isEnabled} - {mainMod.assembliesString}");
#endif
                        if (mainMod.ContainsAssembly(Assembly.GetExecutingAssembly()))
                        {
                            var oneShotAutoEnable = new SavedBool(name: mainMod.name + mainMod.modPath.GetHashCode().ToString() + ".enabled",
                                                                  fileName: Settings.userGameState,
                                                                  def: false,
                                                                  autoUpdate: true);

                            if (!oneShotAutoEnable && !oneShotAutoEnable.exists)
                            {
                                UnityEngine.Debug.Log($"[{Versioning.FULL_PACKAGE_NAME}] INFO - Mod is disabled in the Content Manager! Self-enabling now.");

                                enabled           = true;
                                firstRun          = true;
                                mainMod.isEnabled = true;

                                /* FIXME: isEnabled vs oneShotAutoEnable.Value = true */
                            }
                            else
                            {
                                UnityEngine.Debug.LogWarning($"[{Versioning.FULL_PACKAGE_NAME}] WARNING - Mod is disabled in the Content Manager! Self-enabling has already been used.");
                            }
                        }
                    }
                }
            }
        }