internal static void ShutDownProcessPatch(On.Menu.OptionsMenu.orig_ShutDownProcess orig, OptionsMenu menu)
        {
            orig.Invoke(menu);

            if (OptionScript.ComModExists)
            {
                if (menu.CurrLang != InGameTranslator.LanguageID.Portuguese)
                {
                    OptionScript.curLang = (string)OptionScript.ComMod.GetType().GetField("customLang", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(OptionScript.ComMod);
                }
                else
                {
                    OptionScript.curLang = "eng";
                }
            }
            else
            {
                OptionScript.curLang = OptionScript.ID2Code[(int)menu.CurrLang];
            }
            InternalTranslator.LoadTranslation();

            string songid = "";

            if (menu.manager.musicPlayer != null)
            {
                songid = menu.manager.musicPlayer.song?.name.Substring(0, 5);
            }

            if (!mod)
            { //going back to main menu
                if (menu.manager.musicPlayer != null && songid != "RW_8 " && songid != "Title")
                {
                    Debug.Log(string.Concat("Shutdown Option Music :" + menu.manager.musicPlayer.song?.name));
                    menu.manager.musicPlayer.nextSong = new MenuOrSlideShowSong(menu.manager.musicPlayer, "RW_8 - Sundown", 0.8f, 2f)
                    {
                        playWhenReady = false
                    };
                }
            }
            if (enterConfig != null)
            {
                enterConfig.RemoveSprites();
                enterConfig = null;
            }
        }
示例#2
0
        /// <summary>
        /// Runs right before MainMenu opens
        /// </summary>
        private static void Initialize()
        {
            //Application.RegisterLogCallback(new Application.LogCallback(TroubleShoot));

            ID2Code = new Dictionary <int, string>()
            {
                { 0, "eng" },
                { 1, "fre" },
                { 2, "ita" },
                { 3, "ger" },
                { 4, "spa" },
                { 5, "por" },
                { 6, "jap" },
                { 7, "kor" }
            };
            if (ID2Code.TryGetValue(rw.options.language, out string code))
            {
                curLang = code;
            }
            else
            {
                curLang = "eng";
            }
            string curCurLang = curLang;

            InternalTranslator.LoadTranslation();

            #region PartialityMods
            loadedMods           = Partiality.PartialityManager.Instance.modManager.loadedMods;
            loadedModsDictionary = new Dictionary <string, PartialityMod>();
            ComModExists         = false;
            foreach (PartialityMod mod in loadedMods)
            {
                if (string.IsNullOrEmpty(mod.ModID))
                {
                    goto invaildID;
                }
                if (blackList.Contains <string>(mod.ModID)) //No Config for this :P
                {
                    if (mod.ModID == "CommunicationModule")
                    {
                        ComMod = mod; ComModExists = true;
                        if (rw.options.language != 5)
                        {
                            curLang = (string)mod.GetType().GetField("customLang", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(mod);
                        }
                        else
                        {
                            curLang = "eng";
                        }
                    }
                    continue;
                }
                if (mod.ModID.Substring(0, 1) == "_")
                {
                    continue;
                }                                                   //Skip this mod from configuration
                if (mod.ModID == "SlugBase")
                {
                    SlugBaseMod = mod; SlugBaseExists = true;
                }

                if (loadedModsDictionary.ContainsKey(mod.ModID))
                {
                    Debug.LogError($"Duplicate ModID detected! (dupe ID: {mod.ModID})");
                }
                else if (Regex.IsMatch(mod.ModID, "^[^\\/?%*:|\"<>/.]+$"))
                {
                    loadedModsDictionary.Add(mod.ModID, mod); continue;
                }

invaildID:
                string InvalidID = string.IsNullOrEmpty(mod.ModID) ? "No ModID" : mod.ModID;
                Debug.Log($"{InvalidID} does not support CompletelyOptional: Invalid Mod ID! Using Mod Type name instead.");
                mod.ModID = mod.GetType().Name;
                //Assembly.GetAssembly(this.mod.GetType());
                if (!ValidModIDCheck(mod.ModID))
                {
                    Debug.Log($"{mod.ModID} does not support CompletelyOptional either! Using Assembly Name instead.");
                    mod.ModID = Assembly.GetAssembly(mod.GetType()).GetName().Name;
                    if (!ValidModIDCheck(mod.ModID))
                    {
                        Debug.Log($"{mod.ModID} does not support CompletelyOptional either! Abandoning {InvalidID}!"); continue;
                    }
                }
                loadedModsDictionary.Add(mod.ModID, mod);
            }

            //Debug.Log(string.Concat("curLang: ", curLang));
            if (curCurLang != curLang)
            {
                InternalTranslator.LoadTranslation();
            }

            isOptionMenu        = false;
            loadedInterfaceDict = new Dictionary <string, OptionInterface>();
            loadedInterfaces    = new List <OptionInterface>();

            //No Mods Installed!
            if (loadedModsDictionary.Count == 0 && !OptionMod.ReferencesBepInEx)
            {
                loadedModsDictionary = new Dictionary <string, PartialityMod>(1);
                PartialityMod blankMod = new PartialityMod
                {
                    ModID   = "No Mods Installed",
                    Version = "XXXX",
                    author  = RainWorldMod.authorNull
                };
                loadedModsDictionary.Add(blankMod.ModID, blankMod);

                UnconfiguableOI itf = new UnconfiguableOI(blankMod, UnconfiguableOI.Reason.NoMod);
                loadedInterfaceDict.Add(blankMod.ModID, itf);
                loadedInterfaces.Add(itf);

                return;
            }

            //Load Mod Interfaces!
            foreach (KeyValuePair <string, PartialityMod> item in loadedModsDictionary)
            {
                PartialityMod   mod = loadedModsDictionary[item.Key];
                OptionInterface itf;

                try
                {
                    var method = mod.GetType().GetMethod("LoadOI");
                    if (method == null || method.GetParameters().Length > 0 || method.ContainsGenericParameters)
                    {
                        // Mod didn't attempt to interface with CompletelyOptional, don't bother logging it.
                        itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                    }
                    else if (method.Invoke(mod, null) is OptionInterface oi)
                    {
                        itf = oi;
                        //Your code
                        Debug.Log($"Loaded OptionInterface from {mod.ModID} (type: {itf.GetType()})");
                    }
                    else
                    {
                        itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                        Debug.Log($"{mod.ModID} did not return an OptionInterface in LoadOI.");
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log($"{mod.ModID} threw an exception in LoadOI: {ex.Message}");
                    itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                }

                if (itf.rwMod.mod == null)
                {
                    NullModException e = new NullModException(mod.ModID);
                    Debug.Log(e); Debug.LogException(e);
                    itf.rwMod = new RainWorldMod(mod);
                    // itf = new UnconfiguableOI(mod, e);
                }

                try
                {
                    itf.Initialize();
                }
                catch (Exception ex)
                { //try catch better
                    itf = new UnconfiguableOI(mod, new GeneralInitializeException(ex));
                    itf.Initialize();
                }

                if (itf.Tabs == null || itf.Tabs.Length < 1)
                {
                    itf = new UnconfiguableOI(itf.rwMod, new NoTabException(mod.ModID));
                    itf.Initialize();
                    //OptionScript.loadedInterfaceDict.Remove(mod.ModID);
                    //OptionScript.loadedInterfaceDict.Add(mod.ModID, itf);
                }
                else if (itf.Configuable())
                {
                    if (itf.LoadConfig())
                    {
                        Debug.Log($"CompletelyOptional) {itf.rwMod.ModID} config has been loaded.");
                    }
                    else
                    {
                        Debug.Log($"CompletelyOptional) {itf.rwMod.ModID} does not have config.json.");
                        //itf.Initialize();
                        try
                        {
                            itf.SaveConfig(itf.GrabConfig());
                            Debug.Log($"CompletelyOptional) {itf.rwMod.ModID} uses default config.");
                        }
                        catch (Exception e)
                        {
                            Debug.Log("Saving Default Config Failed.");
                            Debug.Log(e);
                        }
                    }
                }

                loadedInterfaces.Add(itf);
                loadedInterfaceDict.Add(itf.rwMod.ModID, itf);
                //loadedModsDictionary[item.Key].GetType().GetMember("OI")
            }
            // Progression of loaded OIs
            ProgressData.SubPatch();
            if (OptionScript.rw.setup.loadProg)
            {
                ProgressData.LoadOIsProgression();
            }

            #endregion PartialityMods

            #region InternalTest
            if (OptionMod.testing)
            {
#pragma warning disable CS0162
                PartialityMod temp = new PartialityMod()
                {
                    author  = "topicular",
                    ModID   = "InternalTest",
                    Version = OptionMod.instance.Version
                };
                loadedModsDictionary.Add(temp.ModID, temp);
                OptionInterface itf = new InternalTestOI(temp);
                try { itf.Initialize(); }
                catch (Exception ex)
                {
                    itf = new UnconfiguableOI(temp, new GeneralInitializeException(ex));
                    itf.Initialize();
                }
                loadedInterfaces.Add(itf);
                loadedInterfaceDict.Add(temp.ModID, itf);
#pragma warning restore CS0162
            }
            #endregion InternalTest

            // dual's code
            if (OptionMod.ReferencesBepInEx)
            {
                LoadBaseUnityPlugins();
            }

            Debug.Log($"CompletelyOptional finished initializing {loadedInterfaceDict.Count} OIs.");
        }