From b979a6ecceb84249c222273e67c99ad4ccd1692b Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Thu, 2 Sep 2021 20:47:29 +0200 Subject: [PATCH 01/13] Base commit for bepinex transition --- ModMenu/IniFile.cs | 55 -- ModMenu/Libs/0Harmony.dll | 1 + ModMenu/Libs/Assembly-CSharp.dll | 1 + ModMenu/Libs/BepInEx.Harmony.dll | 1 + ModMenu/Libs/BepInEx.dll | 1 + ModMenu/Libs/TextMeshPro.dll | 1 + ModMenu/Libs/UnityEngine.CoreModule.dll | 1 + ModMenu/Libs/UnityEngine.IMGUIModule.dll | 1 + ModMenu/Libs/UnityEngine.TextCoreModule.dll | 1 + .../Libs/UnityEngine.TextRenderingModule.dll | 1 + ModMenu/Libs/UnityEngine.dll | 1 + ModMenu/ModMenu.cs | 696 ++++++++---------- ModMenu/ModMenu.csproj | 183 +---- .../ModMenuIntegration/ModMenuIntegration.cs | 189 ----- ModMenu/ModMenuStyle.cs | 3 +- ModMenu/PluginInfos.cs | 47 ++ ModMenu/Properties/AssemblyInfo.cs | 5 - 17 files changed, 383 insertions(+), 805 deletions(-) delete mode 100644 ModMenu/IniFile.cs create mode 120000 ModMenu/Libs/0Harmony.dll create mode 120000 ModMenu/Libs/Assembly-CSharp.dll create mode 120000 ModMenu/Libs/BepInEx.Harmony.dll create mode 120000 ModMenu/Libs/BepInEx.dll create mode 120000 ModMenu/Libs/TextMeshPro.dll create mode 120000 ModMenu/Libs/UnityEngine.CoreModule.dll create mode 120000 ModMenu/Libs/UnityEngine.IMGUIModule.dll create mode 120000 ModMenu/Libs/UnityEngine.TextCoreModule.dll create mode 120000 ModMenu/Libs/UnityEngine.TextRenderingModule.dll create mode 120000 ModMenu/Libs/UnityEngine.dll mode change 100644 => 100755 ModMenu/ModMenu.cs delete mode 100644 ModMenu/ModMenuIntegration/ModMenuIntegration.cs mode change 100644 => 100755 ModMenu/ModMenuStyle.cs create mode 100755 ModMenu/PluginInfos.cs mode change 100644 => 100755 ModMenu/Properties/AssemblyInfo.cs diff --git a/ModMenu/IniFile.cs b/ModMenu/IniFile.cs deleted file mode 100644 index 4f44bdf..0000000 --- a/ModMenu/IniFile.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace LLModMenu -{ - class IniFile // revision 11 - { - string Path; - string EXE = Assembly.GetExecutingAssembly().GetName().Name; - - [DllImport("kernel32", CharSet = CharSet.Unicode)] - static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath); - - [DllImport("kernel32", CharSet = CharSet.Unicode)] - static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath); - - public IniFile(string IniPath = null) - { - Path = new FileInfo(IniPath ?? EXE + ".ini").FullName.ToString(); - } - - public string Read(string Key, string Section = null) - { - var RetVal = new StringBuilder(255); - GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path); - return RetVal.ToString(); - } - - public void Write(string Key, string Value, string Section = null) - { - WritePrivateProfileString(Section ?? EXE, Key, Value, Path); - } - - public void DeleteKey(string Key, string Section = null) - { - Write(Key, null, Section ?? EXE); - } - - public void DeleteSection(string Section = null) - { - Write(null, null, Section ?? EXE); - } - - public bool KeyExists(string Key, string Section = null) - { - return Read(Key, Section).Length > 0; - } - } -} diff --git a/ModMenu/Libs/0Harmony.dll b/ModMenu/Libs/0Harmony.dll new file mode 120000 index 0000000..689e200 --- /dev/null +++ b/ModMenu/Libs/0Harmony.dll @@ -0,0 +1 @@ +../../../../../BepInEx/BepInEx/core/0Harmony.dll \ No newline at end of file diff --git a/ModMenu/Libs/Assembly-CSharp.dll b/ModMenu/Libs/Assembly-CSharp.dll new file mode 120000 index 0000000..27d2849 --- /dev/null +++ b/ModMenu/Libs/Assembly-CSharp.dll @@ -0,0 +1 @@ +../../../../llb_dlls/Assembly-CSharp.dll \ No newline at end of file diff --git a/ModMenu/Libs/BepInEx.Harmony.dll b/ModMenu/Libs/BepInEx.Harmony.dll new file mode 120000 index 0000000..0cfd90d --- /dev/null +++ b/ModMenu/Libs/BepInEx.Harmony.dll @@ -0,0 +1 @@ +../../../../../BepInEx/BepInEx/core/BepInEx.Harmony.dll \ No newline at end of file diff --git a/ModMenu/Libs/BepInEx.dll b/ModMenu/Libs/BepInEx.dll new file mode 120000 index 0000000..0aefcee --- /dev/null +++ b/ModMenu/Libs/BepInEx.dll @@ -0,0 +1 @@ +../../../../../BepInEx/BepInEx/core/BepInEx.dll \ No newline at end of file diff --git a/ModMenu/Libs/TextMeshPro.dll b/ModMenu/Libs/TextMeshPro.dll new file mode 120000 index 0000000..2e1451a --- /dev/null +++ b/ModMenu/Libs/TextMeshPro.dll @@ -0,0 +1 @@ +../../../../llb_dlls/TextMeshPro.dll \ No newline at end of file diff --git a/ModMenu/Libs/UnityEngine.CoreModule.dll b/ModMenu/Libs/UnityEngine.CoreModule.dll new file mode 120000 index 0000000..e4b7cbe --- /dev/null +++ b/ModMenu/Libs/UnityEngine.CoreModule.dll @@ -0,0 +1 @@ +../../../../llb_dlls/UnityEngine.CoreModule.dll \ No newline at end of file diff --git a/ModMenu/Libs/UnityEngine.IMGUIModule.dll b/ModMenu/Libs/UnityEngine.IMGUIModule.dll new file mode 120000 index 0000000..279cd98 --- /dev/null +++ b/ModMenu/Libs/UnityEngine.IMGUIModule.dll @@ -0,0 +1 @@ +../../../../llb_dlls/UnityEngine.IMGUIModule.dll \ No newline at end of file diff --git a/ModMenu/Libs/UnityEngine.TextCoreModule.dll b/ModMenu/Libs/UnityEngine.TextCoreModule.dll new file mode 120000 index 0000000..a78ec8e --- /dev/null +++ b/ModMenu/Libs/UnityEngine.TextCoreModule.dll @@ -0,0 +1 @@ +../../../../llb_dlls/UnityEngine.TextCoreModule.dll \ No newline at end of file diff --git a/ModMenu/Libs/UnityEngine.TextRenderingModule.dll b/ModMenu/Libs/UnityEngine.TextRenderingModule.dll new file mode 120000 index 0000000..e35bcd2 --- /dev/null +++ b/ModMenu/Libs/UnityEngine.TextRenderingModule.dll @@ -0,0 +1 @@ +../../../../llb_dlls/UnityEngine.TextRenderingModule.dll \ No newline at end of file diff --git a/ModMenu/Libs/UnityEngine.dll b/ModMenu/Libs/UnityEngine.dll new file mode 120000 index 0000000..4e87fd9 --- /dev/null +++ b/ModMenu/Libs/UnityEngine.dll @@ -0,0 +1 @@ +../../../../llb_dlls/UnityEngine.dll \ No newline at end of file diff --git a/ModMenu/ModMenu.cs b/ModMenu/ModMenu.cs old mode 100644 new mode 100755 index 682df02..e7def2c --- a/ModMenu/ModMenu.cs +++ b/ModMenu/ModMenu.cs @@ -1,117 +1,107 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; using UnityEngine; using LLScreen; using LLGUI; -using LLHandlers; -using System.IO; -using System.Text.RegularExpressions; -using System.Linq; +using HarmonyLib; +using BepInEx; +using BepInEx.Configuration; -namespace LLModMenu +namespace ModMenu { - public class ModMenu : MonoBehaviour + [BepInPlugin(PluginInfos.PLUGIN_ID, PluginInfos.PLUGIN_NAME, PluginInfos.PLUGIN_VERSION)] + [BepInProcess("LLBlaze.exe")] + public class ModMenu : BaseUnityPlugin { - private static ModMenu instance = null; - public static ModMenu Instance { get { return instance; } } - public static void Initialize() { GameObject gameObject = new GameObject("ModMenu"); ModMenu modLoader = gameObject.AddComponent(); DontDestroyOnLoad(gameObject); instance = modLoader; ModMenuStyle.InitStyle(); } + public static ModMenu Instance { get; private set; } = null; + public static List registeredMods = new List(); + public void Awake() + { + Instance = this; + ModMenuStyle.InitStyle(); + } + + private readonly Array keyCodes = System.Enum.GetValues(typeof(KeyCode)); - public LLButton button = null; - public List mods = new List(); + private ScreenMenu mainmenu = null; + private ScreenBase submenu = null; + private AccessTools.FieldRef _currentScreens = AccessTools.FieldRefAccess(typeof(LLScreen.UIScreen), "currentScreens"); + private LLButton modSettingsButton = null; public List modButtons = new List(); - public bool inModOptions = false; - public bool inModSubOptions = false; - public ScreenMenu mainmenu = null; - public ScreenBase submenu = null; - public Dictionary configKeys = new Dictionary(); - public Dictionary configBools = new Dictionary(); - public Dictionary configInts = new Dictionary(); - public List intList = new List(); - public Dictionary configHeaders = new Dictionary(); - public Dictionary configSliders = new Dictionary(); - public List sliderList = new List(); - public Dictionary configText = new Dictionary(); - public List optionsQueue = new List(); - - public string currentOpenMod = ""; - public string newKey = ""; - public Vector2 keybindScrollpos = new Vector2(0,0); + + public Vector2 keybindScrollpos = new Vector2(0, 0); public Vector2 optionsScrollpos = new Vector2(0, 0); public Vector2 optionsTextpos = new Vector2(0, 0); - public ModMenuIntegration MMI = null; - - public int switchInputModeTimer = 0; + private BepInEx.PluginInfo currentOpenMod; + private BepInEx.PluginInfo previousOpenMod; - private string modVersion = "v1.1.0"; - private string iniLocation = Path.GetDirectoryName(Application.dataPath) + "\\ModSettings"; + private bool sliderChange = false; + private ConfigDefinition definitionToRebind = null; + private bool rebindingKey = false; + private int switchInputModeTimer = 0; + private bool inModOptions = false; + public static bool InModOptions => Instance.inModOptions; + private bool inModSubOptions = false; + public static void RegisterMod(BepInEx.PluginInfo pluginInfo) + { + registeredMods.Add(pluginInfo); + } private void Update() { - if (!Directory.Exists(iniLocation)) Directory.CreateDirectory(iniLocation); - if (mainmenu == null) { mainmenu = FindObjectOfType(); } - if (submenu == null) { submenu = UIScreen.currentScreens[1]; } - else + if (this.sliderChange && Input.GetKeyUp(KeyCode.Mouse0)) { + this.currentOpenMod.Instance.Config.Save(); + this.currentOpenMod.Instance.Config.SaveOnConfigSet = true; + this.sliderChange = false; + } - List buttons = new List(); - if (submenu.screenType == ScreenType.MENU_OPTIONS && button == null) + if (this.rebindingKey && Input.anyKeyDown) + { + foreach (KeyCode keyCode in keyCodes) { - ScreenMenuOptions SMO = FindObjectOfType(); - buttons.Add(SMO.btGame); - buttons.Add(SMO.btInput); - buttons.Add(SMO.btAudio); - buttons.Add(SMO.btVideo); - buttons.Add(SMO.btCredits); - - button = Instantiate(buttons[4], buttons[4].transform, true); - button.name = "btMods"; - button.SetText("mod settings"); - button.onClick = new LLClickable.ControlDelegate(this.ModSettingsClick); - - buttons.Add(button); - - for(var i = 0; i < buttons.Count(); i++) + if (Input.GetKey(keyCode)) { - Vector3 scale = buttons[i].transform.localScale; - - int modx = 2560; - int mody = 1440; - - if (buttons[i] == button) - { - buttons[i].transform.localPosition = new Vector3(buttons[i].transform.localPosition.x - ((modx / 100) * 1), buttons[i].transform.localPosition.y - ((mody / 100) * 9.5f)); - } - else if (buttons[i] != SMO.btGame) - { - buttons[i].transform.localPosition = new Vector3(SMO.btGame.transform.localPosition.x - (((modx / 100) * 0.55f) * i), SMO.btGame.transform.localPosition.y - (((mody / 100) * 5.3f) * i)); - buttons[i].transform.localScale = new Vector3(scale.x * 0.85f, scale.y * 0.85f, scale.z); - } - else - { - buttons[i].transform.localPosition = new Vector3(-((modx / 100)*8.375f), ((mody / 100) * 12.625f)); - buttons[i].transform.localScale = new Vector3(scale.x * 0.85f, scale.y * 0.85f, scale.z); - } + ConfigFile modConfig = this.currentOpenMod.Instance.Config; + modConfig[this.definitionToRebind].BoxedValue = keyCode; + modConfig.Save(); + this.rebindingKey = false; } } } + if (mainmenu == null) + mainmenu = FindObjectOfType(); + + if (submenu == null) + { + submenu = _currentScreens.Invoke()[1]; + } + else + { + if (submenu.screenType == ScreenType.MENU_OPTIONS && modSettingsButton == null) + { + modSettingsButton = this.InitModSettingsButton(); + } + } if (switchInputModeTimer != 30) switchInputModeTimer++; - if (inModSubOptions) //If we are within the options of a spiesific mod. + if (inModSubOptions && this.currentOpenMod != this.previousOpenMod) //If we are within the options of a spiesific mod. { - Component comp = GameObject.Find(currentOpenMod).GetComponent(currentOpenMod); //Get the script for that mod. - comp.SendMessage("ReadIni"); //Tell it to run the "ReadIni" method. + this.previousOpenMod = this.currentOpenMod; } - if (Controller.mouseKeyboard.GetButton(InputAction.ESC)) + if (inModOptions) { - if (inModOptions) + if (LLHandlers.Controller.mouseKeyboard.GetButton(LLHandlers.InputAction.ESC)) { + this.previousOpenMod = null; UIScreen.Open(ScreenType.MENU_OPTIONS, 1, ScreenTransition.MOVE_RIGHT); inModOptions = false; inModSubOptions = false; @@ -119,34 +109,44 @@ private void Update() } } - private void ModSettingsClick(int playerNr) + #region Handles + public void HandleModSettingsClick(int playerNr) { ScreenBase screen = UIScreen.Open(ScreenType.OPTIONS, 1); inModOptions = true; - GameObject.Find("btQuit").GetComponent().onClick = new LLClickable.ControlDelegate(QuitClick); + GameObject.Find("btQuit").GetComponent().onClick = new LLClickable.ControlDelegate(this.HandleQuitClick); mainmenu.lbTitle.text = "MOD SETTINGS"; var vcount = 0; var hcount = 0; - - foreach (string mod in mods) + foreach (BepInEx.PluginInfo plugin in registeredMods) { - var obj = Instantiate(button, screen.transform); - obj.SetText(mod, 50); + var obj = Instantiate(modSettingsButton, screen.transform); + obj.SetText(plugin.Metadata.Name, 50); obj.transform.localScale = new Vector3(0.4f, 0.3f); obj.transform.position = new Vector3(-1.5f + (0.75f * hcount), 0.80f - (0.125f * vcount)); - obj.onClick = delegate (int pNr) { ModSubSettingsClick(mod); }; + obj.onClick = delegate (int pNr) { this.HandleModSubSettingsClick(plugin); }; modButtons.Add(obj); if (vcount < 12) { vcount++; } else { hcount++; vcount = 0; } } } - private void QuitClick(int playerNr) + private void HandleModSubSettingsClick(BepInEx.PluginInfo plugin) { + inModSubOptions = true; + currentOpenMod = plugin; + ScreenBase screen = UIScreen.Open(ScreenType.OPTIONS, 1); + mainmenu.lbTitle.text = plugin.Metadata.Name.ToUpper() + " SETTINGS"; + } + + private void HandleQuitClick(int playerNr) + { + this.previousOpenMod = null; if (inModOptions == true) { UIScreen.Open(ScreenType.MENU_OPTIONS, 1); - } else + } + else { if (submenu != null) { @@ -160,120 +160,127 @@ private void QuitClick(int playerNr) } } } - if (UIScreen.currentScreens[1].screenType == ScreenType.MENU_OPTIONS) + if (_currentScreens.Invoke()[1].screenType == ScreenType.MENU_OPTIONS) { mainmenu.lbTitle.text = "OPTIONS"; inModOptions = false; inModSubOptions = false; - AudioHandler.PlayMenuSfx(Sfx.MENU_BACK); - AudioHandler.PlayMenuSfx(Sfx.MENU_CONFIRM); + LLHandlers.AudioHandler.PlayMenuSfx(LLHandlers.Sfx.MENU_BACK); + LLHandlers.AudioHandler.PlayMenuSfx(LLHandlers.Sfx.MENU_CONFIRM); } } + #endregion + + public LLButton InitModSettingsButton() + { + LLButton _modSettingsButton = null; + List buttons = new List(); + ScreenMenuOptions SMO = FindObjectOfType(); + buttons.Add(SMO.btGame); + buttons.Add(SMO.btInput); + buttons.Add(SMO.btAudio); + buttons.Add(SMO.btVideo); + buttons.Add(SMO.btCredits); + + _modSettingsButton = Instantiate(buttons[4], buttons[4].transform, true); + _modSettingsButton.name = "btMods"; + _modSettingsButton.SetText("mod settings"); + _modSettingsButton.onClick = new LLClickable.ControlDelegate(this.HandleModSettingsClick); + + buttons.Add(_modSettingsButton); + + for (var i = 0; i < buttons.Count(); i++) + { + if (buttons[i] == null) continue; + Vector3 scale = buttons[i].transform.localScale; + + int modx = 2560; + int mody = 1440; + + if (buttons[i] == _modSettingsButton) + { + buttons[i].transform.localPosition = new Vector3(buttons[i].transform.localPosition.x - ((modx / 100) * 1), buttons[i].transform.localPosition.y - ((mody / 100) * 9.5f)); + } + else if (buttons[i] != SMO.btGame) + { + buttons[i].transform.localPosition = new Vector3(SMO.btGame.transform.localPosition.x - (((modx / 100) * 0.55f) * i), SMO.btGame.transform.localPosition.y - (((mody / 100) * 5.3f) * i)); + buttons[i].transform.localScale = new Vector3(scale.x * 0.85f, scale.y * 0.85f, scale.z); + } + else + { + buttons[i].transform.localPosition = new Vector3(-((modx / 100) * 8.375f), ((mody / 100) * 12.625f)); + buttons[i].transform.localScale = new Vector3(scale.x * 0.85f, scale.y * 0.85f, scale.z); + } + } + + return _modSettingsButton; + } #region GUIStuff + + private GUI.WindowFunction keybindWindowFunction = null; + private GUI.WindowFunction optionsWindowFunction = null; + private GUI.WindowFunction textWindowFunction = null; private void OnGUI() { + if (keybindWindowFunction == null) + keybindWindowFunction = new GUI.WindowFunction(OpenKeybindsWindow); + if (optionsWindowFunction == null) + optionsWindowFunction = new GUI.WindowFunction(OpenOptionsWindow); + if (textWindowFunction == null) + textWindowFunction = new GUI.WindowFunction(OpenTextWindow); + var x1 = Screen.width / 6; var y1 = Screen.height / 10; - var x2 = Screen.width - (Screen.width/6)*2; + var x2 = Screen.width - (Screen.width / 6) * 2; var y2 = Screen.height - (Screen.height / 6); - if (inModSubOptions) { - GUIContent guic = new GUIContent(" ModMenu " + modVersion + " "); + GUIContent guic = new GUIContent(" ModMenu " + this.Info.Metadata.Version + " "); Vector2 calc = GUI.skin.box.CalcSize(guic); - GUI.Box(new Rect(10, 10, calc.x, calc.y), "ModMenu " + modVersion, ModMenuStyle.versionBox); - GUI.Window(0, new Rect(x1, y1, x2, y2 / 3), new GUI.WindowFunction(OpenKeybindsWindow), "Keybindings", ModMenuStyle.windStyle); - GUI.Window(1, new Rect(x1, y1 + y2 / 3 + 10, x2, y2 / 3), new GUI.WindowFunction(OpenOptionsWindow), "Options", ModMenuStyle.windStyle); - GUI.Window(2, new Rect(x1, y1 + ((y2 / 3 + 10)*2), x2, y2 / 5), new GUI.WindowFunction(OpenTextWindow), "Mod Information", ModMenuStyle.windStyle); - GUI.skin.window = null; - } - GUI.skin.label.fontSize = 15; - } + GUI.Box(new Rect(10, 10, calc.x + 20, calc.y), "ModMenu " + this.Info.Metadata.Version, ModMenuStyle.versionBox); - private void ModSubSettingsClick(string modName) - { - inModSubOptions = true; - currentOpenMod = modName; - ScreenBase screen = UIScreen.Open(ScreenType.OPTIONS, 1); - mainmenu.lbTitle.text = modName.ToUpper() + " SETTINGS"; - configKeys.Clear(); - configBools.Clear(); - configInts.Clear(); - intList.Clear(); - configSliders.Clear(); - sliderList.Clear(); - configHeaders.Clear(); - configText.Clear(); - - string[] lines = File.ReadAllLines(iniLocation + @"\" + modName + ".ini"); - foreach (string line in lines) - { - if (line.StartsWith("(key)")) - { - string[] split = line.Split('='); - configKeys.Add(split[0], split[1]); - } - else if (line.StartsWith("(bool)")) - { - string[] split = line.Split('='); - configBools.Add(split[0], split[1]); - } - else if (line.StartsWith("(int)")) - { - string[] split = line.Split('='); - configInts.Add(split[0], split[1]); - intList.Add(split[1]); - } - else if (line.StartsWith("(slider)")) - { - string[] split = line.Split('='); - configSliders.Add(split[0], split[1]); + GUI.Window(0, new Rect(x1, y1, x2, y2 / 3), keybindWindowFunction, "Keybindings", ModMenuStyle.windStyle); + GUI.Window(1, new Rect(x1, y1 + y2 / 3 + 10, x2, y2 / 3), optionsWindowFunction, "Options", ModMenuStyle.windStyle); + GUI.Window(2, new Rect(x1, y1 + ((y2 / 3 + 10) * 2), x2, y2 / 5), textWindowFunction, "Mod Information", ModMenuStyle.windStyle); - string[] valMinMax = split[1].Split('|'); - sliderList.Add(float.Parse(valMinMax[0])); - } - else if (line.StartsWith("(header)")) - { - string[] split = line.Split('='); - configHeaders.Add(split[0], split[1]); - } - else if (line.StartsWith("(text)")) - { - string[] split = line.Split('='); - configText.Add(split[0], split[1]); - } + GUI.skin.window = null; } + GUI.skin.label.fontSize = 15; } - - private void OpenKeybindsWindow(int wId) { GUILayout.Space(30); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); keybindScrollpos = GUILayout.BeginScrollView(keybindScrollpos, false, true); - var keyList = new List(); - if (configKeys.Count > 0) + + ConfigFile modConfig = currentOpenMod.Instance.Config; + + foreach (ConfigDefinition setting in modConfig.Keys.Where((ConfigDefinition setting) => modConfig[setting].SettingType == typeof(KeyCode))) { - foreach (KeyValuePair keyval in configKeys) keyList.Add(keyval.Key); + string formatted = UppercaseFirst(Regex.Replace(setting.Key, "([a-z])([A-Z])", "$1 $2")); + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.Label(formatted + ":", ModMenuStyle.labStyle); + GUILayout.Space(10); + + string displayText; + + if (this.rebindingKey && setting == this.definitionToRebind) + displayText = "WAITING FOR KEY"; + else + displayText = currentOpenMod.Instance.Config[setting].BoxedValue.ToString(); - foreach (string key in keyList) + if (GUILayout.Button("[" + displayText + "]", ModMenuStyle.button, GUILayout.MinWidth(100))) { - string format = key.Remove(0, 5); - string formatted = UppercaseFirst(Regex.Replace(format, "([a-z])([A-Z])", "$1 $2")); - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - GUILayout.Label(formatted + ":", ModMenuStyle.labStyle); - GUILayout.Space(10); - if (GUILayout.Button("[" + configKeys[key] + "]", ModMenuStyle.button, GUILayout.MinWidth(100))) - { - StartCoroutine(BindKey(key)); - } - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); + this.rebindingKey = true; + this.definitionToRebind = setting; } + + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); @@ -286,131 +293,51 @@ private void OpenOptionsWindow(int wId) GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); optionsScrollpos = GUILayout.BeginScrollView(optionsScrollpos, false, true); + ConfigFile modConfig = currentOpenMod.Instance.Config; - optionsQueue = GetOptionsQueue(currentOpenMod); - int bools = 0; - int ints = 0; - int sliders = 0; - int headers = 0; - - if (optionsQueue != null) + foreach (ConfigDefinition setting in modConfig.Keys) { - foreach (string option in optionsQueue) + Type settingType = modConfig[setting].SettingType; + if (settingType == typeof(bool)) { - if (option == "(bool)") + MakeBoolSettingGUI(modConfig, setting); + } + else if (settingType == typeof(int)) + { + if (modConfig[setting].Description?.AcceptableValues is AcceptableValueRange + // NIY || modConfig[setting].Description.AcceptableValues is AcceptableValueRange + ) { - var key = configBools.Keys.ElementAt(bools); - var val = configBools.Values.ElementAt(bools); - string format = key.Remove(0, 6); - string formatted = UppercaseFirst(Regex.Replace(format, "([a-z])([A-Z])", "$1 $2")); - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - GUILayout.Label(formatted + ":", ModMenuStyle.labStyle); - GUILayout.Space(10); - var str = ""; - if (val == "true") str = "Enabled"; - else str = "Disabled"; - - if (GUILayout.Button(str, ModMenuStyle.button, GUILayout.MinWidth(100))) - { - IniFile modIni = new IniFile(iniLocation + @"\" + currentOpenMod + ".ini"); - if (val == "true") - { - modIni.Write(key, "false"); - configBools[key] = "false"; - } - else - { - modIni.Write(key, "true"); - configBools[key] = "true"; - } - } - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - bools++; + MakeSliderSettingGUI(modConfig, setting); } - else if (option == "(int)") + else { - var key = configInts.Keys.ElementAt(ints); - string format = key.Remove(0, 5); - string formatted = UppercaseFirst(Regex.Replace(format, "([a-z])([A-Z])", "$1 $2")); - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - - GUILayout.Label(formatted + ": ", ModMenuStyle.labStyle); - GUILayout.Box(configInts[key], ModMenuStyle.box); - GUILayout.Space(10); - if (GUILayout.Button(" - ", ModMenuStyle.button)) - { - IniFile modIni = new IniFile(iniLocation + @"\" + currentOpenMod + ".ini"); - var j = Convert.ToInt32(configInts[key]); - j--; - modIni.Write(key, j.ToString()); - configInts[key] = j.ToString(); - } - - if (GUILayout.Button(" + ", ModMenuStyle.button)) - { - IniFile modIni = new IniFile(iniLocation + @"\" + currentOpenMod + ".ini"); - var j = Convert.ToInt32(configInts[key]); - j++; - modIni.Write(key, j.ToString()); - configInts[key] = j.ToString(); - } - - GUILayout.Space(30); - - intList[ints] = GUILayout.TextField(intList[ints].ToString(), 10, ModMenuStyle._textFieldStyle, GUILayout.MinWidth(32)); - - if (GUILayout.Button("Set Value From Textbox", ModMenuStyle.button)) - { - IniFile modIni = new IniFile(iniLocation + @"\" + currentOpenMod + ".ini"); - if (Int32.TryParse(intList[ints], out int n)) - { - modIni.Write(key, intList[ints]); - configInts[key] = intList[ints]; - } - } - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - ints++; + MakeNumericSettingGUI(modConfig, setting); } - else if (option == "(slider)") - { - IniFile modIni = new IniFile(iniLocation + @"\" + currentOpenMod + ".ini"); - - var key = configSliders.Keys.ElementAt(sliders); - string format = key.Remove(0, 8); - string formatted = UppercaseFirst(Regex.Replace(format, "([a-z])([A-Z])", "$1 $2")); - - string[] valMinMax = configSliders[key].Split('|'); - - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - - GUILayout.Label(formatted + ": ", ModMenuStyle.labStyle); - sliderList[sliders] = GUILayout.HorizontalSlider(sliderList[sliders], float.Parse(valMinMax[1]), float.Parse(valMinMax[2]), ModMenuStyle._sliderBackgroundStyle, ModMenuStyle._sliderThumbStyle, GUILayout.Width(300)); - GUILayout.Box(System.Math.Round(Double.Parse(sliderList[sliders].ToString())).ToString(), ModMenuStyle.box); - - modIni.Write(key, System.Math.Round(Double.Parse(sliderList[sliders].ToString())).ToString() + "|" + valMinMax[1] + "|" + valMinMax[2]); + } + else if (settingType == typeof(string)) + { + string settingValue = (string)modConfig[setting].BoxedValue; + string settingDesc = modConfig[setting].Description.Description; - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - sliders++; - } - else if (option == "(header)") + if (settingDesc.ToLower() == "modmenu_header") { - var key = configHeaders.Keys.ElementAt(headers); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); - GUILayout.Box(configHeaders[key], ModMenuStyle.headerBox); + GUILayout.Box(settingValue, ModMenuStyle.headerBox); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); - headers++; } - else if (option == "(gap)") + else if (settingDesc.ToLower() == "modmenu_gap") { - GUILayout.Space(20); + if (Int32.TryParse(settingValue, out int n)) + { + GUILayout.Space(n); + } + else + { + GUILayout.Space(20); + } } } } @@ -420,143 +347,129 @@ private void OpenOptionsWindow(int wId) GUILayout.EndHorizontal(); } - private void OpenTextWindow(int wId) + private void MakeBoolSettingGUI(ConfigFile modConfig, ConfigDefinition setting) { - GUILayout.Space(30); - GUILayout.BeginVertical(); - optionsTextpos = GUILayout.BeginScrollView(optionsTextpos, false, true); - if (configText.Count > 0) + bool val = (bool)modConfig[setting].BoxedValue; + string formatted = UppercaseFirst(Regex.Replace(setting.Key, "([a-z])([A-Z])", "$1 $2")); + + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.Label(formatted + ":", ModMenuStyle.labStyle); + GUILayout.Space(10); + + var str = ""; + if (val) str = "Enabled"; + else str = "Disabled"; + + bool isPressed = GUILayout.Button(str, ModMenuStyle.button, GUILayout.MinWidth(100)); + if (isPressed) { - foreach (KeyValuePair keyval in configText) - { - GUILayout.BeginHorizontal(); - GUILayout.Label(keyval.Value, ModMenuStyle.readStyle); - GUILayout.EndHorizontal(); - } + modConfig[setting].BoxedValue = !val; + modConfig.Save(); } - - GUILayout.EndScrollView(); - GUILayout.EndVertical(); + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); } - public void WriteIni(string modName, List writeQueue, Dictionary keyBinds, Dictionary bools, Dictionary ints, Dictionary sliders, Dictionary headers, Dictionary gaps, Dictionary text) + private void MakeNumericSettingGUI(ConfigFile modConfig, ConfigDefinition setting) { + int value = (int)modConfig[setting].BoxedValue; - if (File.Exists(iniLocation + @"\" + modName + ".ini")) - { - string[] lines = File.ReadAllLines(iniLocation + @"\" + modName + ".ini"); - foreach (string key in writeQueue) - { - try - { - if (!lines[writeQueue.IndexOf(key) + 1].Contains(key)) - { - Debug.Log("ModMenu: " + iniLocation + @"\" + modName + ".ini has been remade because it did not match what was expected"); - File.Delete(iniLocation + @"\" + modName + ".ini"); - break; - }; - } catch - { - Debug.Log("ModMenu: " + iniLocation + @"\" + modName + ".ini has been remade because it did not match what was expected"); - File.Delete(iniLocation + @"\" + modName + ".ini"); - break; - } - } - } - IniFile modIni = new IniFile(iniLocation + @"\" + modName + ".ini"); + string formatted = UppercaseFirst(Regex.Replace(setting.Key, "([a-z])([A-Z])", "$1 $2")); + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.Label(formatted + ": ", ModMenuStyle.labStyle); + GUILayout.Box(value.ToString(), ModMenuStyle.box); + GUILayout.Space(10); + + bool isMinusPressed = GUILayout.Button(" - ", ModMenuStyle.button); + bool isPlusPressed = GUILayout.Button(" + ", ModMenuStyle.button); + + + GUILayout.Space(30); + string intValue = GUILayout.TextField(value.ToString(), 10, ModMenuStyle._textFieldStyle, GUILayout.MinWidth(32)); - if (writeQueue.Count() > 0) + bool isFromTextPressed = GUILayout.Button("Set Value From Textbox", ModMenuStyle.button); + + if (isPlusPressed) + { + modConfig[setting].BoxedValue = value + 1; + modConfig.Save(); + } + else if (isMinusPressed) { - foreach (string key in writeQueue) + modConfig[setting].BoxedValue = value - 1; + modConfig.Save(); + } + else if (Int32.TryParse(intValue, out int n)) + { + if ((int)modConfig[setting].BoxedValue != n) { - if (key.StartsWith("(bool)")) - { - if (!modIni.KeyExists(key)) modIni.Write(key, bools[key]); - } - else if (key.StartsWith("(int)")) - { - if (!modIni.KeyExists(key)) modIni.Write(key, ints[key]); - } - else if (key.StartsWith("(slider)")) - { - if (!modIni.KeyExists(key)) modIni.Write(key, sliders[key]); - } - else if (key.StartsWith("(header)")) - { - if (!modIni.KeyExists(key)) modIni.Write(key, headers[key]); - } - else if (key.StartsWith("(gap)")) - { - if (!modIni.KeyExists(key)) modIni.Write(key, gaps[key]); - } - else if (key.StartsWith("(key)")) - { - if (!modIni.KeyExists(key)) modIni.Write(key, keyBinds[key]); - } - else if (key.StartsWith("(text)")) - { - if (!modIni.KeyExists(key)) modIni.Write(key, text[key]); - } + modConfig[setting].BoxedValue = n; + modConfig.Save(); + } + if (isFromTextPressed) + { + modConfig[setting].BoxedValue = n; + modConfig.Save(); } } + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); } - public List GetOptionsQueue(string modName) + private void MakeSliderSettingGUI(ConfigFile modConfig, ConfigDefinition setting) { - List ret = new List(); - string[] lines = File.ReadAllLines(iniLocation + @"\" + modName + ".ini"); - if (lines.Length > 0) + int storedSliderValue = (int)modConfig[setting].BoxedValue; + AcceptableValueRange range = modConfig[setting].Description.AcceptableValues as AcceptableValueRange; + string formatted = UppercaseFirst(Regex.Replace(setting.Key, "([a-z])([A-Z])", "$1 $2")); + + float sliderValue = storedSliderValue; + + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.Label(formatted + ": ", ModMenuStyle.labStyle); + sliderValue = GUILayout.HorizontalSlider(sliderValue, (float)range.MinValue, (float)range.MaxValue, ModMenuStyle._sliderBackgroundStyle, ModMenuStyle._sliderThumbStyle, GUILayout.Width(300)); + GUILayout.Box(System.Math.Round(Double.Parse(sliderValue.ToString())).ToString(), ModMenuStyle.box); + + int newSliderValue = (int)System.Math.Round(sliderValue); + if (newSliderValue != storedSliderValue) { - foreach (string line in lines) - { - if (line.StartsWith("(bool)")) - { - ret.Add("(bool)"); - } - else if (line.StartsWith("(int)")) - { - ret.Add("(int)"); - } - else if (line.StartsWith("(slider)")) - { - ret.Add("(slider)"); - } - else if (line.StartsWith("(header)")) - { - ret.Add("(header)"); - } - else if (line.StartsWith("(gap)")) - { - ret.Add("(gap)"); - } - } + modConfig.SaveOnConfigSet = false; + this.sliderChange = true; + modConfig[setting].BoxedValue = newSliderValue; } - return ret; + + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); } - IEnumerator BindKey(string key) + private void OpenTextWindow(int wId) { - bool pressed = false; - configKeys[key] = "WAITING FOR KEY"; - IniFile modIni = new IniFile(iniLocation + @"\" + currentOpenMod + ".ini"); - while (!pressed) + GUILayout.Space(30); + GUILayout.BeginVertical(); + optionsTextpos = GUILayout.BeginScrollView(optionsTextpos, false, true); + + ConfigFile modConfig = currentOpenMod.Instance.Config; + + foreach (ConfigDefinition setting in modConfig.Keys.Where((setting) => modConfig[setting].SettingType == typeof(string))) { - foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) + string settingValue = (string)modConfig[setting].BoxedValue; + string settingDesc = modConfig[setting].Description.Description; + if (settingDesc.ToLower() == "modmenu_text") { - if (Input.GetKey(vKey)) - { - newKey = vKey.ToString(); - configKeys[key] = newKey; - pressed = true; - modIni.Write(key, newKey); - break; - } + GUILayout.BeginHorizontal(); + GUILayout.Label(settingValue, ModMenuStyle.readStyle); + GUILayout.EndHorizontal(); } - yield return null; } + + GUILayout.EndScrollView(); + GUILayout.EndVertical(); } + #endregion static string UppercaseFirst(string s) { @@ -566,6 +479,5 @@ static string UppercaseFirst(string s) } return char.ToUpper(s[0]) + s.Substring(1); } - #endregion } } diff --git a/ModMenu/ModMenu.csproj b/ModMenu/ModMenu.csproj index 0b7654a..d0396e0 100644 --- a/ModMenu/ModMenu.csproj +++ b/ModMenu/ModMenu.csproj @@ -1,5 +1,5 @@  - + Debug @@ -9,7 +9,7 @@ Properties ModMenu ModMenu - v4.5 + v3.5 512 true @@ -31,186 +31,43 @@ 4 - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\Assembly-CSharp.dll - - - - - - - - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\TextMeshPro.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.AccessibilityModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.AIModule.dll + + Libs\0Harmony.dll - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.AnimationModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ARModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.AssetBundleModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.AudioModule.dll + + Libs\Assembly-CSharp.dll - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ClothModule.dll + + Libs\BepInEx.dll - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ClusterInputModule.dll + + Libs\BepInEx.Harmony.dll - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ClusterRendererModule.dll + + Libs\TextMeshPro.dll - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.CoreModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.CrashReportingModule.dll + Libs\UnityEngine.CoreModule.dll - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.DirectorModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.GameCenterModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.GridModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ImageConversionModule.dll + + Libs\UnityEngine.dll - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.IMGUIModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.InputModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.JSONSerializeModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.Networking.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ParticlesLegacyModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ParticleSystemModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.PerformanceReportingModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.Physics2DModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.PhysicsModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.ScreenCaptureModule.dll + Libs\UnityEngine.IMGUIModule.dll - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.SharedInternalsModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.SpatialTracking.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.SpriteMaskModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.SpriteShapeModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.StandardEvents.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.StyleSheetsModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.TerrainModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.TerrainPhysicsModule.dll + + Libs\UnityEngine.TextCoreModule.dll - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.TextRenderingModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.TilemapModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.Timeline.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UI.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UIElementsModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UIModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UNETModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UnityAnalyticsModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UnityConnectModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UnityWebRequestAudioModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UnityWebRequestModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UnityWebRequestTextureModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.VehiclesModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.VideoModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.VRModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.WebModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\UnityEngine.WindModule.dll - - - F:\Games\SteamLibrary\steamapps\common\LLBlaze\LLBlaze_Data\Managed\XboxOneCommonImport.dll + Libs\UnityEngine.TextRenderingModule.dll - - + \ No newline at end of file diff --git a/ModMenu/ModMenuIntegration/ModMenuIntegration.cs b/ModMenu/ModMenuIntegration/ModMenuIntegration.cs deleted file mode 100644 index cd742ff..0000000 --- a/ModMenu/ModMenuIntegration/ModMenuIntegration.cs +++ /dev/null @@ -1,189 +0,0 @@ -// Script used to connect to ModMenu -using System.Collections.Generic; -using UnityEngine; -using LLModMenu; -using System.IO; -using System; - -namespace LLModMenu -{ - public class ModMenuIntegration : MonoBehaviour - { - private ModMenu mm; - private bool mmAdded = false; - - public Dictionary configKeys = new Dictionary(); - public Dictionary configBools = new Dictionary(); - public Dictionary configInts = new Dictionary(); - public Dictionary configSliders = new Dictionary(); - public Dictionary configHeaders = new Dictionary(); - public Dictionary configGaps = new Dictionary(); - public Dictionary configText = new Dictionary(); - public List writeQueue = new List(); - - private void Start() - { - try { ReadIni(); } catch { Debug.Log("ModMenu: Could not load " + @"\ModSettings\" + gameObject.name + ".ini" + " so we will create it instead"); } - InitConfig(); - ReadIni(); - } - - private void Update() - { - mm = FindObjectOfType(); - if (mm != null) - { - if (mmAdded == false) - { - mm.mods.Add(base.gameObject.name); - mmAdded = true; - } - } - } - - private void InitConfig() - { - /* - * Mod menu now uses a single function to add options etc. (AddToWriteQueue) - * your specified options should be added to this function in the same format as stated under - * - Keybindings: - AddToWriteQueue("(key)keyName", "LeftShift"); value can be: Any KeyCode as a string e.g. "LeftShift" - - Options: - AddToWriteQueue("(bool)boolName", "true"); value can be: ["true" | "false"] - AddToWriteQueue("(int)intName", "27313"); value can be: any number as a string. For instance "123334" - AddToWriteQueue("(slider)sliderName", "50|0|100"); value must be: "Default value|Min Value|MaxValue" - AddToWriteQueue("(header)headerName", "Header Text"); value can be: Any string - AddToWriteQueue("(gap)gapName", "identifier"); value does not matter, just make name and value unique from other gaps - - ModInformation: - AddToWriteQueue("(text)text1", "Descriptive text"); value can be: Any string - */ - - - // Insert your options here \/ - - ModMenu.Instance.WriteIni(gameObject.name, writeQueue, configKeys, configBools, configInts, configSliders, configHeaders, configGaps, configText); - writeQueue.Clear(); - } - - public void ReadIni() - { - string[] lines = File.ReadAllLines(Directory.GetParent(Application.dataPath).FullName + @"\ModSettings\" + gameObject.name + ".ini"); - configBools.Clear(); - configKeys.Clear(); - configInts.Clear(); - configSliders.Clear(); - configHeaders.Clear(); - configGaps.Clear(); - configText.Clear(); - foreach (string line in lines) - { - if (line.StartsWith("(key)")) - { - string[] split = line.Split('='); - configKeys.Add(split[0], split[1]); - } - else if (line.StartsWith("(bool)")) - { - string[] split = line.Split('='); - configBools.Add(split[0], split[1]); - } - else if (line.StartsWith("(int)")) - { - string[] split = line.Split('='); - configInts.Add(split[0], split[1]); - } - else if (line.StartsWith("(slider)")) - { - string[] split = line.Split('='); - configSliders.Add(split[0], split[1]); - } - else if (line.StartsWith("(header)")) - { - string[] split = line.Split('='); - configHeaders.Add(split[0], split[1]); - } - else if (line.StartsWith("(gap)")) - { - string[] split = line.Split('='); - configGaps.Add(split[0], split[1]); - } - else if (line.StartsWith("(text)")) - { - string[] split = line.Split('='); - configText.Add(split[0], split[1]); - } - } - } - - public void AddToWriteQueue(string key, string value) - { - if (key.StartsWith("(key)")) - { - configKeys.Add(key, value); - writeQueue.Add(key); - } - else if (key.StartsWith("(bool)")) - { - configBools.Add(key, value); - writeQueue.Add(key); - } - else if (key.StartsWith("(int)")) - { - configInts.Add(key, value); - writeQueue.Add(key); - } - else if (key.StartsWith("(slider)")) - { - configSliders.Add(key, value); - writeQueue.Add(key); - } - else if (key.StartsWith("(header)")) - { - configHeaders.Add(key, value); - writeQueue.Add(key); - } - else if (key.StartsWith("(gap)")) - { - configGaps.Add(key, value); - writeQueue.Add(key); - } - else if (key.StartsWith("(text)")) - { - configText.Add(key, value); - writeQueue.Add(key); - } - } - - public KeyCode GetKeyCode(string keyCode) - { - foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) - { - if (vKey.ToString() == keyCode) - { - return vKey; - } - } - return KeyCode.A; - } - - public bool GetTrueFalse(string boolName) - { - if (boolName == "true") return true; - else return false; - } - - public int GetSliderValue(string sliderName) - { - string[] vals = configSliders[sliderName].Split('|'); - return Convert.ToInt32(vals[0]); - } - - public int GetInt(string intName) - { - return Convert.ToInt32(configInts[intName]); - } - } -} \ No newline at end of file diff --git a/ModMenu/ModMenuStyle.cs b/ModMenu/ModMenuStyle.cs old mode 100644 new mode 100755 index f5dacc9..b378cc1 --- a/ModMenu/ModMenuStyle.cs +++ b/ModMenu/ModMenuStyle.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; -namespace LLModMenu +namespace ModMenu { public static class ModMenuStyle { @@ -10,6 +10,7 @@ public static class ModMenuStyle public static void InitStyle() { + texColors.Clear(); texColors.Add("Yellow", ColorToTexture2D(new Color(1f, 0.968f, 0.3f))); texColors.Add("LightYellow", ColorToTexture2D(new Color(1f, 1f, 0.5f))); texColors.Add("DarkGray", ColorToTexture2D(new Color(0.145f, 0.145f, 0.145f))); diff --git a/ModMenu/PluginInfos.cs b/ModMenu/PluginInfos.cs new file mode 100755 index 0000000..380864a --- /dev/null +++ b/ModMenu/PluginInfos.cs @@ -0,0 +1,47 @@ +using System.Reflection; +using ModMenu; + +#region Assembly attributes +/* + * These attributes define various metainformation of the generated DLL. + * In general, you don't need to touch these. Instead, edit the values in PluginInfo. + */ +[assembly: AssemblyVersion(PluginInfos.PLUGIN_VERSION)] +[assembly: AssemblyTitle(PluginInfos.PLUGIN_NAME + " (" + PluginInfos.PLUGIN_ID + ")")] +[assembly: AssemblyProduct(PluginInfos.PLUGIN_NAME)] +#endregion + +namespace ModMenu +{ + /// + /// The main metadata of the plugin. + /// This information is used for BepInEx plugin metadata. + /// + /// + /// See also description of BepInEx metadata: + /// https://bepinex.github.io/bepinex_docs/master/articles/dev_guide/plugin_tutorial/2_plugin_start.html#basic-information-about-the-plug-in + /// + internal static class PluginInfos + { + /// + /// Human-readable name of the plugin. In general, it should be short and concise. + /// This is the name that is shown to the users who run BepInEx and to modders that inspect BepInEx logs. + /// + public const string PLUGIN_NAME = "ModMenu"; + + /// + /// Unique ID of the plugin. + /// This must be a unique string that contains only characters a-z, 0-9 underscores (_) and dots (.) + /// Prefer using the reverse domain name notation: https://eqdn.tech/reverse-domain-notation/ + /// + /// When creating Harmony patches, prefer using this ID for Harmony instances as well. + /// + public const string PLUGIN_ID = "no.mrgentle.plugins.llb.modmenu"; + + /// + /// Version of the plugin. Must be in form .... + /// Major and minor versions are mandatory, but build and revision can be left unspecified. + /// + public const string PLUGIN_VERSION = "1.0.1"; + } +} \ No newline at end of file diff --git a/ModMenu/Properties/AssemblyInfo.cs b/ModMenu/Properties/AssemblyInfo.cs old mode 100644 new mode 100755 index 7c6bdc6..db3b8b5 --- a/ModMenu/Properties/AssemblyInfo.cs +++ b/ModMenu/Properties/AssemblyInfo.cs @@ -5,12 +5,8 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("ModMenu")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ModMenu")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2019")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +28,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] From 19c699fe994d6fe774d52a1b0b087cd9c847123d Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Thu, 9 Sep 2021 18:00:42 +0200 Subject: [PATCH 02/13] Remove unnecessary libs from build --- ModMenu/ModMenu.csproj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ModMenu/ModMenu.csproj b/ModMenu/ModMenu.csproj index d0396e0..1b55c97 100644 --- a/ModMenu/ModMenu.csproj +++ b/ModMenu/ModMenu.csproj @@ -34,33 +34,43 @@ Libs\0Harmony.dll + False Libs\Assembly-CSharp.dll + False Libs\BepInEx.dll + False Libs\BepInEx.Harmony.dll + False Libs\TextMeshPro.dll + False Libs\UnityEngine.CoreModule.dll + False Libs\UnityEngine.dll + False Libs\UnityEngine.IMGUIModule.dll + False Libs\UnityEngine.TextCoreModule.dll + False Libs\UnityEngine.TextRenderingModule.dll + False From 4a7b3cdc8e5617456b3ef35c0364706397a46266 Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Thu, 9 Sep 2021 18:01:19 +0200 Subject: [PATCH 03/13] Change the way info text is passed to modmenu to avoid freezing it in config --- ModMenu/ModMenu.cs | 45 +++++++++++++++++++++++++++++++----------- ModMenu/PluginInfos.cs | 4 ++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/ModMenu/ModMenu.cs b/ModMenu/ModMenu.cs index e7def2c..948e7a1 100755 --- a/ModMenu/ModMenu.cs +++ b/ModMenu/ModMenu.cs @@ -16,7 +16,7 @@ namespace ModMenu public class ModMenu : BaseUnityPlugin { public static ModMenu Instance { get; private set; } = null; - public static List registeredMods = new List(); + public static Dictionary> registeredMods = new Dictionary>(); public void Awake() { Instance = this; @@ -47,9 +47,9 @@ public void Awake() private bool inModSubOptions = false; - public static void RegisterMod(BepInEx.PluginInfo pluginInfo) + public static void RegisterMod(BepInEx.PluginInfo pluginInfo, List modmenu_textinfo = null) { - registeredMods.Add(pluginInfo); + registeredMods.Add(pluginInfo, modmenu_textinfo); } private void Update() @@ -119,7 +119,7 @@ public void HandleModSettingsClick(int playerNr) var vcount = 0; var hcount = 0; - foreach (BepInEx.PluginInfo plugin in registeredMods) + foreach (BepInEx.PluginInfo plugin in registeredMods.Keys) { var obj = Instantiate(modSettingsButton, screen.transform); obj.SetText(plugin.Metadata.Name, 50); @@ -242,8 +242,15 @@ private void OnGUI() GUI.Box(new Rect(10, 10, calc.x + 20, calc.y), "ModMenu " + this.Info.Metadata.Version, ModMenuStyle.versionBox); GUI.Window(0, new Rect(x1, y1, x2, y2 / 3), keybindWindowFunction, "Keybindings", ModMenuStyle.windStyle); - GUI.Window(1, new Rect(x1, y1 + y2 / 3 + 10, x2, y2 / 3), optionsWindowFunction, "Options", ModMenuStyle.windStyle); - GUI.Window(2, new Rect(x1, y1 + ((y2 / 3 + 10) * 2), x2, y2 / 5), textWindowFunction, "Mod Information", ModMenuStyle.windStyle); + if (registeredMods[currentOpenMod] != null) + { + GUI.Window(1, new Rect(x1, y1 + y2 / 3 + 10, x2, y2 / 3), optionsWindowFunction, "Options", ModMenuStyle.windStyle); + GUI.Window(2, new Rect(x1, y1 + ((y2 / 3 + 10) * 2), x2, y2 / 5), textWindowFunction, "Mod Information", ModMenuStyle.windStyle); + } + else + { + GUI.Window(1, new Rect(x1, y1 + y2 / 3 + 10, x2, 2 * y2 / 3 ), optionsWindowFunction, "Options", ModMenuStyle.windStyle); + } GUI.skin.window = null; } @@ -453,18 +460,32 @@ private void OpenTextWindow(int wId) optionsTextpos = GUILayout.BeginScrollView(optionsTextpos, false, true); ConfigFile modConfig = currentOpenMod.Instance.Config; - - foreach (ConfigDefinition setting in modConfig.Keys.Where((setting) => modConfig[setting].SettingType == typeof(string))) + if (registeredMods.ContainsKey(currentOpenMod.Instance.Info) && registeredMods[currentOpenMod.Instance.Info] != null) { - string settingValue = (string)modConfig[setting].BoxedValue; - string settingDesc = modConfig[setting].Description.Description; - if (settingDesc.ToLower() == "modmenu_text") + foreach (string textLine in registeredMods[currentOpenMod.Instance.Info]) { GUILayout.BeginHorizontal(); - GUILayout.Label(settingValue, ModMenuStyle.readStyle); + GUILayout.Label(textLine, ModMenuStyle.readStyle); GUILayout.EndHorizontal(); } } + /* + else + { + // DEPRECATED WILL BE REMOVED SOON + foreach (ConfigDefinition setting in modConfig.Keys.Where((setting) => modConfig[setting].SettingType == typeof(string))) + { + string settingValue = (string)modConfig[setting].BoxedValue; + string settingDesc = modConfig[setting].Description.Description; + if (settingDesc.ToLower() == "modmenu_text") + { + GUILayout.BeginHorizontal(); + GUILayout.Label(settingValue, ModMenuStyle.readStyle); + GUILayout.EndHorizontal(); + } + } + } + */ GUILayout.EndScrollView(); GUILayout.EndVertical(); diff --git a/ModMenu/PluginInfos.cs b/ModMenu/PluginInfos.cs index 380864a..e30fe1b 100755 --- a/ModMenu/PluginInfos.cs +++ b/ModMenu/PluginInfos.cs @@ -21,7 +21,7 @@ namespace ModMenu /// See also description of BepInEx metadata: /// https://bepinex.github.io/bepinex_docs/master/articles/dev_guide/plugin_tutorial/2_plugin_start.html#basic-information-about-the-plug-in /// - internal static class PluginInfos + public static class PluginInfos { /// /// Human-readable name of the plugin. In general, it should be short and concise. @@ -42,6 +42,6 @@ internal static class PluginInfos /// Version of the plugin. Must be in form .... /// Major and minor versions are mandatory, but build and revision can be left unspecified. /// - public const string PLUGIN_VERSION = "1.0.1"; + public const string PLUGIN_VERSION = "1.1.0"; } } \ No newline at end of file From c02646f22fc06bb5cd57ccadc8bf93971ce9a099 Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Mon, 4 Oct 2021 00:19:53 +0200 Subject: [PATCH 04/13] Add Readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5745134 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ModMenu +Configure options straight from the game! From 311177f91a7ab52788809509781a77adde2e6aba Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Mon, 4 Oct 2021 00:23:58 +0200 Subject: [PATCH 05/13] Fix libs --- ModMenu/Libs/0Harmony.dll | 2 +- ModMenu/Libs/BepInEx.Harmony.dll | 1 - ModMenu/Libs/BepInEx.dll | 2 +- ModMenu/ModMenu.csproj | 20 ++++++++------------ 4 files changed, 10 insertions(+), 15 deletions(-) delete mode 120000 ModMenu/Libs/BepInEx.Harmony.dll diff --git a/ModMenu/Libs/0Harmony.dll b/ModMenu/Libs/0Harmony.dll index 689e200..1670607 120000 --- a/ModMenu/Libs/0Harmony.dll +++ b/ModMenu/Libs/0Harmony.dll @@ -1 +1 @@ -../../../../../BepInEx/BepInEx/core/0Harmony.dll \ No newline at end of file +../../../../BepInEx/BepInEx/core/0Harmony.dll \ No newline at end of file diff --git a/ModMenu/Libs/BepInEx.Harmony.dll b/ModMenu/Libs/BepInEx.Harmony.dll deleted file mode 120000 index 0cfd90d..0000000 --- a/ModMenu/Libs/BepInEx.Harmony.dll +++ /dev/null @@ -1 +0,0 @@ -../../../../../BepInEx/BepInEx/core/BepInEx.Harmony.dll \ No newline at end of file diff --git a/ModMenu/Libs/BepInEx.dll b/ModMenu/Libs/BepInEx.dll index 0aefcee..e0a9178 120000 --- a/ModMenu/Libs/BepInEx.dll +++ b/ModMenu/Libs/BepInEx.dll @@ -1 +1 @@ -../../../../../BepInEx/BepInEx/core/BepInEx.dll \ No newline at end of file +../../../../BepInEx/BepInEx/core/BepInEx.dll \ No newline at end of file diff --git a/ModMenu/ModMenu.csproj b/ModMenu/ModMenu.csproj index 1b55c97..9f82d89 100644 --- a/ModMenu/ModMenu.csproj +++ b/ModMenu/ModMenu.csproj @@ -32,22 +32,10 @@ - - Libs\0Harmony.dll - False - Libs\Assembly-CSharp.dll False - - Libs\BepInEx.dll - False - - - Libs\BepInEx.Harmony.dll - False - Libs\TextMeshPro.dll False @@ -72,6 +60,14 @@ Libs\UnityEngine.TextRenderingModule.dll False + + Libs\0Harmony.dll + False + + + Libs\BepInEx.dll + False + From 621101b2e46ba93ef5714dae2349690bd74c96bb Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Sat, 13 Nov 2021 14:43:45 +0100 Subject: [PATCH 06/13] Fix useless warning, add string settings and bump version --- ModMenu/ModMenu.cs | 69 ++++++++++++++++++++++++++++++------------ ModMenu/ModMenu.csproj | 7 ++++- ModMenu/PluginInfos.cs | 2 +- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/ModMenu/ModMenu.cs b/ModMenu/ModMenu.cs index 948e7a1..f8c9762 100755 --- a/ModMenu/ModMenu.cs +++ b/ModMenu/ModMenu.cs @@ -312,7 +312,7 @@ private void OpenOptionsWindow(int wId) else if (settingType == typeof(int)) { if (modConfig[setting].Description?.AcceptableValues is AcceptableValueRange - // NIY || modConfig[setting].Description.AcceptableValues is AcceptableValueRange + // NYI || modConfig[setting].Description.AcceptableValues is AcceptableValueRange ) { MakeSliderSettingGUI(modConfig, setting); @@ -326,8 +326,14 @@ private void OpenOptionsWindow(int wId) { string settingValue = (string)modConfig[setting].BoxedValue; string settingDesc = modConfig[setting].Description.Description; + object[] settingTags = modConfig[setting].Description.Tags; - if (settingDesc.ToLower() == "modmenu_header") + if (settingTags.Contains("modmenu_filepicker") || settingDesc.ToLower() == "modmenu_filepicker") + { + // TODO NYI MakeFilePickerSettingGUI(modConfig, setting); + MakeStringSettingGUI(modConfig, setting); + } + else if (settingTags.Contains("modmenu_header") || settingDesc.ToLower() == "modmenu_header") { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); @@ -335,7 +341,7 @@ private void OpenOptionsWindow(int wId) GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } - else if (settingDesc.ToLower() == "modmenu_gap") + else if (settingTags.Contains("modmenu_gap") || settingDesc.ToLower() == "modmenu_gap") { if (Int32.TryParse(settingValue, out int n)) { @@ -346,6 +352,10 @@ private void OpenOptionsWindow(int wId) GUILayout.Space(20); } } + else + { + MakeStringSettingGUI(modConfig, setting); + } } } @@ -453,6 +463,42 @@ private void MakeSliderSettingGUI(ConfigFile modConfig, ConfigDefinition setting GUILayout.EndHorizontal(); } + private void MakeStringSettingGUI(ConfigFile modConfig, ConfigDefinition setting) + { + string value = (string)modConfig[setting].BoxedValue; + + string formatted = UppercaseFirst(Regex.Replace(setting.Key, "([a-z])([A-Z])", "$1 $2")); + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.Label(formatted + ": ", ModMenuStyle.labStyle); + GUILayout.Space(30); + + string textFieldString = GUILayout.TextField(value, 256, ModMenuStyle._textFieldStyle, GUILayout.MinWidth(120)); + + + GUIStyle test = ModMenuStyle.button; + if ((string)modConfig[setting].BoxedValue != textFieldString) + { + test.fontStyle = FontStyle.Bold; + modConfig.SaveOnConfigSet = false; + modConfig[setting].BoxedValue = textFieldString; + } + bool isFromTextPressed = GUILayout.Button("Set Value", test); + + if (isFromTextPressed) + { + modConfig.Save(); + modConfig.SaveOnConfigSet = true; + } + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + + private void MakeFilePickerSettingGUI(ConfigFile modConfig, ConfigDefinition setting) + { + // TODO NYI + } + private void OpenTextWindow(int wId) { GUILayout.Space(30); @@ -469,23 +515,6 @@ private void OpenTextWindow(int wId) GUILayout.EndHorizontal(); } } - /* - else - { - // DEPRECATED WILL BE REMOVED SOON - foreach (ConfigDefinition setting in modConfig.Keys.Where((setting) => modConfig[setting].SettingType == typeof(string))) - { - string settingValue = (string)modConfig[setting].BoxedValue; - string settingDesc = modConfig[setting].Description.Description; - if (settingDesc.ToLower() == "modmenu_text") - { - GUILayout.BeginHorizontal(); - GUILayout.Label(settingValue, ModMenuStyle.readStyle); - GUILayout.EndHorizontal(); - } - } - } - */ GUILayout.EndScrollView(); GUILayout.EndVertical(); diff --git a/ModMenu/ModMenu.csproj b/ModMenu/ModMenu.csproj index 9f82d89..296e44e 100644 --- a/ModMenu/ModMenu.csproj +++ b/ModMenu/ModMenu.csproj @@ -13,6 +13,11 @@ 512 true + + + $(MSBuildWarningsAsMessages);MSB3277 + + true full @@ -76,4 +81,4 @@ - \ No newline at end of file + diff --git a/ModMenu/PluginInfos.cs b/ModMenu/PluginInfos.cs index e30fe1b..d45c9c2 100755 --- a/ModMenu/PluginInfos.cs +++ b/ModMenu/PluginInfos.cs @@ -42,6 +42,6 @@ public static class PluginInfos /// Version of the plugin. Must be in form .... /// Major and minor versions are mandatory, but build and revision can be left unspecified. /// - public const string PLUGIN_VERSION = "1.1.0"; + public const string PLUGIN_VERSION = "1.2.0"; } } \ No newline at end of file From 7a7a720f16460793d51dd423ef7c59fd2f9beae5 Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Tue, 21 Dec 2021 14:53:28 +0100 Subject: [PATCH 07/13] comments cleanup --- ModMenu/ModMenu.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ModMenu/ModMenu.cs b/ModMenu/ModMenu.cs index f8c9762..9e6844c 100755 --- a/ModMenu/ModMenu.cs +++ b/ModMenu/ModMenu.cs @@ -249,7 +249,7 @@ private void OnGUI() } else { - GUI.Window(1, new Rect(x1, y1 + y2 / 3 + 10, x2, 2 * y2 / 3 ), optionsWindowFunction, "Options", ModMenuStyle.windStyle); + GUI.Window(1, new Rect(x1, y1 + y2 / 3 + 10, x2, 2 * y2 / 3), optionsWindowFunction, "Options", ModMenuStyle.windStyle); } GUI.skin.window = null; @@ -312,7 +312,7 @@ private void OpenOptionsWindow(int wId) else if (settingType == typeof(int)) { if (modConfig[setting].Description?.AcceptableValues is AcceptableValueRange - // NYI || modConfig[setting].Description.AcceptableValues is AcceptableValueRange + // TODO NYI || modConfig[setting].Description.AcceptableValues is AcceptableValueRange ) { MakeSliderSettingGUI(modConfig, setting); @@ -330,8 +330,7 @@ private void OpenOptionsWindow(int wId) if (settingTags.Contains("modmenu_filepicker") || settingDesc.ToLower() == "modmenu_filepicker") { - // TODO NYI MakeFilePickerSettingGUI(modConfig, setting); - MakeStringSettingGUI(modConfig, setting); + MakeFilePickerSettingGUI(modConfig, setting); } else if (settingTags.Contains("modmenu_header") || settingDesc.ToLower() == "modmenu_header") { @@ -497,6 +496,8 @@ private void MakeStringSettingGUI(ConfigFile modConfig, ConfigDefinition setting private void MakeFilePickerSettingGUI(ConfigFile modConfig, ConfigDefinition setting) { // TODO NYI + MakeStringSettingGUI(modConfig, setting); + } private void OpenTextWindow(int wId) From 0a7a2eb66aacbaaf632020b04f0e7a00e21ffd0d Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Fri, 27 May 2022 16:03:56 +0200 Subject: [PATCH 08/13] File and directory pickers + cleaning/refactoring a bit --- ModMenu/Libs/SFB.dll | 1 + ModMenu/ModMenu.cs | 152 ++++++++++++++++++++++++++++++----------- ModMenu/ModMenu.csproj | 13 +++- ModMenu/PluginInfos.cs | 2 +- 4 files changed, 128 insertions(+), 40 deletions(-) create mode 120000 ModMenu/Libs/SFB.dll diff --git a/ModMenu/Libs/SFB.dll b/ModMenu/Libs/SFB.dll new file mode 120000 index 0000000..6de4a56 --- /dev/null +++ b/ModMenu/Libs/SFB.dll @@ -0,0 +1 @@ +../../../SFB/SFB/bin/Release/SFB.dll \ No newline at end of file diff --git a/ModMenu/ModMenu.cs b/ModMenu/ModMenu.cs index 9e6844c..656b38d 100755 --- a/ModMenu/ModMenu.cs +++ b/ModMenu/ModMenu.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -12,6 +14,7 @@ namespace ModMenu { [BepInPlugin(PluginInfos.PLUGIN_ID, PluginInfos.PLUGIN_NAME, PluginInfos.PLUGIN_VERSION)] + [BepInDependency(SFB.PluginInfos.PLUGIN_ID, BepInDependency.DependencyFlags.HardDependency)] [BepInProcess("LLBlaze.exe")] public class ModMenu : BaseUnityPlugin { @@ -41,7 +44,6 @@ public void Awake() private bool sliderChange = false; private ConfigDefinition definitionToRebind = null; private bool rebindingKey = false; - private int switchInputModeTimer = 0; private bool inModOptions = false; public static bool InModOptions => Instance.inModOptions; private bool inModSubOptions = false; @@ -89,9 +91,6 @@ private void Update() } } - - if (switchInputModeTimer != 30) switchInputModeTimer++; - if (inModSubOptions && this.currentOpenMod != this.previousOpenMod) //If we are within the options of a spiesific mod. { this.previousOpenMod = this.currentOpenMod; @@ -304,8 +303,27 @@ private void OpenOptionsWindow(int wId) foreach (ConfigDefinition setting in modConfig.Keys) { + object[] settingTags = modConfig[setting].Description.Tags; Type settingType = modConfig[setting].SettingType; - if (settingType == typeof(bool)) + + if (modConfig[setting].Description.Tags.Contains("modmenu_hidden")) + { + continue; + } + else if (settingTags.Contains("modmenu_filepicker") || + settingTags.Contains("modmenu_directorypicker")) + { + MakeFilePickerSettingGUI(modConfig, setting); + } + else if (settingTags.Contains("modmenu_header")) + { + MakeHeaderGUI(modConfig, setting); + } + else if (settingTags.Contains("modmenu_gap")) + { + MakeGapGUI(modConfig, setting); + } + else if (settingType == typeof(bool)) { MakeBoolSettingGUI(modConfig, setting); } @@ -324,37 +342,7 @@ private void OpenOptionsWindow(int wId) } else if (settingType == typeof(string)) { - string settingValue = (string)modConfig[setting].BoxedValue; - string settingDesc = modConfig[setting].Description.Description; - object[] settingTags = modConfig[setting].Description.Tags; - - if (settingTags.Contains("modmenu_filepicker") || settingDesc.ToLower() == "modmenu_filepicker") - { - MakeFilePickerSettingGUI(modConfig, setting); - } - else if (settingTags.Contains("modmenu_header") || settingDesc.ToLower() == "modmenu_header") - { - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - GUILayout.Box(settingValue, ModMenuStyle.headerBox); - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - } - else if (settingTags.Contains("modmenu_gap") || settingDesc.ToLower() == "modmenu_gap") - { - if (Int32.TryParse(settingValue, out int n)) - { - GUILayout.Space(n); - } - else - { - GUILayout.Space(20); - } - } - else - { - MakeStringSettingGUI(modConfig, setting); - } + MakeStringSettingGUI(modConfig, setting); } } @@ -363,6 +351,32 @@ private void OpenOptionsWindow(int wId) GUILayout.EndHorizontal(); } + private void MakeHeaderGUI(ConfigFile modConfig, ConfigDefinition setting) + { + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.Box((string)modConfig[setting].BoxedValue, ModMenuStyle.headerBox); + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + + private void MakeGapGUI(ConfigFile modConfig, ConfigDefinition setting) + { + Type settingType = modConfig[setting].SettingType; + if (settingType == typeof(int)) + { + GUILayout.Space((int)modConfig[setting].BoxedValue); + } + else if (Int32.TryParse((string)modConfig[setting].BoxedValue, out int n)) + { + GUILayout.Space(n); + } + else + { + GUILayout.Space(20); + } + } + private void MakeBoolSettingGUI(ConfigFile modConfig, ConfigDefinition setting) { @@ -495,9 +509,71 @@ private void MakeStringSettingGUI(ConfigFile modConfig, ConfigDefinition setting private void MakeFilePickerSettingGUI(ConfigFile modConfig, ConfigDefinition setting) { - // TODO NYI - MakeStringSettingGUI(modConfig, setting); + string value = (string)modConfig[setting].BoxedValue; + string formatted = UppercaseFirst(Regex.Replace(setting.Key, "([a-z])([A-Z])", "$1 $2")); + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.Label(formatted + ": ", ModMenuStyle.labStyle); + GUILayout.Space(30); + string textFieldString = GUILayout.TextField(value, 256, ModMenuStyle._textFieldStyle, GUILayout.MinWidth(120)); + + GUIStyle llbButtonStyle = ModMenuStyle.button; + if ((string)modConfig[setting].BoxedValue != textFieldString) + { + llbButtonStyle.fontStyle = FontStyle.Bold; + modConfig.SaveOnConfigSet = false; + modConfig[setting].BoxedValue = textFieldString; + } + + bool isFromTextPressed = GUILayout.Button("Set Value", llbButtonStyle); + bool isBrowseFilesPressed = GUILayout.Button("Browse Files", ModMenuStyle.button); + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + + if (isFromTextPressed) + { + modConfig.Save(); + modConfig.SaveOnConfigSet = true; + return; + } + if (isBrowseFilesPressed) + { + object[] settingTags = modConfig[setting].Description.Tags; + if (settingTags.Contains("modmenu_directorypicker")) + { + SFB.StandaloneFileBrowser.OpenFolderPanelAsync( + "Select Folder for: " + modConfig[setting].Definition.Key, + value, + false, + FileSelectionCallback(modConfig[setting]) + ); + } else if (settingTags.Contains("modmenu_filepicker")) + { + SFB.StandaloneFileBrowser.OpenFilePanelAsync( + "Select File for: " + modConfig[setting].Definition.Key, + value, + "*", + false, + FileSelectionCallback(modConfig[setting]) + ); + } + } + } + private Action FileSelectionCallback(ConfigEntryBase setting) + { + return (string[] results) => + { + if (results.Length > 0 && results[0].Length > 0) + { + Logger.LogDebug("Got directory: '" + results[0] + "'."); + setting.BoxedValue = results[0]; + } + else + { + Logger.LogInfo("File selection was cancelled."); + } + }; } private void OpenTextWindow(int wId) diff --git a/ModMenu/ModMenu.csproj b/ModMenu/ModMenu.csproj index 296e44e..b4390bf 100644 --- a/ModMenu/ModMenu.csproj +++ b/ModMenu/ModMenu.csproj @@ -26,14 +26,19 @@ DEBUG;TRACE prompt 4 + true + + false - pdbonly + true + embedded true bin\Release\ TRACE prompt 4 + true @@ -73,6 +78,12 @@ Libs\BepInEx.dll False + + True + + + Libs\SFB.dll + diff --git a/ModMenu/PluginInfos.cs b/ModMenu/PluginInfos.cs index d45c9c2..f502f53 100755 --- a/ModMenu/PluginInfos.cs +++ b/ModMenu/PluginInfos.cs @@ -42,6 +42,6 @@ public static class PluginInfos /// Version of the plugin. Must be in form .... /// Major and minor versions are mandatory, but build and revision can be left unspecified. /// - public const string PLUGIN_VERSION = "1.2.0"; + public const string PLUGIN_VERSION = "1.3.0"; } } \ No newline at end of file From b287de2425ca22c1eba976a17f34ae649dce4007 Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Sat, 17 Dec 2022 13:39:19 +0100 Subject: [PATCH 09/13] Transform InModOptions to a pure function, this makes it easier to access with reflection --- ModMenu/ModMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModMenu/ModMenu.cs b/ModMenu/ModMenu.cs index 656b38d..9f77856 100755 --- a/ModMenu/ModMenu.cs +++ b/ModMenu/ModMenu.cs @@ -45,7 +45,7 @@ public void Awake() private ConfigDefinition definitionToRebind = null; private bool rebindingKey = false; private bool inModOptions = false; - public static bool InModOptions => Instance.inModOptions; + public static bool InModOptions() => Instance.inModOptions; private bool inModSubOptions = false; From 1577eb4621c0f5cb31fa84582234af1ad825ae03 Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Sat, 31 Dec 2022 22:52:13 +0100 Subject: [PATCH 10/13] bumped version --- ModMenu/PluginInfos.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModMenu/PluginInfos.cs b/ModMenu/PluginInfos.cs index f502f53..ace86f8 100755 --- a/ModMenu/PluginInfos.cs +++ b/ModMenu/PluginInfos.cs @@ -42,6 +42,6 @@ public static class PluginInfos /// Version of the plugin. Must be in form .... /// Major and minor versions are mandatory, but build and revision can be left unspecified. /// - public const string PLUGIN_VERSION = "1.3.0"; + public const string PLUGIN_VERSION = "1.3.1"; } } \ No newline at end of file From 93d393e2d0d256f90a8baf4efc56525fc738afce Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Sun, 6 Oct 2024 16:40:01 +0200 Subject: [PATCH 11/13] Switched to the publicized assembly --- ModMenu/Libs/Assembly-CSharp-publicized.dll | 1 + ModMenu/Libs/Assembly-CSharp.dll | 1 - ModMenu/ModMenu.csproj | 9 ++++----- 3 files changed, 5 insertions(+), 6 deletions(-) create mode 120000 ModMenu/Libs/Assembly-CSharp-publicized.dll delete mode 120000 ModMenu/Libs/Assembly-CSharp.dll diff --git a/ModMenu/Libs/Assembly-CSharp-publicized.dll b/ModMenu/Libs/Assembly-CSharp-publicized.dll new file mode 120000 index 0000000..eb66175 --- /dev/null +++ b/ModMenu/Libs/Assembly-CSharp-publicized.dll @@ -0,0 +1 @@ +../../../../llb_dlls/Assembly-CSharp-publicized.dll \ No newline at end of file diff --git a/ModMenu/Libs/Assembly-CSharp.dll b/ModMenu/Libs/Assembly-CSharp.dll deleted file mode 120000 index 27d2849..0000000 --- a/ModMenu/Libs/Assembly-CSharp.dll +++ /dev/null @@ -1 +0,0 @@ -../../../../llb_dlls/Assembly-CSharp.dll \ No newline at end of file diff --git a/ModMenu/ModMenu.csproj b/ModMenu/ModMenu.csproj index b4390bf..6563788 100644 --- a/ModMenu/ModMenu.csproj +++ b/ModMenu/ModMenu.csproj @@ -41,11 +41,11 @@ true - - Libs\Assembly-CSharp.dll + Libs\Assembly-CSharp-publicized.dll False + Libs\TextMeshPro.dll False @@ -78,11 +78,10 @@ Libs\BepInEx.dll False - - True - + Libs\SFB.dll + False From 3ac84b9c6807a501988d851094f976424b416b9c Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Sun, 6 Oct 2024 16:40:35 +0200 Subject: [PATCH 12/13] removed reflection access, and use direct access via publicized assembly --- ModMenu/ModMenu.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ModMenu/ModMenu.cs b/ModMenu/ModMenu.cs index 9f77856..be11a50 100755 --- a/ModMenu/ModMenu.cs +++ b/ModMenu/ModMenu.cs @@ -30,7 +30,6 @@ public void Awake() private ScreenMenu mainmenu = null; private ScreenBase submenu = null; - private AccessTools.FieldRef _currentScreens = AccessTools.FieldRefAccess(typeof(LLScreen.UIScreen), "currentScreens"); private LLButton modSettingsButton = null; public List modButtons = new List(); @@ -76,12 +75,12 @@ private void Update() } } } - if (mainmenu == null) - mainmenu = FindObjectOfType(); + if (mainmenu == null && UIScreen.currentScreens[0] is ScreenMenu screen0) + mainmenu = screen0; if (submenu == null) { - submenu = _currentScreens.Invoke()[1]; + submenu = UIScreen.currentScreens[1]; } else { @@ -159,7 +158,7 @@ private void HandleQuitClick(int playerNr) } } } - if (_currentScreens.Invoke()[1].screenType == ScreenType.MENU_OPTIONS) + if (UIScreen.currentScreens[1].screenType == ScreenType.MENU_OPTIONS) { mainmenu.lbTitle.text = "OPTIONS"; inModOptions = false; @@ -222,6 +221,8 @@ public LLButton InitModSettingsButton() private GUI.WindowFunction textWindowFunction = null; private void OnGUI() { + + if (keybindWindowFunction == null) keybindWindowFunction = new GUI.WindowFunction(OpenKeybindsWindow); if (optionsWindowFunction == null) @@ -524,7 +525,7 @@ private void MakeFilePickerSettingGUI(ConfigFile modConfig, ConfigDefinition set modConfig.SaveOnConfigSet = false; modConfig[setting].BoxedValue = textFieldString; } - + bool isFromTextPressed = GUILayout.Button("Set Value", llbButtonStyle); bool isBrowseFilesPressed = GUILayout.Button("Browse Files", ModMenuStyle.button); GUILayout.FlexibleSpace(); @@ -542,9 +543,9 @@ private void MakeFilePickerSettingGUI(ConfigFile modConfig, ConfigDefinition set if (settingTags.Contains("modmenu_directorypicker")) { SFB.StandaloneFileBrowser.OpenFolderPanelAsync( - "Select Folder for: " + modConfig[setting].Definition.Key, - value, - false, + "Select Folder for: " + modConfig[setting].Definition.Key, + value, + false, FileSelectionCallback(modConfig[setting]) ); } else if (settingTags.Contains("modmenu_filepicker")) From 29a7e18cbeb0d0527c8a71568aa9983f6fc45f27 Mon Sep 17 00:00:00 2001 From: Glomzubuk Date: Sun, 6 Oct 2024 16:40:44 +0200 Subject: [PATCH 13/13] bumped version --- ModMenu/PluginInfos.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ModMenu/PluginInfos.cs b/ModMenu/PluginInfos.cs index ace86f8..9bbbaed 100755 --- a/ModMenu/PluginInfos.cs +++ b/ModMenu/PluginInfos.cs @@ -4,7 +4,7 @@ #region Assembly attributes /* * These attributes define various metainformation of the generated DLL. - * In general, you don't need to touch these. Instead, edit the values in PluginInfo. + * In general, you don't need to touch these. Instead, edit the values in PluginInfo. */ [assembly: AssemblyVersion(PluginInfos.PLUGIN_VERSION)] [assembly: AssemblyTitle(PluginInfos.PLUGIN_NAME + " (" + PluginInfos.PLUGIN_ID + ")")] @@ -25,7 +25,7 @@ public static class PluginInfos { /// /// Human-readable name of the plugin. In general, it should be short and concise. - /// This is the name that is shown to the users who run BepInEx and to modders that inspect BepInEx logs. + /// This is the name that is shown to the users who run BepInEx and to modders that inspect BepInEx logs. /// public const string PLUGIN_NAME = "ModMenu"; @@ -42,6 +42,6 @@ public static class PluginInfos /// Version of the plugin. Must be in form .... /// Major and minor versions are mandatory, but build and revision can be left unspecified. /// - public const string PLUGIN_VERSION = "1.3.1"; + public const string PLUGIN_VERSION = "1.3.2"; } -} \ No newline at end of file +}