Ejemplo n.º 1
0
 public UnconfiguableOI(PartialityMod mod, Exception exception) : base(mod)
 {
     Tabs           = new OpTab[1];
     Tabs[0]        = new OpTab();
     this.reason    = Reason.InitError;
     this.exception = exception.ToString();
 }
        /// <summary>Loads the Partiality Mods after sorting</summary>
        void LoadPartialityMods()
        {
            string partialityPath = Path.Combine(Paths.BepInExRootPath, "partiality");

            if (!Directory.Exists(partialityPath))
            {
                Directory.CreateDirectory(partialityPath);
                return;
            }

            var modTypes = LoadTypes <PartialityMod>(partialityPath);

            var loadedMods = PartialityManager.Instance.modManager.loadedMods;

            //Load mods from types
            foreach (Type t in modTypes)
            {
                //Don't try to load the base class
                if (t.Name == "PartialityMod")
                {
                    continue;
                }

                try {
                    PartialityMod newMod = (PartialityMod)Activator.CreateInstance(t);

                    newMod.Init();

                    if (newMod.ModID == "NULL")
                    {
                        Logger.LogWarning("Mod With NULL id, assigning the file as the ID");
                        newMod.ModID = t.Name;
                    }

                    loadedMods.Add(newMod);

                    Logger.LogInfo("Initialized mod " + newMod.ModID);
                } catch (Exception e) {
                    Logger.LogError("Could not instantiate Partiality Mod of Type: " + t.Name + "\r\n" + e);
                }
            }

            var loadedModsSorted = loadedMods.OrderBy(mod => mod.loadPriority);

            //Call mod load function
            foreach (PartialityMod pMod in loadedModsSorted)
            {
                try {
                    pMod.OnLoad();
                    pMod.OnEnable();

                    Logger.LogInfo("Loaded mod " + pMod.ModID);
                } catch (Exception e) {
                    Logger.LogError("Could not load Partiality Mod: " + pMod.ModID + "\r\n" + e);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Declare 'Ctor' method in your proxy to run anything in constructor
        /// </summary>
        /// <param name="mod">PartialityMod instance</param>
        /// <param name="proxy">proxy class</param>
        public InterfaceWrapper(PartialityMod mod, object proxy) : base(mod)
        {
            this.proxy = proxy;
            MethodInfo method = proxy.GetType().GetMethod("Ctor");

            if (method != null)
            {
                method.Invoke(proxy, new object[] { this });
            }
        }
Ejemplo n.º 4
0
        public JObject LoadModConfig(PartialityMod mod)
        {
            if (mod == null)
            {
                throw new ArgumentNullException(nameof(mod));
            }
            var path = GetModConfigFilePath(mod);
            var json = File.ReadAllText(path);

            return(JObject.Parse(json));
        }
Ejemplo n.º 5
0
        private string GetModConfigFilePath(PartialityMod mod)
        {
            var configName = mod.ModID;

            if (configName == null)
            {
                throw new ArgumentException("NimbatusMod.Name is null", nameof(mod));
            }
            configName = configName.ToLower();
            var path = Path.Combine(Folder, configName) + FileExtension;

            return(path);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// OptionInterface for Partiality Mod.
        /// Create <c>public static [YourOIclass] LoadOI()</c> in your <see cref="PartialityMod"/>.
        /// ConfigMachine will load your OI after IntroRoll.
        /// </summary>
        /// <remarks>Example:
        /// <code>
        /// public static MyOptionInterface LoadOI()
        /// {
        ///     return new MyOptionInterface(mod: MyMod.instance);
        /// }
        /// </code>
        /// </remarks>
        /// <param name="mod">Your Partiality mod</param>
        public OptionInterface(PartialityMod mod)
        {
#pragma warning disable CS0612
            if (mod != null)
            {
                this.mod = mod; this.rwMod = new RainWorldMod(mod);
            }
#pragma warning restore CS0612
            else
            {
                this.rwMod = new RainWorldMod();
            }
            this.rawConfig = rawConfigDef;
        }
Ejemplo n.º 7
0
 public RainWorldMod(PartialityMod mod)
 {
     this.type        = Type.PartialityMod;
     this.mod         = mod;
     this.ModID       = mod.ModID;
     this.author      = string.IsNullOrEmpty(mod.author) ? authorNull : mod.author;
     this.description = authorNull;
     this.Version     = mod.Version;
     try
     {
         Assembly assm = Assembly.GetAssembly(mod.GetType());
         if (assm.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false).FirstOrDefault() is AssemblyDescriptionAttribute descAttr && !string.IsNullOrEmpty(descAttr.Description))
         {
             description = descAttr.Description;
         }
     }
     catch (Exception) { }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Simple Key Binder. Value is the KeyCode in string form.
        /// </summary>
        /// <param name="pos">LeftBottom Position of this UI</param>
        /// <param name="size">Size. minimum size is 30f*30f.</param>
        /// <param name="mod">Your PartialityMod</param>
        /// <param name="key">Unique Key for UIconfig</param>
        /// <param name="defaultKey">Default Keycode name</param>
        /// <param name="collisionCheck">Whether you will check the key is colliding with other KeyBinder or not</param>
        /// <param name="ctrlerNo">Which controller you want to bind to. The number is equal to RW control config menu.</param>
        public OpKeyBinder(Vector2 pos, Vector2 size, PartialityMod mod, string key, string defaultKey, bool collisionCheck = true, BindController ctrlerNo = BindController.AnyController) : this(pos, size, mod.ModID, key, defaultKey)
        {
            if (string.IsNullOrEmpty(defaultKey))
            {
                throw new ElementFormatException(this, "OpKeyBinderNull: defaultKey for this keyBinder is null.", key);
            }
            this.controlKey = string.Concat(modID, "_", key);
            this.modID      = mod.ModID;
            Vector2 minSize = new Vector2(Mathf.Max(30f, size.x), Mathf.Max(30f, size.y));

            this._size = minSize;
            this.check = collisionCheck;
            this.bind  = ctrlerNo;

            if (!_init)
            {
                return;
            }
            this.Initalize(defaultKey);
        }
Ejemplo n.º 9
0
 public OpKeyBinder(Vector2 pos, Vector2 size, PartialityMod mod, string key, string defaultKey) : this(pos, size, mod.ModID, key, defaultKey)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// This is for using default template, for when you want to use other function of OptionInterface(e.g. <see cref="OptionInterface.Translate(string)"/> but not wanting to set up Config Screen.
 /// </summary>
 /// <param name="mod">PartialityMod instance</param>
 /// <param name="description">Description for your mod</param>
 public GeneratedOI(PartialityMod mod, string description = "") : base(mod)
 {
     mode = GenMode.ModderCall; modDescription = description;
 }
Ejemplo n.º 11
0
        public void Initialize() //UI
        {
            if (vanillaMenu != null)
            {
                vanillaMenu.ShutDownProcess();
                vanillaMenu = null;
            }

            instance = this;
            mute     = true;

#pragma warning disable CS0162 // 접근할 수 없는 코드가 있습니다.
            if (!OptionMod.testing)
            {
                if (!redUnlocked)
                {
                    this.scene = new InteractiveMenuScene(this, this.pages[0], (MenuScene.SceneID)(bgList[Mathf.FloorToInt(UnityEngine.Random.value * (bgList.Length))]));
                }
                else
                {
                    this.scene = new InteractiveMenuScene(this, this.pages[0], (MenuScene.SceneID)(bgListRed[Mathf.FloorToInt(UnityEngine.Random.value * (bgListRed.Length))]));
                }
                Debug.Log(string.Concat("Chosen Background : " + this.scene.sceneID.ToString()));
                this.pages[0].subObjects.Add(this.scene);
            }
            else
            {
                this.scene = new SlideShowMenuScene(this, this.pages[0], MenuScene.SceneID.Intro_4_Walking);
                this.pages[0].subObjects.Add(this.scene);
            }
#pragma warning restore CS0162

            this.fadeSprite.RemoveFromContainer();
            this.pages[0].Container.AddChild(this.fadeSprite); //reset fadeSprite

            this.darkSprite = new FSprite("pixel", true)
            {
                color   = new Color(0f, 0f, 0f),
                anchorX = 0f,
                anchorY = 0f,
                scaleX  = 1368f,
                scaleY  = 770f,
                x       = -1f,
                y       = -1f,
                alpha   = 0.6f
            };
            this.pages[0].Container.AddChild(this.darkSprite);

            modListBound = new OpRect(new Vector2(193f, 240f) - UIelement._offset, new Vector2(280f, 495f), 0.3f);
            //modCanvasBound = new OpRect(new Vector2(553f, 105f), new Vector2(630f, 630f), 0.4f);
            modCanvasBound = new OpRect(new Vector2(543f, 105f) - UIelement._offset, new Vector2(630f, 630f), 0.4f);
            //Base: new Vector2(468f, 120f);
            menuTab.AddItems(modListBound, modCanvasBound);
            this.pages[0].subObjects.Add(modListBound.rect);
            this.pages[0].subObjects.Add(modCanvasBound.rect);

            this.backButton = new SimpleButton(this, this.pages[0], InternalTranslator.Translate("BACK"), "CANCEL", new Vector2(450f, 50f), new Vector2(110f, 30f));
            this.pages[0].subObjects.Add(this.backButton);
            this.saveButton = new SimpleButton(this, this.pages[0], InternalTranslator.Translate("APPLY"), "APPLY", new Vector2(600f, 50f), new Vector2(110f, 30f));
            this.pages[0].subObjects.Add(this.saveButton);
            base.MutualHorizontalButtonBind(saveButton, backButton);
            this.resetButton = new HoldButton(this, this.pages[0], InternalTranslator.Translate("RESET CONFIG"), "RESET CONFIG", new Vector2(300f, 110f), 30f);
            this.pages[0].subObjects.Add(this.resetButton);
            this.alertLabel = new MenuLabel(this, this.pages[0], "", new Vector2(383f, 735f), new Vector2(600f, 30f), false);
            this.pages[0].subObjects.Add(this.alertLabel);
            this.alertLabelFade = 0f; this.lastAlertLabelFade = 0f; this.alertLabelSin = 0f;

            //Dark Box for ModList & Canvas
            //modlist x200 y400 w240 h600
            //canvas  x568 y120 w600 h600

            this.resetButton.nextSelectable[2] = this.backButton;
            this.backButton.nextSelectable[0]  = this.resetButton;
            this.backButton.nextSelectable[2]  = this.saveButton;
            this.saveButton.nextSelectable[0]  = this.backButton;

            menuTab.lblInfoButton           = new OpLabel(new Vector2(233f, 215f) - UIelement._offset, new Vector2(200f, 20f), "Config Machine " + MenuTab.GetCMVersion());
            menuTab.lblInfoButton.bumpBehav = new BumpBehaviour(menuTab.lblInfoButton);
            menuTab.AddItems(menuTab.lblInfoButton);
            this.pages[0].subObjects.Add(menuTab.lblInfoButton.label);

            List <OptionInterface> itfs = new List <OptionInterface>();

            // Initialize
            OptionScript.loadedInterfaceDict.Remove(InternalTranslator.Translate("Mod List")); // Remove old Mod List
            List <UnconfiguableOI> replacedOIs = new List <UnconfiguableOI>();
            foreach (string id in OptionScript.loadedInterfaceDict.Keys)
            {
                OptionInterface itf = OptionScript.loadedInterfaceDict[id];
                Debug.Log(string.Concat("OptionInterface Initializing: " + id));

#pragma warning disable CS0612
                try { itf.Initialize(); }
                catch (Exception ex)
                { itf = new UnconfiguableOI(itf.mod, new GeneralInitializeException(ex)); goto replaced; }

                if (itf.Tabs == null || itf.Tabs.Length < 1)
                {
                    itf = new UnconfiguableOI(itf.mod, new NoTabException(id)); goto replaced;
                }
                else if (itf.Tabs.Length > 20)
                {
                    itf = new UnconfiguableOI(itf.mod, new TooManyTabsException()); goto replaced;
                }

                try { itf.LoadConfig(); itf.ShowConfig(); }
                catch (Exception ex)
                {
                    itf = new UnconfiguableOI(itf.mod, new LoadDataException(string.Concat("OILoad/ShowConfigError: ", id, " had a problem in Load/ShowConfig()\nAre you editing LoadConfig()/ShowConfig()? That could cause serious error.",
                                                                                           Environment.NewLine, ex
                                                                                           )));
                    goto replaced;
                }
#pragma warning restore CS0612

                itfs.Add(itf);
                continue;

replaced:
                itf.Initialize();
                itfs.Add(itf);
                replacedOIs.Add(itf as UnconfiguableOI);
            }
            foreach (UnconfiguableOI itf in replacedOIs)
            {
                OptionScript.loadedInterfaceDict.Remove(itf.rwMod.ModID);
                OptionScript.loadedInterfaceDict.Add(itf.rwMod.ModID, itf);
            }

            // Remove Excess
            int                 priority    = (int)OptionInterface.Priority.NoInterface;
            UnconfiguableOI     listItf     = null;
            List <RainWorldMod> listIgnored = new List <RainWorldMod>();
            while (itfs.Count > 16 && priority < (int)OptionInterface.Priority.Inconfiguable) // 1
            {
                Debug.Log(string.Concat("Mod Count: ", itfs.Count, "! Discarding priority ", priority));

                /* if (priority == -2)
                 * {
                 *  List<OptionInterface> temp2 = new List<OptionInterface>();
                 *  foreach (OptionInterface oi in itfs) { if (oi.GetPriority() > -2) { temp2.Add(oi); } }
                 *  itfs = temp2; priority++; continue;
                 * } */
                if (priority == (int)OptionInterface.Priority.NoInterface)
                {
                    PartialityMod blankMod = new PartialityMod
                    {
                        ModID   = InternalTranslator.Translate("Mod List"),
                        Version = "XXXX",
                        author  = RainWorldMod.authorNull
                    };
                    listItf = new UnconfiguableOI(blankMod, UnconfiguableOI.Reason.TooManyMod);
                }
                List <OptionInterface> temp = new List <OptionInterface>();
                foreach (OptionInterface oi in itfs)
                {
                    if (oi.GetPriority() > priority)
                    {
                        temp.Add(oi);
                    }
                    else
                    {
                        listIgnored.Add(oi.rwMod);
                    }
                }
                itfs = temp;
                priority++;
            }

            // Sorting
            {
                List <OptionInterface>[] sortTemp = new List <OptionInterface> [(int)OptionInterface.Priority.Error + 2];
                for (int p = 0; p < sortTemp.Length; p++)
                {
                    sortTemp[p] = new List <OptionInterface>();
                }
                foreach (OptionInterface oi in itfs)
                {
                    sortTemp[oi.GetPriority() + 1].Add(oi);
                }
                int cmCount = 0;
                for (int p = 0; p < sortTemp.Length; p++)
                {
                    cmCount += sortTemp[p].Count; sortTemp[p].Sort(CompareOIModID);
                }

                itfs = new List <OptionInterface>();
                if (priority > (int)OptionInterface.Priority.NoInterface)
                {
                    OptionScript.loadedInterfaceDict.Add(InternalTranslator.Translate("Mod List"), listItf);
                    listItf.SetIgnoredModList(listIgnored);
                    if (cmCount > 15)
                    {
                        listItf.SetConfiguableModList(sortTemp);
                    }
                    else
                    {
                        listItf.SetConfiguableModList(null);
                    }
                    listItf.Initialize();
                    itfs.Add(listItf);
                }
                for (int p = sortTemp.Length - 1; p >= 0; p--)
                {
                    for (int i = 0; i < sortTemp[p].Count; i++)
                    {
                        itfs.Add(sortTemp[p][i]);
                    }
                }
            }

            // Add Buttons
            modButtons = new SelectOneButton[Math.Min(16, itfs.Count)];
            Dictionary <int, string> dictionary = new Dictionary <int, string>(itfs.Count);
            selectedModIndex = 0;
            for (int i = 0; i < itfs.Count; i++)
            {
                OptionInterface itf = itfs[i];
#pragma warning disable CS0162
                if (OptionMod.testing)
                {
                    Debug.Log(string.Concat("Mod(" + i + ") : " + itf.rwMod.ModID));
                }
#pragma warning restore CS0162
                for (int t = 0; t < itf.Tabs.Length; t++)
                {
                    OptionScript.tabs.Add(string.Concat(i.ToString("D3") + "_" + t.ToString("D2")), itf.Tabs[t]);
                    foreach (UIelement element in itf.Tabs[t].items)
                    {
                        foreach (MenuObject obj in element.subObjects)
                        {
                            this.pages[0].subObjects.Add(obj);
                        }
                        this.pages[0].Container.AddChild(element.myContainer);
                    }
                    itf.Tabs[t].Hide();
                }
                dictionary.Add(i, itf.rwMod.ModID);

                if (i > 15)
                {
                    continue;
                }
                modButtons[i] = new SelectOneButton(this, this.pages[0], itf.rwMod.ModID, "ModSelect", new Vector2(208f, 700f - 30f * i), new Vector2(250f, 24f), modButtons, i);
                this.pages[0].subObjects.Add(modButtons[i]);
            }
            modList    = dictionary;
            scrollMode = false;
            if (itfs.Count > 16)
            {
                scrollMode = true;
                scrollTop  = 1;
                modButtons[1].menuLabel.text  = InternalTranslator.Translate("Scroll Up");
                modButtons[1].signalText      = "ScrollUp";
                modButtons[15].menuLabel.text = InternalTranslator.Translate("Scroll Down");
                modButtons[15].signalText     = "ScrollDown";
                ScrollButtons();
            }

            if (this.modButtons.Length > 1)
            {
                for (int m = 0; m < this.modButtons.Length - 1; m++)
                {
                    this.modButtons[m].nextSelectable[3]     = this.modButtons[m + 1];
                    this.modButtons[m + 1].nextSelectable[1] = this.modButtons[m];
                }
                if (listItf != null)
                {
                    this.modButtons[0].menuLabel.text = listItf.rwMod.ModID;
                }
            }
            this.resetButton.nextSelectable[1] = this.modButtons[this.modButtons.Length - 1];
            this.backButton.nextSelectable[1]  = this.modButtons[this.modButtons.Length - 1];
            this.saveButton.nextSelectable[1]  = this.modButtons[this.modButtons.Length - 1];
            this.modButtons[this.modButtons.Length - 1].nextSelectable[3] = this.saveButton;

            //Load Tab
            selectedTabIndex = 0;
            currentInterface = OptionScript.loadedInterfaceDict[modList[0]];
            currentTab       = OptionScript.tabs[string.Concat(selectedModIndex.ToString("D3") + "_" + selectedTabIndex.ToString("D2"))];

            currentTab.Show();
            if (currentInterface.Configuable())
            {
                saveButton.buttonBehav.greyedOut  = false;
                resetButton.buttonBehav.greyedOut = false;
            }
            else
            {
                saveButton.buttonBehav.greyedOut  = true;
                resetButton.buttonBehav.greyedOut = true;
            }

            tabCtrler = new ConfigTabController(new Vector2(503f, 120f) - UIelement._offset, new Vector2(40f, 600f), menuTab, this);
            menuTab.AddItems(tabCtrler);
            foreach (MenuObject obj in tabCtrler.subObjects)
            {
                this.pages[0].subObjects.Add(obj);
            }

            this.selectedObject = this.backButton;

            OptionScript.configChanged = false;

            mute = false;
        }
Ejemplo n.º 12
0
 public EFConfig(PartialityMod mod) : base(mod)
 {
 }
Ejemplo n.º 13
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.");
        }
Ejemplo n.º 14
0
 public InternalTestOI(PartialityMod mod) : base(mod)
 {
 }
Ejemplo n.º 15
0
 public override void OnEnable()
 {
     base.OnEnable();
     instance = this;
     Hook();
 }
Ejemplo n.º 16
0
 public UnconfiguableOI(PartialityMod mod, Reason type) : base(mod)
 {
     this.reason = type;
 }
Ejemplo n.º 17
0
 public UnconfiguableOI(PartialityMod mod, Exception exception) : base(mod)
 {
     CtorInitError(exception);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// MonoBehavior Update
        /// </summary>
        public void Update()
        {
            if (!init)
            {
                rw = UnityEngine.Object.FindObjectOfType <RainWorld>();
                if (rw == null)
                {
                    return;
                }
                pm = rw.processManager;
                if (pm.upcomingProcess == ProcessManager.ProcessID.MainMenu)
                {
                    try
                    {
                        Initialize();
                    }
                    catch (Exception ex) { Debug.LogError(ex); }
                    init = true;
                }
                ConfigMenu.currentTab = null;
                return;
            }
            if (pm == null)
            {
                rw = UnityEngine.Object.FindObjectOfType <RainWorld>();
                if (rw == null)
                {
                    return;
                }
                pm = rw.processManager;
                return;
            }

            if (pm.currentMainLoop?.ID != ProcessManager.ProcessID.OptionsMenu)
            {
                goto BackgroundUpdate;
            }
            else if (!OptionsMenuPatch.mod)
            {
                return;
            }

            //Option is running
            ConfigMenu.script = this;

            if (ConfigMenu.currentTab != null)
            {
                ConfigMenu.description = "";
                ConfigMenu.menuTab.Update(Time.deltaTime);
                if (soundFill > 0)
                {
                    soundFill--;
                }
                try
                {
                    if (!ConfigMenu.freezeMenu)
                    {
                        ConfigMenu.currentTab.Update(Time.deltaTime);
                    }
                    else
                    {
                        bool h = false;
                        foreach (UIelement element in ConfigMenu.currentTab.items)
                        {
                            if (element.GetType().IsSubclassOf(typeof(UIconfig)))
                            {
                                if ((element as UIconfig).held)
                                {
                                    h = true; element.Update(Time.deltaTime); continue;
                                }
                            }
                        }
                        if (!h)
                        {
                            foreach (UIelement element in ConfigMenu.currentTab.items)
                            {
                                element.Update(Time.deltaTime);
                            }
                        }
                    }
                    ConfigMenu.currentInterface.Update(Time.deltaTime);
                }
                catch (Exception ex)
                { //Update Error Handle!
                    PartialityMod    mod    = ConfigMenu.currentInterface.mod;
                    List <Exception> unload = new List <Exception>();
                    ConfigMenu       menu   = (pm.currentMainLoop as ConfigMenu);
                    foreach (OpTab tab in ConfigMenu.currentInterface.Tabs)
                    {
                        try
                        {
                            tab.Hide();
                            tab.Unload();
                        }
                        catch (Exception ex0) { unload.Add(ex0); }
                    }
                    string fullLog = string.Concat(
                        mod.ModID, " had error in Update(Time.deltaTime)!", Environment.NewLine,
                        ex.ToString());
                    foreach (Exception ex0 in unload)
                    {
                        fullLog += Environment.NewLine + "TabUnloadError: " + ex0.ToString();
                    }

                    UnconfiguableOI newItf = new UnconfiguableOI(mod, new GenericUpdateException(fullLog));
                    loadedInterfaceDict.Remove(mod.ModID);
                    loadedInterfaceDict.Add(mod.ModID, newItf);

                    int index = 0;
                    foreach (KeyValuePair <int, string> item in menu.modList)
                    {
                        if (item.Value == mod.ModID)
                        {
                            index = item.Key; break;
                        }
                    }
                    int i = 0;
                    do
                    {
                        string key = string.Concat(index.ToString("D3") + "_" + i.ToString("D2"));
                        if (tabs.ContainsKey(key))
                        {
                            tabs.Remove(key);
                        }
                        else
                        {
                            break;
                        }
                        i++;
                    } while (i < 100);


                    newItf.Initialize();
                    ConfigMenu.selectedTabIndex = 0;
                    tabs.Add(string.Concat(index.ToString("D3") + "_00"), newItf.Tabs[0]);

                    foreach (UIelement element in newItf.Tabs[0].items)
                    {
                        foreach (MenuObject obj in element.subObjects)
                        {
                            menu.pages[0].subObjects.Add(obj);
                        }
                        menu.pages[0].Container.AddChild(element.myContainer);
                    }
                    newItf.Tabs[0].Show();

                    ConfigMenu.currentInterface = newItf;
                    ConfigMenu.currentTab       = newItf.Tabs[0];

                    (pm.currentMainLoop as ConfigMenu).PlaySound(SoundID.MENU_Error_Ping);
                    (pm.currentMainLoop as ConfigMenu).opened = false;
                    (pm.currentMainLoop as ConfigMenu).OpenMenu();
                }
            }

            return;

BackgroundUpdate:
            //Background running
            if (pm.currentMainLoop?.ID == ProcessManager.ProcessID.IntroRoll)
            {
                return;
            }

            /*
             * foreach (OptionInterface oi in loadedInterfaces)
             * {
             *
             * }
             */
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Runs right before MainMenu opens
        /// </summary>
        public static void Initialize()
        {
            loadedMods           = Partiality.PartialityManager.Instance.modManager.loadedMods;
            loadedModsDictionary = new Dictionary <string, PartialityMod>();
            foreach (PartialityMod mod in loadedMods)
            {
                if (blackList.Contains <string>(mod.ModID))
                {
                    continue;
                }                                                        //No Config for this :P
                else if (mod.ModID.Substring(0, 1) == "_")
                {
                    continue;
                }                                                        //Skip this mod from configuration
                if (!loadedModsDictionary.ContainsKey(mod.ModID))
                {
                    loadedModsDictionary.Add(mod.ModID, mod);
                }
                else
                {
                    Debug.LogError(string.Concat("Duplicate ModID detected! Only one of them is loaded. (duplicated ID: ", mod.ModID, ")"));
                }
            }

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

            //No Mods Installed!
            if (loadedModsDictionary.Count == 0)
            {
                loadedModsDictionary = new Dictionary <string, PartialityMod>(1);
                PartialityMod blankMod = new PartialityMod
                {
                    ModID   = "No Mods Installed",
                    Version = "XXXX",
                    author  = "NULL"
                };
                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;

                if (!Regex.IsMatch(mod.ModID, "^[^\\/?%*:|\"<>/.]+$"))
                {
                    Debug.Log(string.Concat(new object[] {
                        mod.ModID,
                        " does not support CompletelyOptional: Invaild Mod ID!"
                    }));
                    itf = new UnconfiguableOI(mod, new Exception(string.Concat(mod.ModID, " is invaild ModID! Use something that can be used as folder name!")));
                    loadedInterfaces.Add(itf);
                    loadedInterfaceDict.Add(mod.ModID, itf);
                    continue;
                }


                try
                {
                    object obj = mod.GetType().GetMethod("LoadOI").Invoke(mod, new object[] { });
                    //Debug.Log(obj);
                    //itf = (OptionInterface)obj;
                    //itf = obj as OptionInterface;

                    if (obj.GetType().IsSubclassOf(typeof(OptionInterface)))
                    {
                        itf = obj as OptionInterface;
                        //Your code
                        Debug.Log(string.Concat(new object[] {
                            "Loaded OptionInterface from ",
                            mod.ModID,
                            " (type: ",
                            itf.GetType(),
                            ")"
                        }));
                    }
                    else
                    {
                        Debug.Log(string.Concat(new object[] {
                            mod.ModID,
                            " does not support CompletelyOptional: LoadOI returns what is not OptionInterface."
                        }));
                        itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log(string.Concat(new object[] {
                        mod.ModID,
                        " does not support CompletelyOptional: ",
                        ex
                    }));
                    itf = new UnconfiguableOI(mod, UnconfiguableOI.Reason.NoInterface);
                }

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

                if (itf.Tabs == null || itf.Tabs.Length < 1)
                {
                    itf = new UnconfiguableOI(itf.mod, new NoTabException(mod.ModID));
                    //OptionScript.loadedInterfaceDict.Remove(mod.ModID);
                    //OptionScript.loadedInterfaceDict.Add(mod.ModID, itf);
                }

                bool loaded = itf.LoadConfig();
                if (loaded)
                {
                    Debug.Log(string.Concat("CompletelyOptional: ", mod.ModID, " config has been loaded."));
                }
                else
                {
                    Debug.Log(string.Concat("CompletelyOptional: ", mod.ModID, " does not have config.txt; Use default config."));
                }


                loadedInterfaces.Add(itf);
                loadedInterfaceDict.Add(mod.ModID, itf);
                //loadedModsDictionary[item.Key].GetType().GetMember("OI")
            }
        }
Ejemplo n.º 20
0
 public OpKeyBinder(Vector2 pos, Vector2 size, PartialityMod mod, string key, string defaultKey, bool collisionCheck = true, BindController ctrlerNo = BindController.AnyController)
     : this(pos, size, mod.ModID, key, defaultKey, collisionCheck, ctrlerNo)
 {
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Option Interface for Partiality Mod/Patch.
 /// Create public static [YourOIclass] LoadOI() in your PartialityMod.
 /// CompletelyOptional will load your OI after Intro Roll.
 /// </summary>
 /// <param name="mod">Your Partiality mod.</param>
 public OptionInterface(PartialityMod mod)
 {
     this.mod       = mod;
     this.rawConfig = "Unconfiguable";
     instance       = this;
 }
Ejemplo n.º 22
0
 public override void OnLoad()
 {
     base.OnLoad();
     Hook();
     mod = this;
 }
Ejemplo n.º 23
0
 public override void OnEnable()
 {
     base.OnEnable();
     mod = this;
     BloodHooks.Hook();
     BloodMod.bloodTex            = new Texture2D(32, 16, TextureFormat.ARGB32, false);
     BloodMod.bloodTex.anisoLevel = 0;
     BloodMod.bloodTex.filterMode = FilterMode.Point;
     byte[] bloodTex = Convert.FromBase64String(BloodMod.bloodData);
     BloodMod.bloodTex.LoadImage(bloodTex);
     w = BloodMod.bloodTex.width;
     h = BloodMod.bloodTex.height;
     //Default unmodified blood colors for each creature
     defaultColors = new Dictionary <string, Color>()
     {
         { "Slugcat", new Color(0.5f, 0f, 0f) },
         { "PinkLizard", new Color(0.5f, 0f, 0.07f) },
         { "GreenLizard", new Color(0.5f, 0.1f, 0f) },
         { "BlueLizard", new Color(0.5f, 0f, 0.12f) },
         { "YellowLizard", new Color(0.55f, 0.09f, 0f) },
         { "WhiteLizard", new Color(0.5f, 0f, 0f) },
         { "RedLizard", new Color(0.7f, 0f, 0f) },
         { "BlackLizard", new Color(0.4f, 0f, 0f) },
         { "Salamander", new Color(0.6f, 0.09f, 0.09f) },
         { "CyanLizard", new Color(0.5f, 0f, 0.05f) },
         { "Fly", new Color(0.5f, 0.43f, 0.07f) },
         { "Leech", new Color(0.55f, 0f, 0f) },
         { "SeaLeech", new Color(0.55f, 0f, 0f) },
         { "Snail", new Color(0.52f, 0.50f, 0.07f) },
         { "Vulture", new Color(0.5f, 0f, 0f) },
         { "GarbageWorm", new Color(0.5f, 0.43f, 0.07f) },
         { "LanternMouse", new Color(0.5f, 0f, 0f) },
         { "CicadaA", new Color(0.5f, 0.43f, 0.07f) },
         { "CicadaB", new Color(0.5f, 0.43f, 0.07f) },
         { "Spider", new Color(0.5f, 0.43f, 0.07f) },
         { "JetFish", new Color(0.5f, 0f, 0f) },
         { "BigEel", new Color(0.5f, 0f, 0f) },
         { "Deer", new Color(0.5f, 0f, 0f) },
         { "TubeWorm", new Color(0.5f, 0.43f, 0.07f) },
         { "DaddyLongLegs", new Color(0f, 0.2f, 0.8f) },
         { "BrotherLongLegs", new Color(0.55f, 0.5f, 0.07f) },
         { "TentaclePlant", new Color(0.4f, 0.2f, 0f) },
         { "PoleMimic", new Color(0.5f, 0f, 0f) },
         { "MirosBird", new Color(0.5f, 0f, 0f) },
         { "TempleGuard", new Color(0.5f, 0f, 0f) },
         { "Centipede", new Color(0.5f, 0.43f, 0.07f) },
         { "RedCentipede", new Color(0.5f, 0.43f, 0.07f) },
         { "Centiwing", new Color(0.5f, 0.43f, 0.07f) },
         { "SmallCentipede", new Color(0.5f, 0.43f, 0.07f) },
         { "Scavenger", new Color(0.5f, 0f, 0f) },
         { "Overseer", new Color(1f, 0.85f, 0f) },
         { "VultureGrub", new Color(0.5f, 0.43f, 0.07f) },
         { "EggBug", new Color(0.43f, 0.58f, 0.33f) },
         { "BigSpider", new Color(0.5f, 0.13f, 0.07f) },
         { "SpitterSpider", new Color(0.5f, 0.13f, 0.07f) },
         { "SmallNeedleWorm", new Color(0.84f, 0.43f, 0.39f) },
         { "BigNeedleWorm", new Color(0.84f, 0.43f, 0.39f) },
         { "DropBug", new Color(0.5f, 0.43f, 0.07f) },
         { "KingVulture", new Color(0.5f, 0.03f, 0.07f) },
         { "Hazer", new Color(0f, 0.5f, 0.51f) },
     };
     //Vibrant blood color preset
     vibrantColors = new Dictionary <string, Color>()
     {
         { "Slugcat", new Color(0.5f, 0f, 0f) },
         { "PinkLizard", new Color(0.85f, 0f, 0.6f) },
         { "GreenLizard", new Color(0f, 0.8f, 0f) },
         { "BlueLizard", new Color(0f, 0.4f, 0.58f) },
         { "YellowLizard", new Color(1f, 0.58f, 0f) },
         { "WhiteLizard", new Color(0.8f, 0.8f, 0.8f) },
         { "RedLizard", new Color(0.8f, 0f, 0f) },
         { "BlackLizard", new Color(0.4f, 0.4f, 0.4f) },
         { "Salamander", new Color(1f, 0.5f, 0.5f) },
         { "CyanLizard", new Color(0f, 0.86f, 0.93f) },
         { "Fly", new Color(0.5f, 0.43f, 0.07f) },
         { "Leech", new Color(0.6f, 0f, 0f) },
         { "SeaLeech", new Color(0.6f, 0f, 0f) },
         { "Snail", new Color(0.52f, 0.50f, 0.07f) },
         { "Vulture", new Color(0.55f, 0f, 0.1f) },
         { "GarbageWorm", new Color(0.5f, 0.43f, 0.07f) },
         { "LanternMouse", new Color(0.5f, 0f, 0.3f) },
         { "CicadaA", new Color(0.5f, 0.43f, 0.07f) },
         { "CicadaB", new Color(0.4f, 0.53f, 0.07f) },
         { "Spider", new Color(0.5f, 0.43f, 0.07f) },
         { "JetFish", new Color(0.5f, 0f, 0f) },
         { "BigEel", new Color(0.5f, 0f, 0f) },
         { "Deer", new Color(0.5f, 0f, 0f) },
         { "TubeWorm", new Color(0.5f, 0.43f, 0.07f) },
         { "DaddyLongLegs", new Color(0f, 0.2f, 0.8f) },
         { "BrotherLongLegs", new Color(0.454901963f, 0.5254902f, 0.305882365f) },
         { "TentaclePlant", new Color(0.5f, 0.12f, 0f) },
         { "PoleMimic", new Color(0.5f, 0f, 0f) },
         { "MirosBird", new Color(0.5f, 0f, 0f) },
         { "TempleGuard", new Color(0.5f, 0f, 0f) },
         { "Centipede", new Color(0.67f, 0.4f, 0.07f) },
         { "RedCentipede", new Color(0.85f, 0.03f, 0.07f) },
         { "Centiwing", new Color(0.27f, 0.6f, 0f) },
         { "SmallCentipede", new Color(0.5f, 0.43f, 0f) },
         { "Scavenger", new Color(0.5f, 0f, 0f) },
         { "Overseer", new Color(1f, 0.85f, 0f) },
         { "VultureGrub", new Color(0.5f, 0.53f, 0.07f) },
         { "EggBug", new Color(0.33f, 0.85f, 0.33f) },
         { "BigSpider", new Color(0.5f, 0.13f, 0.07f) },
         { "SpitterSpider", new Color(0.5f, 0.13f, 0.07f) },
         { "SmallNeedleWorm", new Color(0.84f, 0.43f, 0.39f) },
         { "BigNeedleWorm", new Color(0.84f, 0.43f, 0.39f) },
         { "DropBug", new Color(0.5f, 0.43f, 0.07f) },
         { "KingVulture", new Color(0.5f, 0f, 0.07f) },
         { "Hazer", new Color(0.211764708f, 0.7921569f, 0.3882353f) },
     };
     //Create a copy of the default colors Dictionary which can be modified by the config screen
     creatureColors = new Dictionary <string, Color>(defaultColors);
     //Create a new blank texture for each creature in the game with the same width and height of the splatter texture
     bloodTextures = new Dictionary <string, Texture2D>();
     foreach (string name in Enum.GetNames(typeof(CreatureTemplate.Type)))
     {
         bloodTextures.Add(name, new Texture2D(w, h));
     }
 }