diff --git a/AutoStore/BepInExPlugin.cs b/AutoStore/BepInExPlugin.cs index 9f68217..079c1f3 100644 --- a/AutoStore/BepInExPlugin.cs +++ b/AutoStore/BepInExPlugin.cs @@ -215,7 +215,7 @@ static void Postfix(Container __instance, ZNetView ___m_nview) continue; Dbgl($"auto storing {item.m_itemData.m_dropPrefab.name} from ground"); - + item.GetComponent().ClaimOwnership(); while (item.m_itemData.m_stack > 1 && __instance.GetInventory().CanAddItem(item.m_itemData, 1)) { diff --git a/ConfigurationManager/ConfigurationManager.cs b/ConfigurationManager/BepInExPlugin.cs similarity index 82% rename from ConfigurationManager/ConfigurationManager.cs rename to ConfigurationManager/BepInExPlugin.cs index d07ccd9..7b8eadb 100644 --- a/ConfigurationManager/ConfigurationManager.cs +++ b/ConfigurationManager/BepInExPlugin.cs @@ -1,26 +1,25 @@ // Based on code made by MarC0 / ManlyMarco // Copyright 2018 GNU General Public License v3.0 +using BepInEx; +using BepInEx.Bootstrap; +using BepInEx.Configuration; +using BepInEx.Logging; +using HarmonyLib; using System; using System.Collections.Generic; -using System.ComponentModel; using System.IO; using System.Linq; using System.Reflection; -using BepInEx; -using BepInEx.Logging; using UnityEngine; -using BepInEx.Configuration; -using HarmonyLib; namespace ConfigurationManager { /// /// An easy way to let user configure how a plugin behaves without the need to make your own GUI. The user can change any of the settings you expose, even keyboard shortcuts. - /// https://github.com/ManlyMarco/BepInEx.ConfigurationManager /// - [BepInPlugin(GUID, "Valheim Configuration Manager", Version)] - public class ConfigurationManager : BaseUnityPlugin + [BepInPlugin(GUID, "Valheim Configuration Manager", "0.3.3")] + public class BepInExPlugin : BaseUnityPlugin { /// /// GUID of this plugin @@ -30,13 +29,10 @@ public class ConfigurationManager : BaseUnityPlugin public static void Dbgl(string str = "", bool pref = true) { if (isDebug) - Debug.Log((pref ? typeof(ConfigurationManager).Namespace + " " : "") + str); + Debug.Log((pref ? typeof(BepInExPlugin).Namespace + " " : "") + str); } - /// - /// Version constant - /// - public const string Version = "0.1.0"; - private static ConfigurationManager context; + + private static BepInExPlugin context; internal static new ManualLogSource Logger; private static SettingFieldDrawer _fieldDrawer; @@ -91,6 +87,20 @@ public static void Dbgl(string str = "", bool pref = true) public static ConfigEntry _pluginConfigCollapsedDefault; public static ConfigEntry _windowPosition; public static ConfigEntry _windowSize; + + public static ConfigEntry _windowTitle; + public static ConfigEntry _normalText; + public static ConfigEntry _shortcutsText; + public static ConfigEntry _advancedText; + public static ConfigEntry _searchText; + public static ConfigEntry _reloadText; + public static ConfigEntry _resetText; + public static ConfigEntry _resetSettingText; + public static ConfigEntry _expandText; + public static ConfigEntry _collapseText; + public static ConfigEntry _tipText; + public static ConfigEntry _clearText; + public static ConfigEntry _textSize; public static ConfigEntry _windowBackgroundColor; public static ConfigEntry _entryBackgroundColor; @@ -103,6 +113,7 @@ public static void Dbgl(string str = "", bool pref = true) public static GUIStyle headerStyle; public static GUIStyle entryStyle; public static GUIStyle labelStyle; + public static GUIStyle textStyle; public static GUIStyle toggleStyle; public static GUIStyle buttonStyle; public static GUIStyle boxStyle; @@ -113,7 +124,7 @@ public static void Dbgl(string str = "", bool pref = true) public static int fontSize = 14; /// - public ConfigurationManager() + public BepInExPlugin() { context = this; Logger = base.Logger; @@ -129,21 +140,35 @@ public ConfigurationManager() _showKeybinds = Config.Bind("Filtering", "Show keybinds", true); _showSettings = Config.Bind("Filtering", "Show settings", true); _hideSingleSection = Config.Bind("General", "Hide single sections", false, new ConfigDescription("Show section title for plugins with only one section")); + + _windowTitle = Config.Bind("Text", "WindowTitle", "Configuration Manager", new ConfigDescription("Window title text")); + _normalText = Config.Bind("Text", "NormalText", "Normal", new ConfigDescription("Normal settings toggle text")); + _shortcutsText = Config.Bind("Text", "ShortcutsText", "Keybinds", new ConfigDescription("Shortcut key settings toggle text")); + _advancedText = Config.Bind("Text", "AdvancedText", "Advanced", new ConfigDescription("Advanced settings toggle text")); + _searchText = Config.Bind("Text", "SearchText", "Search Settings: ", new ConfigDescription("Search label text")); + _reloadText = Config.Bind("Text", "ReloadText", "Reload From File", new ConfigDescription("Reload mod config from file text")); + _resetText = Config.Bind("Text", "ResetText", "Reset To Default", new ConfigDescription("Reset mod config to default text")); + _resetSettingText = Config.Bind("Text", "ResetSettingText", "Reset", new ConfigDescription("Reset setting text")); + _expandText = Config.Bind("Text", "ExpandText", "Expand", new ConfigDescription("Expand button text")); + _collapseText = Config.Bind("Text", "CollapseText", "Collapse", new ConfigDescription("Collapse button text")); + _tipText = Config.Bind("Text", "TipText", "Tip: Click plugin names to expand. Click setting and group names to see their descriptions.", new ConfigDescription("Tip text")); + _clearText = Config.Bind("Text", "ClearText", "Clear", new ConfigDescription("Clear search text")); + _pluginConfigCollapsedDefault = Config.Bind("General", "Plugin collapsed default", true, new ConfigDescription("If set to true plugins will be collapsed when opening the configuration manager window")); _windowPosition = Config.Bind("General", "WindowPosition", new Vector2(55,35), "Window position"); _windowSize = Config.Bind("General", "WindowSize", DefaultWindowRect.size, "Window size"); _textSize = Config.Bind("General", "FontSize", 14, "Font Size"); _windowBackgroundColor = Config.Bind("Colors", "WindowBackgroundColor", new Color(0,0,0,1), "Window background color"); - _entryBackgroundColor = Config.Bind("Colors", "EntryBackgroundColor", new Color(0.557f, 0.502f, 0.502f, 0.871f), "Etnry background color"); + _entryBackgroundColor = Config.Bind("Colors", "EntryBackgroundColor", new Color(0.557f, 0.502f, 0.502f, 0.871f), "Entry background color"); _fontColor = Config.Bind("Colors", "FontColor", new Color(1, 0.714f, 0.361f, 1), "Font color"); _widgetBackgroundColor = Config.Bind("Colors", "WidgetColor", new Color(0.882f, 0.463f, 0, 0.749f), "Widget color"); currentWindowRect = new Rect(_windowPosition.Value, _windowSize.Value); + Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), null); } - private void OnGUI() { if (DisplayingWindow) @@ -164,10 +189,14 @@ private void OnGUI() GUI.Box(currentWindowRect, GUIContent.none, new GUIStyle()); GUI.backgroundColor = _windowBackgroundColor.Value; - if(_windowSize.Value.x > 100 && _windowSize.Value.x < Screen.width && _windowSize.Value.y > 100 && _windowSize.Value.y < Screen.height) + if(_windowSize.Value.x > 200 && _windowSize.Value.x < Screen.width && _windowSize.Value.y > 200 && _windowSize.Value.y < Screen.height) currentWindowRect.size = _windowSize.Value; - currentWindowRect = GUILayout.Window(WindowId, currentWindowRect, SettingsWindow, "Plugin / mod settings", windowStyle); + RightColumnWidth = Mathf.RoundToInt(currentWindowRect.width / 2.5f * fontSize / 12f); + LeftColumnWidth = Mathf.RoundToInt(currentWindowRect.width - RightColumnWidth - 115); + + + currentWindowRect = GUILayout.Window(WindowId, currentWindowRect, SettingsWindow, _windowTitle.Value, windowStyle); if (!SettingFieldDrawer.SettingKeyboardShortcut) Input.ResetInputAxes(); @@ -183,7 +212,7 @@ private void OnGUI() private void SettingsWindow(int id) { GUI.DragWindow(new Rect(0, 0, currentWindowRect.width, 20)); - //DrawWindowHeader(); + DrawWindowHeader(); _settingWindowScrollPos = GUILayout.BeginScrollView(_settingWindowScrollPos, false, true); @@ -257,13 +286,13 @@ private void DrawTips() { GUILayout.BeginHorizontal(); { - GUILayout.Label("Tip: Click plugin names to expand. Click setting and group names to see their descriptions.", labelStyle); + GUILayout.Label(_tipText.Value, labelStyle); GUILayout.FlexibleSpace(); Color color = GUI.backgroundColor; GUI.backgroundColor = _widgetBackgroundColor.Value; - if (GUILayout.Button(_pluginConfigCollapsedDefault.Value ? "Expand" : "Collapse", buttonStyle, GUILayout.ExpandWidth(false))) + if (GUILayout.Button(_pluginConfigCollapsedDefault.Value ? _expandText.Value : _collapseText.Value, buttonStyle, GUILayout.ExpandWidth(false))) { var newValue = !_pluginConfigCollapsedDefault.Value; _pluginConfigCollapsedDefault.Value = newValue; @@ -280,25 +309,23 @@ private void DrawWindowHeader() GUI.backgroundColor = _entryBackgroundColor.Value; GUILayout.BeginHorizontal(); { - GUILayout.Label("Show: ", labelStyle, GUILayout.ExpandWidth(false)); - GUI.enabled = SearchString == string.Empty; - var newVal = GUILayout.Toggle(_showSettings.Value, "Normal settings", toggleStyle); + var newVal = GUILayout.Toggle(_showSettings.Value, _normalText.Value, toggleStyle); if (_showSettings.Value != newVal) { _showSettings.Value = newVal; BuildFilteredSettingList(); } - newVal = GUILayout.Toggle(_showKeybinds.Value, "Keyboard shortcuts", toggleStyle); + newVal = GUILayout.Toggle(_showKeybinds.Value, _shortcutsText.Value, toggleStyle); if (_showKeybinds.Value != newVal) { _showKeybinds.Value = newVal; BuildFilteredSettingList(); } - newVal = GUILayout.Toggle(_showAdvanced.Value, "Advanced settings", toggleStyle); + newVal = GUILayout.Toggle(_showAdvanced.Value, _advancedText.Value, toggleStyle); if (_showAdvanced.Value != newVal) { _showAdvanced.Value = newVal; @@ -321,10 +348,9 @@ private void DrawWindowHeader() } } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(); { - GUILayout.Label("Search settings: ", labelStyle, GUILayout.ExpandWidth(false)); + GUILayout.Label(_searchText.Value, labelStyle, GUILayout.ExpandWidth(false)); GUI.SetNextControlName(SearchBoxName); SearchString = GUILayout.TextField(SearchString, GUILayout.ExpandWidth(true)); @@ -337,7 +363,7 @@ private void DrawWindowHeader() } Color color = GUI.backgroundColor; GUI.backgroundColor = _widgetBackgroundColor.Value; - if (GUILayout.Button("Clear", buttonStyle, GUILayout.ExpandWidth(false))) + if (GUILayout.Button(_clearText.Value, buttonStyle, GUILayout.ExpandWidth(false))) SearchString = string.Empty; GUI.backgroundColor = color; } @@ -380,6 +406,35 @@ private void DrawSinglePlugin(PluginSettingsData plugin) GUILayout.Space(2); } } + GUILayout.BeginHorizontal(); + var color = GUI.backgroundColor; + GUI.backgroundColor = _widgetBackgroundColor.Value; + if (GUILayout.Button(_reloadText.Value, buttonStyle, GUILayout.ExpandWidth(true))) + { + foreach (var category in plugin.Categories) + { + foreach (var setting in category.Settings) + { + setting.PluginInstance.Config.Reload(); + break; + } + break; + } + BuildFilteredSettingList(); + } + if (GUILayout.Button(_resetText.Value, buttonStyle, GUILayout.ExpandWidth(true))) + { + foreach (var category in plugin.Categories) + { + foreach (var setting in category.Settings) + { + setting.Set(setting.DefaultValue); + } + } + BuildFilteredSettingList(); + } + GUI.backgroundColor = color; + GUILayout.EndHorizontal(); } GUILayout.EndVertical(); @@ -423,7 +478,7 @@ private static void DrawDefaultButton(SettingEntryBase setting) bool DrawDefaultButton() { GUILayout.Space(5); - return GUILayout.Button("Reset", buttonStyle, GUILayout.ExpandWidth(false)); + return GUILayout.Button(_resetSettingText.Value, buttonStyle, GUILayout.ExpandWidth(false)); } if (setting.DefaultValue != null) @@ -548,8 +603,7 @@ string GetCategory(SettingEntryBase eb) .OrderBy(x => string.Equals(x.Key, shortcutsCatName, StringComparison.Ordinal)) .ThenBy(x => x.Key) .Select(x => new PluginSettingsData.PluginSettingsGroupData { Name = x.Key, Settings = x.OrderByDescending(set => set.Order).ThenBy(set => set.DispName).ToList() }); - - return new PluginSettingsData { Info = pluginSettings.Key, Categories = categories.ToList(), Collapsed = nonDefaultCollpasingStateByPluginName.Contains(pluginSettings.Key.Name) ? !settingsAreCollapsed : settingsAreCollapsed }; + return new PluginSettingsData {Info = pluginSettings.Key, Categories = categories.ToList(), Collapsed = nonDefaultCollpasingStateByPluginName.Contains(pluginSettings.Key.Name) ? !settingsAreCollapsed : settingsAreCollapsed }; }) .OrderBy(x => x.Info.Name) .ToList(); @@ -557,7 +611,7 @@ string GetCategory(SettingEntryBase eb) private static bool IsKeyboardShortcut(SettingEntryBase x) { - return x.SettingType == typeof(BepInEx.Configuration.KeyboardShortcut); + return x.SettingType == typeof(KeyboardShortcut); } private static bool ContainsSearchString(SettingEntryBase setting, string[] searchStrings) @@ -576,7 +630,7 @@ private static bool ContainsSearchString(SettingEntryBase setting, string[] sear private void CalculateDefaultWindowRect() { var width = Mathf.Min(Screen.width, 650); - var height = Screen.height < 560 ? Screen.height : Screen.height - 100; + var height = Screen.height < 800 ? Screen.height : 800; var offsetX = Mathf.RoundToInt((Screen.width - width) / 2f); var offsetY = Mathf.RoundToInt((Screen.height - height) / 2f); DefaultWindowRect = new Rect(offsetX, offsetY, width, height); @@ -639,6 +693,20 @@ private set private void Start() { + + try + { + Dbgl("Searching for vanilla Config Manager."); + var vanilla = Chainloader.PluginInfos.First(p => p.Key == "com.bepis.bepinex.configurationmanager"); + vanilla.Value.Instance.enabled = false; + Dbgl("Disabled Vanilla Config Manager"); + } + catch + { + Dbgl("Vanilla Config Manager not found."); + } + + // Use reflection to keep compatibility with unity 4.x since it doesn't have Cursor var tCursor = typeof(Cursor); _curLockState = tCursor.GetProperty("lockState", BindingFlags.Static | BindingFlags.Public); @@ -683,6 +751,10 @@ private void CreateStyles() labelStyle.normal.textColor = _fontColor.Value; labelStyle.fontSize = fontSize; + textStyle = new GUIStyle(GUI.skin.textArea); + textStyle.normal.textColor = _fontColor.Value; + textStyle.fontSize = fontSize; + buttonStyle = new GUIStyle(GUI.skin.button); buttonStyle.normal.textColor = _fontColor.Value; buttonStyle.fontSize = fontSize; @@ -774,7 +846,7 @@ static class InputText_Patch static bool Prefix(Console __instance) { string text = __instance.m_input.text; - if (text.ToLower().Equals($"{typeof(ConfigurationManager).Namespace.ToLower()} reset")) + if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} reset")) { context.Config.Reload(); context.Config.Save(); diff --git a/ConfigurationManager/ConfigurationManager.csproj b/ConfigurationManager/ConfigurationManager.csproj index 049fc36..0220ed8 100644 --- a/ConfigurationManager/ConfigurationManager.csproj +++ b/ConfigurationManager/ConfigurationManager.csproj @@ -96,7 +96,7 @@ - + diff --git a/ConfigurationManager/LegacySettingEntry.cs b/ConfigurationManager/LegacySettingEntry.cs index a80a618..bdbda95 100644 --- a/ConfigurationManager/LegacySettingEntry.cs +++ b/ConfigurationManager/LegacySettingEntry.cs @@ -46,7 +46,7 @@ public static LegacySettingEntry FromConfigWrapper(object instance, PropertyInfo if (wrapper == null) { - ConfigurationManager.Logger.Log(LogLevel.Debug, $"Skipping ConfigWrapper entry because it's null : {instance} | {settingProp.Name} | {pluginInfo?.Name}"); + BepInExPlugin.Logger.Log(LogLevel.Debug, $"Skipping ConfigWrapper entry because it's null : {instance} | {settingProp.Name} | {pluginInfo?.Name}"); return null; } @@ -57,7 +57,7 @@ public static LegacySettingEntry FromConfigWrapper(object instance, PropertyInfo if (innerProp == null) { - ConfigurationManager.Logger.Log(LogLevel.Error, "Failed to find property Value of ConfigWrapper"); + BepInExPlugin.Logger.Log(LogLevel.Error, "Failed to find property Value of ConfigWrapper"); return null; } @@ -106,7 +106,7 @@ public static LegacySettingEntry FromConfigWrapper(object instance, PropertyInfo } catch (SystemException ex) { - ConfigurationManager.Logger.Log(LogLevel.Error, + BepInExPlugin.Logger.Log(LogLevel.Error, $"Failed to create ConfigWrapper entry : {instance} | {settingProp?.Name} | {pluginInfo?.Name} | Error: {ex.Message}"); return null; } diff --git a/ConfigurationManager/SettingEntryBase.cs b/ConfigurationManager/SettingEntryBase.cs index ba8b5ff..77a6ddb 100644 --- a/ConfigurationManager/SettingEntryBase.cs +++ b/ConfigurationManager/SettingEntryBase.cs @@ -175,7 +175,7 @@ internal void SetFromAttributes(object[] attribs, BaseUnityPlugin pluginInstance } catch (Exception ex) { - ConfigurationManager.Logger.LogWarning($"Failed to copy value {propertyPair.my.Name} from provided tag object {attrType.FullName} - " + ex.Message); + BepInExPlugin.Logger.LogWarning($"Failed to copy value {propertyPair.my.Name} from provided tag object {attrType.FullName} - " + ex.Message); } } break; diff --git a/ConfigurationManager/SettingFieldDrawer.cs b/ConfigurationManager/SettingFieldDrawer.cs index d06e2ea..fcaa713 100644 --- a/ConfigurationManager/SettingFieldDrawer.cs +++ b/ConfigurationManager/SettingFieldDrawer.cs @@ -1,6 +1,7 @@ // Based on code made by MarC0 / ManlyMarco // Copyright 2018 GNU General Public License v3.0 +using BepInEx.Configuration; using ConfigurationManager.Utilities; using System; using System.Collections; @@ -21,7 +22,7 @@ internal class SettingFieldDrawer private static readonly Dictionary _comboBoxCache = new Dictionary(); private static readonly Dictionary _colorCache = new Dictionary(); - private readonly ConfigurationManager _instance; + private readonly BepInExPlugin _instance; private static SettingEntryBase _currentKeyboardShortcutToSet; public static bool SettingKeyboardShortcut => _currentKeyboardShortcutToSet != null; @@ -32,6 +33,7 @@ static SettingFieldDrawer() { {typeof(bool), DrawBoolField}, {typeof(BepInEx.Configuration.KeyboardShortcut), DrawKeyboardShortcut}, + {typeof(KeyCode), DrawKeyboardShortcut}, {typeof(Color), DrawColor }, {typeof(Vector2), DrawVector2 }, {typeof(Vector3), DrawVector3 }, @@ -40,14 +42,14 @@ static SettingFieldDrawer() }; } - public SettingFieldDrawer(ConfigurationManager instance) + public SettingFieldDrawer(BepInExPlugin instance) { _instance = instance; } public void DrawSettingValue(SettingEntryBase setting) { - GUI.backgroundColor = ConfigurationManager._widgetBackgroundColor.Value; + GUI.backgroundColor = BepInExPlugin._widgetBackgroundColor.Value; if (setting.CustomDrawer != null) setting.CustomDrawer(setting is ConfigSettingEntry newSetting ? newSetting.Entry : null); @@ -79,21 +81,21 @@ public static void DrawCenteredLabel(string text, params GUILayoutOption[] optio { GUILayout.BeginHorizontal(options); GUILayout.FlexibleSpace(); - GUILayout.Label(text, ConfigurationManager.labelStyle); + GUILayout.Label(text, BepInExPlugin.labelStyle); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } public static void DrawCategoryHeader(string text) { - GUILayout.Label(text, ConfigurationManager.categoryHeaderSkin); + GUILayout.Label(text, BepInExPlugin.categoryHeaderSkin); } public static bool DrawPluginHeader(GUIContent content, bool isCollapsed) { //if (isCollapsed) content.text += "\n..."; - return GUILayout.Button(content, ConfigurationManager.pluginHeaderSkin, GUILayout.ExpandWidth(true)); + return GUILayout.Button(content, BepInExPlugin.pluginHeaderSkin, GUILayout.ExpandWidth(true)); } public static bool DrawCurrentDropdown() @@ -129,9 +131,9 @@ private void DrawFieldBasedOnValueType(SettingEntryBase setting) private static void DrawBoolField(SettingEntryBase setting) { - GUI.backgroundColor = ConfigurationManager._widgetBackgroundColor.Value; + GUI.backgroundColor = BepInExPlugin._widgetBackgroundColor.Value; var boolVal = (bool)setting.Get(); - var result = GUILayout.Toggle(boolVal, boolVal ? "Enabled" : "Disabled", ConfigurationManager.toggleStyle, GUILayout.ExpandWidth(true)); + var result = GUILayout.Toggle(boolVal, boolVal ? "Enabled" : "Disabled", BepInExPlugin.toggleStyle, GUILayout.ExpandWidth(true)); if (result != boolVal) setting.Set(result); } @@ -165,7 +167,7 @@ private static void DrawFlagsField(SettingEntryBase setting, IList enumValues, i GUI.changed = false; - var newVal = GUILayout.Toggle((currentValue & value.val) == value.val, value.name, ConfigurationManager.toggleStyle, + var newVal = GUILayout.Toggle((currentValue & value.val) == value.val, value.name, BepInExPlugin.toggleStyle, GUILayout.ExpandWidth(false)); if (GUI.changed) { @@ -192,7 +194,7 @@ private static void DrawComboboxField(SettingEntryBase setting, IList list, floa if (!_comboBoxCache.TryGetValue(setting, out var box)) { - box = new ComboBox(dispRect, buttonText, list.Cast().Select(ObjectToGuiContent).ToArray(), ConfigurationManager.boxStyle, windowYmax); + box = new ComboBox(dispRect, buttonText, list.Cast().Select(ObjectToGuiContent).ToArray(), BepInExPlugin.boxStyle, windowYmax); _comboBoxCache[setting] = box; } else @@ -229,7 +231,7 @@ private static void DrawRangeField(SettingEntryBase setting) var leftValue = (float)Convert.ToDouble(setting.AcceptableValueRange.Key, CultureInfo.InvariantCulture); var rightValue = (float)Convert.ToDouble(setting.AcceptableValueRange.Value, CultureInfo.InvariantCulture); - var result = GUILayout.HorizontalSlider(converted, leftValue, rightValue, ConfigurationManager.sliderStyle, ConfigurationManager.thumbStyle, GUILayout.ExpandWidth(true)); + var result = GUILayout.HorizontalSlider(converted, leftValue, rightValue, BepInExPlugin.sliderStyle, BepInExPlugin.thumbStyle, GUILayout.ExpandWidth(true)); if (Math.Abs(result - converted) > Mathf.Abs(rightValue - leftValue) / 1000) { var newValue = Convert.ChangeType(result, setting.SettingType, CultureInfo.InvariantCulture); @@ -268,7 +270,7 @@ private void DrawUnknownField(SettingEntryBase setting, int rightColumnWidth) if (setting.ObjToStr != null && setting.StrToObj != null) { var text = setting.ObjToStr(setting.Get()).AppendZeroIfFloat(setting.SettingType); - var result = GUILayout.TextField(text, ConfigurationManager.buttonStyle, GUILayout.MaxWidth(rightColumnWidth)); + var result = GUILayout.TextField(text, BepInExPlugin.textStyle, GUILayout.MaxWidth(rightColumnWidth)); if (result != text) setting.Set(setting.StrToObj(result)); } @@ -279,13 +281,13 @@ private void DrawUnknownField(SettingEntryBase setting, int rightColumnWidth) var value = rawValue == null ? "NULL" : rawValue.ToString().AppendZeroIfFloat(setting.SettingType); if (CanCovert(value, setting.SettingType)) { - var result = GUILayout.TextField(value, ConfigurationManager.buttonStyle, GUILayout.MaxWidth(rightColumnWidth)); + var result = GUILayout.TextField(value, BepInExPlugin.textStyle, GUILayout.MaxWidth(rightColumnWidth)); if (result != value) setting.Set(Convert.ChangeType(result, setting.SettingType, CultureInfo.InvariantCulture)); } else { - GUILayout.TextArea(value, ConfigurationManager.buttonStyle, GUILayout.MaxWidth(rightColumnWidth)); + GUILayout.TextArea(value, BepInExPlugin.textStyle, GUILayout.MaxWidth(rightColumnWidth)); } } @@ -314,12 +316,14 @@ private bool CanCovert(string value, Type type) private static void DrawKeyboardShortcut(SettingEntryBase setting) { -#pragma warning disable 618 // Disable obsolete warning var value = setting.Get(); + if (value.GetType() == typeof(KeyCode)){ + value = new KeyboardShortcut((KeyCode)value); + } if (_currentKeyboardShortcutToSet == setting) { - GUILayout.Label("Press any key combination", ConfigurationManager.labelStyle, GUILayout.ExpandWidth(true)); + GUILayout.Label("Press any key combination", BepInExPlugin.labelStyle, GUILayout.ExpandWidth(true)); GUIUtility.keyboardControl = -1; foreach (var key in _keysToCheck) @@ -332,7 +336,7 @@ private static void DrawKeyboardShortcut(SettingEntryBase setting) } } - if (GUILayout.Button("Cancel", ConfigurationManager.buttonStyle, GUILayout.ExpandWidth(false))) + if (GUILayout.Button("Cancel", BepInExPlugin.buttonStyle, GUILayout.ExpandWidth(false))) _currentKeyboardShortcutToSet = null; } else @@ -340,13 +344,12 @@ private static void DrawKeyboardShortcut(SettingEntryBase setting) if (GUILayout.Button(value.ToString(), GUILayout.ExpandWidth(true))) _currentKeyboardShortcutToSet = setting; - if (GUILayout.Button("Clear", ConfigurationManager.buttonStyle, GUILayout.ExpandWidth(false))) + if (GUILayout.Button("Clear", BepInExPlugin.buttonStyle, GUILayout.ExpandWidth(false))) { setting.Set(BepInEx.Configuration.KeyboardShortcut.Empty); _currentKeyboardShortcutToSet = null; } } -#pragma warning restore 618 } private static void DrawVector2(SettingEntryBase obj) @@ -392,7 +395,7 @@ private static void DrawQuaternion(SettingEntryBase obj) private static float DrawSingleVectorSlider(float setting, string label) { - GUILayout.Label(label, ConfigurationManager.labelStyle, GUILayout.ExpandWidth(false)); + GUILayout.Label(label, BepInExPlugin.labelStyle, GUILayout.ExpandWidth(false)); float.TryParse(GUILayout.TextField(setting.ToString("F", CultureInfo.InvariantCulture), GUILayout.ExpandWidth(true)), NumberStyles.Any, CultureInfo.InvariantCulture, out var x); return x; } @@ -408,13 +411,13 @@ private static void DrawColor(SettingEntryBase obj) _colorCache[obj] = cacheEntry; } - GUILayout.Label("R", ConfigurationManager.labelStyle, GUILayout.ExpandWidth(false)); + GUILayout.Label("R", BepInExPlugin.labelStyle, GUILayout.ExpandWidth(false)); setting.r = GUILayout.HorizontalSlider(setting.r, 0f, 1f, GUILayout.ExpandWidth(true)); - GUILayout.Label("G", ConfigurationManager.labelStyle, GUILayout.ExpandWidth(false)); + GUILayout.Label("G", BepInExPlugin.labelStyle, GUILayout.ExpandWidth(false)); setting.g = GUILayout.HorizontalSlider(setting.g, 0f, 1f, GUILayout.ExpandWidth(true)); - GUILayout.Label("B", ConfigurationManager.labelStyle, GUILayout.ExpandWidth(false)); + GUILayout.Label("B", BepInExPlugin.labelStyle, GUILayout.ExpandWidth(false)); setting.b = GUILayout.HorizontalSlider(setting.b, 0f, 1f, GUILayout.ExpandWidth(true)); - GUILayout.Label("A", ConfigurationManager.labelStyle, GUILayout.ExpandWidth(false)); + GUILayout.Label("A", BepInExPlugin.labelStyle, GUILayout.ExpandWidth(false)); setting.a = GUILayout.HorizontalSlider(setting.a, 0f, 1f, GUILayout.ExpandWidth(true)); GUILayout.Space(4); @@ -426,7 +429,7 @@ private static void DrawColor(SettingEntryBase obj) cacheEntry.Last = setting; } - GUILayout.Label(cacheEntry.Tex, ConfigurationManager.labelStyle, GUILayout.ExpandWidth(false)); + GUILayout.Label(cacheEntry.Tex, BepInExPlugin.labelStyle, GUILayout.ExpandWidth(false)); } private sealed class ColorCacheEntry diff --git a/ConfigurationManager/SettingSearcher.cs b/ConfigurationManager/SettingSearcher.cs index 8d45db3..49c1e21 100644 --- a/ConfigurationManager/SettingSearcher.cs +++ b/ConfigurationManager/SettingSearcher.cs @@ -33,11 +33,16 @@ public static void CollectSettings(out IEnumerable results, ou catch (Exception ex) { results = Enumerable.Empty(); - ConfigurationManager.Logger.LogError(ex); + BepInExPlugin.Logger.LogError(ex); } foreach (var plugin in Utils.FindPlugins()) { + if (plugin.Info.Metadata.GUID == "com.bepis.bepinex.configurationmanager" || plugin.enabled == false) + { + BepInExPlugin.Dbgl($"plugin: {plugin.Info.Metadata.Name} enabled {plugin.enabled}"); + } + var type = plugin.GetType(); var pluginInfo = plugin.Info.Metadata; diff --git a/ConfigurationManager/Utilities/ComboBox.cs b/ConfigurationManager/Utilities/ComboBox.cs index 8acdf70..1f01ad4 100644 --- a/ConfigurationManager/Utilities/ComboBox.cs +++ b/ConfigurationManager/Utilities/ComboBox.cs @@ -112,7 +112,7 @@ public void Show(Action onItemSelected) var outerRectLocal = new Rect(scrpos.x, scrpos.y, outerRectScreen.width, outerRectScreen.height); GUI.Box(outerRectLocal, GUIContent.none, - new GUIStyle { normal = new GUIStyleState { background = ConfigurationManager.WindowBackground } }); + new GUIStyle { normal = new GUIStyleState { background = BepInExPlugin.WindowBackground } }); _scrollPosition = GUI.BeginScrollView(outerRectLocal, _scrollPosition, innerRect, false, false); { diff --git a/CustomAudio/BepInExPlugin.cs b/CustomAudio/BepInExPlugin.cs index e8e7c22..68db555 100644 --- a/CustomAudio/BepInExPlugin.cs +++ b/CustomAudio/BepInExPlugin.cs @@ -11,7 +11,7 @@ namespace CustomAudio { - [BepInPlugin("aedenthorn.CustomAudio", "Custom Audio", "0.8.0")] + [BepInPlugin("aedenthorn.CustomAudio", "Custom Audio", "0.9.0")] public class BepInExPlugin: BaseUnityPlugin { public static ConfigEntry isDebug; @@ -382,6 +382,38 @@ static void Prefix(ref float ___m_queuedAmbientVol, ref float ___m_ambientVol, r } } + [HarmonyPatch(typeof(Fireplace), "Start")] + static class Fireplace_Start_Patch + { + static void Postfix(Fireplace __instance) + { + if (__instance.name.Contains("groundtorch") && customSFX.ContainsKey("groundtorch")) + { + Dbgl("Replacing ground torch audio"); + __instance.m_enabledObjectHigh.GetComponentInChildren().clip = customSFX["groundtorch"]; + } + else if(__instance.name.Contains("walltorch") && customSFX.ContainsKey("walltorch")) + { + Dbgl("Replacing walltorch audio"); + __instance.m_enabledObjectHigh.GetComponentInChildren().clip = customSFX["walltorch"]; + } + else if (__instance.name.Contains("fire_pit") && customSFX.ContainsKey("fire_pit")) + { + Dbgl("Replacing fire_pit audio"); + __instance.m_enabledObjectHigh.GetComponentInChildren().clip = customSFX["fire_pit"]; + } + else if (__instance.name.Contains("bonfire") && customSFX.ContainsKey("bonfire")) + { + Dbgl("Replacing bonfire audio"); + __instance.m_enabledObjectHigh.GetComponentInChildren().clip = customSFX["bonfire"]; + } + else if (__instance.name.Contains("hearth") && customSFX.ContainsKey("hearth")) + { + Dbgl("Replacing hearth audio"); + __instance.m_enabledObjectHigh.GetComponentInChildren().clip = customSFX["hearth"]; + } + } + } [HarmonyPatch(typeof(Console), "InputText")] static class InputText_Patch diff --git a/CustomAudio/CustomAudio.csproj b/CustomAudio/CustomAudio.csproj index 7f0eb6e..c9aee03 100644 --- a/CustomAudio/CustomAudio.csproj +++ b/CustomAudio/CustomAudio.csproj @@ -115,7 +115,6 @@ - - + call $(SolutionDir)copyDll.bat $(ProjectName) \ No newline at end of file diff --git a/CustomTextures/BepInExPlugin.cs b/CustomTextures/BepInExPlugin.cs index 1d61d86..2a57aad 100644 --- a/CustomTextures/BepInExPlugin.cs +++ b/CustomTextures/BepInExPlugin.cs @@ -11,7 +11,7 @@ namespace CustomTextures { - [BepInPlugin("aedenthorn.CustomTextures", "Custom Textures", "2.0.1")] + [BepInPlugin("aedenthorn.CustomTextures", "Custom Textures", "2.0.3")] public partial class BepInExPlugin: BaseUnityPlugin { public static ConfigEntry modEnabled; diff --git a/CustomTextures/CustomTextures.csproj b/CustomTextures/CustomTextures.csproj index bf187ab..1ec11b4 100644 --- a/CustomTextures/CustomTextures.csproj +++ b/CustomTextures/CustomTextures.csproj @@ -90,7 +90,7 @@ - + diff --git a/CustomTextures/Replacement.cs b/CustomTextures/DoReplacement.cs similarity index 98% rename from CustomTextures/Replacement.cs rename to CustomTextures/DoReplacement.cs index 70a2e8d..59c17c6 100644 --- a/CustomTextures/Replacement.cs +++ b/CustomTextures/DoReplacement.cs @@ -233,16 +233,18 @@ private static void CheckSetMatTextures(string goName, Material m, string prefix Texture vanilla = m.GetTexture(propHash); Texture2D result = null; + + bool isBump = property.Contains("Bump") || property.Contains("Normal"); + + if (ShouldLoadCustomTexture(str + property)) - result = LoadTexture(str+property, vanilla); + result = LoadTexture(str+property, vanilla, isBump); else if (property == "_MainTex" && ShouldLoadCustomTexture(str + "_texture")) - result = LoadTexture(str + "_texture", vanilla); + result = LoadTexture(str + "_texture", vanilla, isBump); else if (property == "_BumpMap" && ShouldLoadCustomTexture(str + "_bump")) - result = LoadTexture(str + "_bump", vanilla); + result = LoadTexture(str + "_bump", vanilla, isBump); else if (property == "_StyleTex" && ShouldLoadCustomTexture(str + "_style")) - result = LoadTexture(str + "_style", vanilla); - - + result = LoadTexture(str + "_style", vanilla, isBump); if (result == null) continue; @@ -250,7 +252,7 @@ private static void CheckSetMatTextures(string goName, Material m, string prefix result.name = name; m.SetTexture(propHash, result); - if (result != null) + if (result != null && property == "_MainTex") m.SetColor(propHash, Color.white); break; } @@ -276,7 +278,7 @@ private static string[] MakePrefixStrings(string prefix, string thingName, strin } - private static Texture2D LoadTexture(string id, Texture vanilla, bool point = true, bool needCustom = false, bool isSprite = false) + private static Texture2D LoadTexture(string id, Texture vanilla, bool isBump, bool point = true, bool needCustom = false, bool isSprite = false) { if (cachedTextures.ContainsKey(id)) { @@ -284,8 +286,6 @@ private static Texture2D LoadTexture(string id, Texture vanilla, bool point = tr return cachedTextures[id]; } - bool isBump = id.EndsWith("_bump") || id.EndsWith("BumpMap"); - Texture2D tex; var layers = customTextures.Where(p => p.Key.StartsWith(id+"_")); diff --git a/CustomTextures/Patches.cs b/CustomTextures/Patches.cs index 267cc82..8fe046e 100644 --- a/CustomTextures/Patches.cs +++ b/CustomTextures/Patches.cs @@ -44,12 +44,6 @@ static void Postfix(ZNetScene __instance, Dictionary ___m_named ReplaceEnvironmentTextures(); - if (dumpSceneTextures.Value) - { - string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CustomTextures", "scene_dump.txt"); - Dbgl($"Writing {path}"); - File.WriteAllLines(path, outputDump); - } //LogStopwatch("ZNetScene 2"); } } @@ -60,7 +54,6 @@ static class ZoneSystem_Awake_Patch static void Prefix(ZoneSystem __instance) { ReplaceZoneSystemTextures(__instance); - } } @@ -84,6 +77,13 @@ static void Postfix(ClutterSystem __instance) if (logDump.Any()) Dbgl("\n" + string.Join("\n", logDump)); + if (ZNetScene.instance && dumpSceneTextures.Value) + { + string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CustomTextures", "scene_dump.txt"); + Dbgl($"Writing {path}"); + File.WriteAllLines(path, outputDump); + } + //LogStopwatch("Clutter System"); } @@ -101,16 +101,16 @@ static void Postfix(VisEquipment __instance) if (ShouldLoadCustomTexture($"player_model_{i}{property}")) { - __instance.m_models[i].m_baseMaterial.SetTexture(property, LoadTexture($"player_model_{i}{property}", __instance.m_models[i].m_baseMaterial.GetTexture(property))); + __instance.m_models[i].m_baseMaterial.SetTexture(property, LoadTexture($"player_model_{i}{property}", __instance.m_models[i].m_baseMaterial.GetTexture(property), false)); Dbgl($"set player_model_{i}_texture custom texture."); } else if (property == "_MainTex" && ShouldLoadCustomTexture($"player_model_{i}_texture")) // legacy { - __instance.m_models[i].m_baseMaterial.SetTexture(property, LoadTexture($"player_model_{i}_texture", __instance.m_models[i].m_baseMaterial.GetTexture(property))); + __instance.m_models[i].m_baseMaterial.SetTexture(property, LoadTexture($"player_model_{i}_texture", __instance.m_models[i].m_baseMaterial.GetTexture(property), false)); } else if (property == "_SkinBumpMap" && ShouldLoadCustomTexture($"player_model_{i}_bump")) // legacy { - __instance.m_models[i].m_baseMaterial.SetTexture(property, LoadTexture($"player_model_{i}_bump", __instance.m_models[i].m_baseMaterial.GetTexture(property))); + __instance.m_models[i].m_baseMaterial.SetTexture(property, LoadTexture($"player_model_{i}_bump", __instance.m_models[i].m_baseMaterial.GetTexture(property), true)); } } } diff --git a/CustomUI/CustomUI.csproj b/CustomUI/CustomUI.csproj index 3ab5561..e5ab15c 100644 --- a/CustomUI/CustomUI.csproj +++ b/CustomUI/CustomUI.csproj @@ -81,12 +81,20 @@ ..\valheim_Data\Managed\UnityEngine.PhysicsModule.dll + + False + ..\valheim_Data\Managed\UnityEngine.TextCoreModule.dll + ..\valheim_Data\Managed\UnityEngine.TextRenderingModule.dll ..\valheim_Data\Managed\UnityEngine.UI.dll + + False + ..\valheim_Data\Managed\UnityEngine.UIElementsModule.dll + ..\valheim_Data\Managed\UnityEngine.UIModule.dll diff --git a/MonsterAITweaks/BepInExPlugin.cs b/MonsterAITweaks/BepInExPlugin.cs new file mode 100644 index 0000000..3dcb520 --- /dev/null +++ b/MonsterAITweaks/BepInExPlugin.cs @@ -0,0 +1,241 @@ +using BepInEx; +using BepInEx.Configuration; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace MonsterAITweaks +{ + [BepInPlugin("aedenthorn.MonsterAITweaks", "Monster AI Tweaks", "0.2.1")] + public class BepInExPlugin: BaseUnityPlugin + { + private static readonly bool isDebug = true; + private static BepInExPlugin context; + private Harmony harmony; + + public static ConfigEntry modEnabled; + public static ConfigEntry nexusID; + + public static ConfigEntry noMonstersTargetPlayers; + public static ConfigEntry noMonstersAlerted; + public static ConfigEntry allMonstersTame; + public static ConfigEntry noBuildingTargeting; + public static ConfigEntry allMonstersFearFire; + public static ConfigEntry allMonstersAvoidFire; + + public static ConfigEntry neverTargetPlayersListString; + public static ConfigEntry neverAlertedListString; + public static ConfigEntry defaultTamedListString; + public static ConfigEntry noBuildingTargetListString; + public static ConfigEntry fearFireListString; + public static ConfigEntry avoidFireListString; + + public static ConfigEntry viewRangeMult; + public static ConfigEntry viewAngleMult; + public static ConfigEntry hearRangeMult; + + private static string[] neverTargetPlayersList; + private static string[] neverAlertedList; + private static string[] defaultTamedList; + private static string[] noBuildingTargetList; + private static string[] fearFireList; + private static string[] avoidFireList; + + public static void Dbgl(string str = "", bool pref = true) + { + if (isDebug) + Debug.Log((pref ? typeof(BepInExPlugin).Namespace + " " : "") + str); + } + private void Awake() + { + context = this; + + modEnabled = Config.Bind("General", "Enabled", true, "Enable this mod"); + //nexusID = Config.Bind("General", "NexusID", , "Nexus mod ID for updates"); + + noMonstersTargetPlayers = Config.Bind("Global", "NoMonstersTargetPlayers", false, "No monsters target players."); + noMonstersAlerted = Config.Bind("Global", "NoMonstersAlerted", false, "No monsters become alerted."); + allMonstersTame = Config.Bind("Global", "NoMonstersAlerted", false, "All monsters tamed by default."); + noBuildingTargeting = Config.Bind("Global", "NoBuildingTargeting", false, "No monsters target buildings."); + allMonstersFearFire = Config.Bind("Global", "AllMonstersFearFire", false, "All monsters fear fire."); + allMonstersAvoidFire = Config.Bind("Global", "AllMonstersAvoidFire", false, "All monsters avoid fire."); + + neverTargetPlayersListString = Config.Bind("Lists", "NeverTargetPlayersList", "", "List of monsters that will never target players (comma-separated)."); + neverAlertedListString = Config.Bind("Lists", "NeverAlertedList", "", "List of monsters that will never be alerted (comma-separated)."); + defaultTamedListString = Config.Bind("Lists", "DefaultTamedList", "", "List of monsters that are tamed by default (comma-separated)."); + noBuildingTargetListString = Config.Bind("Lists", "NoBuildingTargetList", "", "List of monsters that do not target buildings (comma-separated)."); + fearFireListString = Config.Bind("Lists", "FearFireListString", "", "List of monsters that fear fire (comma-separated)."); + avoidFireListString = Config.Bind("Lists", "AvoidFireListString", "", "List of monsters that avoid fire (comma-separated)."); + + viewRangeMult = Config.Bind("Variables", "ViewRangeMult", 1f, "Monster view range multiplier."); + viewAngleMult = Config.Bind("Variables", "ViewAngleMult", 1f, "Monster view angle multiplier."); + hearRangeMult = Config.Bind("Variables", "HearRangeMult", 1f, "Monster hear range multiplier."); + + if (!modEnabled.Value) + return; + + neverTargetPlayersList = neverTargetPlayersListString.Value.Split(','); + neverAlertedList = neverAlertedListString.Value.Split(','); + defaultTamedList = defaultTamedListString.Value.Split(','); + noBuildingTargetList = noBuildingTargetListString.Value.Split(','); + fearFireList = fearFireListString.Value.Split(','); + avoidFireList = avoidFireListString.Value.Split(','); + + harmony = new Harmony(Info.Metadata.GUID); + harmony.PatchAll(); + } + + [HarmonyPatch(typeof(MonsterAI), "Awake")] + static class MonsterAI_Awake_Patch + { + static void Postfix(MonsterAI __instance) + { + if (!modEnabled.Value) + return; + + if (allMonstersTame.Value || defaultTamedList.Contains(ZNetView.GetPrefabName(__instance.gameObject))) + __instance.MakeTame(); + if (allMonstersAvoidFire.Value || avoidFireList.Contains(ZNetView.GetPrefabName(__instance.gameObject))) + __instance.m_avoidFire = true; + if (allMonstersFearFire.Value || fearFireList.Contains(ZNetView.GetPrefabName(__instance.gameObject))) + __instance.m_afraidOfFire = true; + + } + } + + [HarmonyPatch(typeof(BaseAI), "Awake")] + static class BaseAI_Awake_Patch + { + static void Postfix(BaseAI __instance) + { + if (!modEnabled.Value) + return; + + + __instance.m_viewRange *= viewRangeMult.Value; + __instance.m_viewAngle *= viewAngleMult.Value; + + } + } + + [HarmonyPatch(typeof(MonsterAI), "SetTarget", new Type[] { typeof(Character) })] + static class MonsterAI_SetTarget_Patch + { + static bool Prefix(MonsterAI __instance, Character attacker) + { + if (!modEnabled.Value) + return true; + + //Dbgl($"{__instance.name} setting target player {attacker.IsPlayer()} cancel {noMonstersTargetPlayers.Value}"); + + if (attacker?.IsPlayer() == true && (noMonstersTargetPlayers.Value || neverTargetPlayersList.Contains(ZNetView.GetPrefabName(__instance.gameObject)))) + return false; + return true; + } + } + + [HarmonyPatch(typeof(BaseAI), "FindEnemy")] + static class BaseAI_FindEnemy_Patch + { + static void Postfix(BaseAI __instance, ref Character __result) + { + if (!modEnabled.Value) + return; + + //Dbgl($"{__instance.name} finding target player {__result?.IsPlayer()} cancel {noMonstersTargetPlayers.Value}"); + + if (__result?.IsPlayer() == true && (noMonstersTargetPlayers.Value || neverTargetPlayersList.Contains(ZNetView.GetPrefabName(__instance.gameObject)))) + { + __result = null; + } + } + } + + [HarmonyPatch(typeof(BaseAI), "Alert")] + static class BaseAI_Alert_Patch + { + static bool Prefix(BaseAI __instance) + { + if (!modEnabled.Value) + return true; + + if (noMonstersAlerted.Value || neverAlertedList.Contains(ZNetView.GetPrefabName(__instance.gameObject))) + { + return false; + } + return true; + } + } + [HarmonyPatch(typeof(BaseAI), "FindClosestStaticPriorityTarget")] + static class BaseAI_FindClosestStaticPriorityTarget_Patch + { + static bool Prefix(BaseAI __instance, ref StaticTarget __result) + { + if (!modEnabled.Value) + return true; + + if (noBuildingTargeting.Value || noBuildingTargetList.Contains(ZNetView.GetPrefabName(__instance.gameObject))) + { + __result = null; + return false; + } + return true; + } + } + [HarmonyPatch(typeof(BaseAI), "FindRandomStaticTarget")] + static class BaseAI_FindRandomStaticTarget_Patch + { + static bool Prefix(BaseAI __instance, ref StaticTarget __result) + { + if (!modEnabled.Value) + return true; + + if (noBuildingTargeting.Value || noBuildingTargetList.Contains(ZNetView.GetPrefabName(__instance.gameObject))) + { + __result = null; + return false; + } + return true; + } + } + + [HarmonyPatch(typeof(MonsterAI), "SetAlerted")] + static class MonsterAI_SetAlerted_Patch + { + static bool Prefix(MonsterAI __instance, bool alert) + { + if (!modEnabled.Value || !alert) + return true; + + if (noMonstersAlerted.Value || neverAlertedList.Contains(ZNetView.GetPrefabName(__instance.gameObject))) + { + return false; + } + return true; + } + } + + [HarmonyPatch(typeof(Console), "InputText")] + static class InputText_Patch + { + static bool Prefix(Console __instance) + { + if (!modEnabled.Value) + return true; + string text = __instance.m_input.text; + if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} reset")) + { + context.Config.Reload(); + context.Config.Save(); + Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue(); + Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} config reloaded" }).GetValue(); + return false; + } + return true; + } + } + } +} diff --git a/MonsterAITweaks/Class1.cs b/MonsterAITweaks/Class1.cs deleted file mode 100644 index d0d3e0f..0000000 --- a/MonsterAITweaks/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonsterAITweaks -{ - public class Class1 - { - } -} diff --git a/MonsterAITweaks/MonsterAITweaks.csproj b/MonsterAITweaks/MonsterAITweaks.csproj index 20ee32e..eba002f 100644 --- a/MonsterAITweaks/MonsterAITweaks.csproj +++ b/MonsterAITweaks/MonsterAITweaks.csproj @@ -1,10 +1,10 @@ - + Debug AnyCPU - 110352b6-6b4a-4172-898f-84018761af2e + {110352B6-6B4A-4172-898F-84018761AF2E} Library Properties MonsterAITweaks @@ -31,24 +31,69 @@ 4 - - - - - - - - - - - - - - + + ..\BepInEx\0Harmony20.dll + + + ..\valheim_Data\Managed\assembly_guiutils.dll + + + ..\valheim_Data\Managed\assembly_valheim.dll + + + ..\BepInEx\BepInEx.dll + + + + + + + + + + + ..\valheim_Data\Managed\UnityEngine.dll + + + ..\valheim_Data\Managed\UnityEngine.AudioModule.dll + + + ..\valheim_Data\Managed\UnityEngine.CoreModule.dll + + + ..\valheim_Data\Managed\UnityEngine.ImageConversionModule.dll + + + ..\valheim_Data\Managed\UnityEngine.IMGUIModule.dll + + + ..\valheim_Data\Managed\UnityEngine.InputLegacyModule.dll + + + ..\valheim_Data\Managed\UnityEngine.InputModule.dll + + + ..\valheim_Data\Managed\UnityEngine.TextCoreModule.dll + + + ..\valheim_Data\Managed\UnityEngine.TextRenderingModule.dll + + + ..\valheim_Data\Managed\UnityEngine.UI.dll + + + ..\valheim_Data\Managed\UnityEngine.UIElementsModule.dll + + + ..\valheim_Data\Managed\UnityEngine.UIModule.dll + - + - + + call $(SolutionDir)copyDll.bat $(ProjectName) + + \ No newline at end of file diff --git a/TorchMod/TorchMod.cs b/TorchMod/TorchMod.cs index 8fcc045..f90239a 100644 --- a/TorchMod/TorchMod.cs +++ b/TorchMod/TorchMod.cs @@ -6,12 +6,12 @@ namespace TorchMod { - [BepInPlugin("aedenthorn.TorchMod", "Torch Light Mod", "0.5.3")] + [BepInPlugin("aedenthorn.TorchMod", "Torch Light Mod", "0.6.0")] - public class TorchMod: BaseUnityPlugin + public class BepInExPlugin : BaseUnityPlugin { private static readonly bool isDebug = true; - private static TorchMod context; + private static BepInExPlugin context; public static ConfigEntry modEnabled; public static ConfigEntry nexusID; @@ -62,10 +62,42 @@ public class TorchMod: BaseUnityPlugin public static ConfigEntry firePitShadowStrengthHigh; public static ConfigEntry firePitUseColorTemperatureHigh; public static ConfigEntry firePitColorTemperatureHigh; + + public static ConfigEntry bonfireColorLow; + public static ConfigEntry bonfireRangeLow; + public static ConfigEntry bonfireIntensityLow; + public static ConfigEntry bonfireBounceIntensityLow; + public static ConfigEntry bonfireShadowStrengthLow; + public static ConfigEntry bonfireUseColorTemperatureLow; + public static ConfigEntry bonfireColorTemperatureLow; + + public static ConfigEntry bonfireColorHigh; + public static ConfigEntry bonfireRangeHigh; + public static ConfigEntry bonfireIntensityHigh; + public static ConfigEntry bonfireBounceIntensityHigh; + public static ConfigEntry bonfireShadowStrengthHigh; + public static ConfigEntry bonfireUseColorTemperatureHigh; + public static ConfigEntry bonfireColorTemperatureHigh; + + public static ConfigEntry hearthColorLow; + public static ConfigEntry hearthRangeLow; + public static ConfigEntry hearthIntensityLow; + public static ConfigEntry hearthBounceIntensityLow; + public static ConfigEntry hearthShadowStrengthLow; + public static ConfigEntry hearthUseColorTemperatureLow; + public static ConfigEntry hearthColorTemperatureLow; + + public static ConfigEntry hearthColorHigh; + public static ConfigEntry hearthRangeHigh; + public static ConfigEntry hearthIntensityHigh; + public static ConfigEntry hearthBounceIntensityHigh; + public static ConfigEntry hearthShadowStrengthHigh; + public static ConfigEntry hearthUseColorTemperatureHigh; + public static ConfigEntry hearthColorTemperatureHigh; public static void Dbgl(string str = "", bool pref = true) { if (isDebug) - Debug.Log((pref ? typeof(TorchMod).Namespace + " " : "") + str); + Debug.Log((pref ? typeof(BepInExPlugin ).Namespace + " " : "") + str); } private void Awake() { @@ -122,6 +154,38 @@ private void Awake() firePitUseColorTemperatureHigh = Config.Bind("Fire Pits", "FirePitUseColorTemperatureHigh", false, "Set to true to use the color temperature."); firePitColorTemperatureHigh = Config.Bind("Fire Pits", "FirePitColorTemperatureHigh", 6570f, "The color temperature of the light. (float)"); + bonfireColorLow = Config.Bind("Bonfires", "BonfireColorLow", new Color(0.838f, 0.504f, 0.324f, 1f), "The color of the light."); + bonfireRangeLow = Config.Bind("Bonfires", "BonfireRangeLow", 20f, "The range of the light. (float)"); + bonfireIntensityLow = Config.Bind("Bonfires", "BonfireIntensityLow", 1.75f, "The Intensity of a light is multiplied with the Light color. (float 0-8)"); + bonfireBounceIntensityLow = Config.Bind("Bonfires", "BonfireBounceIntensityLow", 1f, "The multiplier that defines the strength of the bounce lighting. (float 0+)"); + bonfireShadowStrengthLow = Config.Bind("Bonfires", "BonfireShadowStrengthLow", 1f, "Strength of light's shadows. (float)"); + bonfireUseColorTemperatureLow = Config.Bind("Bonfires", "BonfireUseColorTemperatureLow", false, "Set to true to use the color temperature."); + bonfireColorTemperatureLow = Config.Bind("Bonfires", "BonfireColorTemperatureLow", 6570f, "The color temperature of the light. (float)"); + + bonfireColorHigh = Config.Bind("Bonfires", "BonfireColorHigh", new Color(1f, 0.504f, 0.324f, 1f), "The color of the light."); + bonfireRangeHigh = Config.Bind("Bonfires", "BonfireRangeHigh", 20f, "The range of the light. (float)"); + bonfireIntensityHigh = Config.Bind("Bonfires", "BonfireIntensityHigh", 1.894302f, "The Intensity of a light is multiplied with the Light color. (float 0-8)"); + bonfireBounceIntensityHigh = Config.Bind("Bonfires", "BonfireBounceIntensityHigh", 1f, "The multiplier that defines the strength of the bounce lighting. (float 0+)"); + bonfireShadowStrengthHigh = Config.Bind("Bonfires", "BonfireShadowStrengthHigh", 1f, "Strength of light's shadows. (float)"); + bonfireUseColorTemperatureHigh = Config.Bind("Bonfires", "BonfireUseColorTemperatureHigh", false, "Set to true to use the color temperature."); + bonfireColorTemperatureHigh = Config.Bind("Bonfires", "BonfireColorTemperatureHigh", 6570f, "The color temperature of the light. (float)"); + + hearthColorLow = Config.Bind("Hearths", "HearthColorLow", new Color(0.838f, 0.527f, 0.413f, 1f), "The color of the light."); + hearthRangeLow = Config.Bind("Hearths", "HearthRangeLow", 3f, "The range of the light. (float)"); + hearthIntensityLow = Config.Bind("Hearths", "HearthIntensityLow", 1.5f, "The Intensity of a light is multiplied with the Light color. (float 0-8)"); + hearthBounceIntensityLow = Config.Bind("Hearths", "HearthBounceIntensityLow", 1f, "The multiplier that defines the strength of the bounce lighting. (float 0+)"); + hearthShadowStrengthLow = Config.Bind("Hearths", "HearthShadowStrengthLow", 1f, "Strength of light's shadows. (float)"); + hearthUseColorTemperatureLow = Config.Bind("Hearths", "HearthUseColorTemperatureLow", false, "Set to true to use the color temperature."); + hearthColorTemperatureLow = Config.Bind("Hearths", "HearthColorTemperatureLow", 6570f, "The color temperature of the light. (float)"); + + hearthColorHigh = Config.Bind("Hearths", "HearthColorHigh", new Color(1f, 0.621f, 0.482f, 1f), "The color of the light."); + hearthRangeHigh = Config.Bind("Hearths", "HearthRangeHigh", 13f, "The range of the light. (float)"); + hearthIntensityHigh = Config.Bind("Hearths", "HearthIntensityHigh", 2.145109f, "The Intensity of a light is multiplied with the Light color. (float 0-8)"); + hearthBounceIntensityHigh = Config.Bind("Hearths", "HearthBounceIntensityHigh", 1f, "The multiplier that defines the strength of the bounce lighting. (float 0+)"); + hearthShadowStrengthHigh = Config.Bind("Hearths", "HearthShadowStrengthHigh", 1f, "Strength of light's shadows. (float)"); + hearthUseColorTemperatureHigh = Config.Bind("Hearths", "HearthUseColorTemperatureHigh", false, "Set to true to use the color temperature."); + hearthColorTemperatureHigh = Config.Bind("Hearths", "HearthColorTemperatureHigh", 6570f, "The color temperature of the light. (float)"); + if (!modEnabled.Value) return; @@ -266,8 +330,6 @@ static void Postfix(Fireplace __instance) LightFlicker lf2 = __instance.m_enabledObjectHigh.GetComponentInChildren(); Light light2 = lf2.GetComponent(); - - light2.color = firePitColorHigh.Value; light2.range = firePitRangeHigh.Value; light2.bounceIntensity = firePitBounceIntensityHigh.Value; @@ -276,9 +338,77 @@ static void Postfix(Fireplace __instance) light2.shadowStrength = firePitShadowStrengthHigh.Value; lfi.SetValue(lf2, firePitIntensityHigh.Value); } + else if (name.Contains("bonfire")) + { + LightFlicker lf = __instance.m_enabledObjectLow.GetComponentInChildren(); + Light light = lf.GetComponent(); + + light.color = bonfireColorLow.Value; + light.range = bonfireRangeLow.Value; + light.bounceIntensity = bonfireBounceIntensityLow.Value; + light.useColorTemperature = bonfireUseColorTemperatureLow.Value; + light.colorTemperature = bonfireColorTemperatureLow.Value; + light.shadowStrength = bonfireShadowStrengthLow.Value; + lfi.SetValue(lf, bonfireIntensityLow.Value); + + LightFlicker lf2 = __instance.m_enabledObjectHigh.GetComponentInChildren(); + Light light2 = lf2.GetComponent(); + + light2.color = bonfireColorHigh.Value; + light2.range = bonfireRangeHigh.Value; + light2.bounceIntensity = bonfireBounceIntensityHigh.Value; + light2.useColorTemperature = bonfireUseColorTemperatureHigh.Value; + light2.colorTemperature = bonfireColorTemperatureHigh.Value; + light2.shadowStrength = bonfireShadowStrengthHigh.Value; + lfi.SetValue(lf2, bonfireIntensityHigh.Value); + } + else if (name.Contains("hearth")) + { + LightFlicker lf = __instance.m_enabledObjectLow.GetComponentInChildren(); + Light light = lf.GetComponent(); + + light.color = hearthColorLow.Value; + light.range = hearthRangeLow.Value; + light.bounceIntensity = hearthBounceIntensityLow.Value; + light.useColorTemperature = hearthUseColorTemperatureLow.Value; + light.colorTemperature = hearthColorTemperatureLow.Value; + light.shadowStrength = hearthShadowStrengthLow.Value; + lfi.SetValue(lf, hearthIntensityLow.Value); + + LightFlicker lf2 = __instance.m_enabledObjectHigh.GetComponentInChildren(); + Light light2 = lf2.GetComponent(); + light2.color = hearthColorHigh.Value; + light2.range = hearthRangeHigh.Value; + light2.bounceIntensity = hearthBounceIntensityHigh.Value; + light2.useColorTemperature = hearthUseColorTemperatureHigh.Value; + light2.colorTemperature = hearthColorTemperatureHigh.Value; + light2.shadowStrength = hearthShadowStrengthHigh.Value; + lfi.SetValue(lf2, hearthIntensityHigh.Value); + } } } + + [HarmonyPatch(typeof(Console), "InputText")] + static class InputText_Patch + { + static bool Prefix(Console __instance) + { + if (!modEnabled.Value) + return true; + string text = __instance.m_input.text; + if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} reset")) + { + context.Config.Reload(); + context.Config.Save(); + + Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue(); + Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} config reloaded" }).GetValue(); + return false; + } + return true; + } + } } } diff --git a/TorchMod/TorchMod.csproj b/TorchMod/TorchMod.csproj index 2264bd2..cda8127 100644 --- a/TorchMod/TorchMod.csproj +++ b/TorchMod/TorchMod.csproj @@ -57,6 +57,10 @@ ..\valheim_Data\Managed\UnityEngine.IMGUIModule.dll + + False + ..\valheim_Data\Managed\UnityEngine.UI.dll + ..\valheim_Data\Managed\UnityEngine.UIModule.dll