diff --git a/ConfigurationManager/BepInExPlugin.cs b/ConfigurationManager/BepInExPlugin.cs
index 8fd0591..5204aaf 100644
--- a/ConfigurationManager/BepInExPlugin.cs
+++ b/ConfigurationManager/BepInExPlugin.cs
@@ -17,7 +17,7 @@ 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.
///
- [BepInPlugin(GUID, "Valheim Configuration Manager", "0.4.0")]
+ [BepInPlugin(GUID, "Valheim Configuration Manager", "0.5.0")]
public class BepInExPlugin : BaseUnityPlugin
{
///
diff --git a/ConfigurationManager/SettingSearcher.cs b/ConfigurationManager/SettingSearcher.cs
index 6cc05a9..2eed63e 100644
--- a/ConfigurationManager/SettingSearcher.cs
+++ b/ConfigurationManager/SettingSearcher.cs
@@ -35,8 +35,17 @@ public static void CollectSettings(out IEnumerable results, ou
BepInExPlugin.Logger.LogError(ex);
}
- foreach (var plugin in Utilities.Utils.FindPlugins())
+ var allPlugins = Utilities.Utils.FindPlugins();
+
+ BepInExPlugin.Dbgl($"all plugins: {allPlugins.Length}");
+
+ foreach (var plugin in allPlugins)
{
+ if (plugin == null)
+ continue;
+
+ //BepInExPlugin.Dbgl(plugin.name);
+
if (plugin.Info.Metadata.GUID == "com.bepis.bepinex.configurationmanager" || plugin.enabled == false)
{
BepInExPlugin.Dbgl($"plugin: {plugin.Info.Metadata.Name} enabled {plugin.enabled}");
@@ -49,6 +58,7 @@ public static void CollectSettings(out IEnumerable results, ou
if (type.GetCustomAttributes(typeof(BrowsableAttribute), false).Cast()
.Any(x => !x.Browsable))
{
+ BepInExPlugin.Dbgl($"{pluginInfo.Name} has no settings, skipping.");
modsWithoutSettings.Add(pluginInfo.Name);
continue;
}
@@ -57,10 +67,18 @@ public static void CollectSettings(out IEnumerable results, ou
detected.AddRange(GetPluginConfig(plugin).Cast());
- detected.RemoveAll(x => x.Browsable == false);
+ int count = detected.FindAll(x => x.Browsable == false).Count;
+ if(count > 0)
+ {
+ BepInExPlugin.Dbgl($"{count} settings are not browseable, removing.");
+ detected.RemoveAll(x => x.Browsable == false);
+ }
if (!detected.Any())
+ {
+ BepInExPlugin.Dbgl($"{pluginInfo.Name} has no showable settings, skipping.");
modsWithoutSettings.Add(pluginInfo.Name);
+ }
// Allow to enable/disable plugin if it uses any update methods ------
if (showDebug && type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Any(x => _updateMethodNames.Contains(x.Name)))
@@ -75,6 +93,7 @@ public static void CollectSettings(out IEnumerable results, ou
if (detected.Any())
{
+ //BepInExPlugin.Dbgl($"Adding {pluginInfo.Name} to config manager.");
results = results.Concat(detected);
}
}
diff --git a/ConfigurationManager/Utilities/Utilities.cs b/ConfigurationManager/Utilities/Utilities.cs
index f12cc0e..9eb28e9 100644
--- a/ConfigurationManager/Utilities/Utilities.cs
+++ b/ConfigurationManager/Utilities/Utilities.cs
@@ -59,7 +59,16 @@ public static bool IsSubclassOfRawGeneric(this Type toCheck, Type generic)
}
// Search for objects instead of using chainloader API to find dynamically loaded plugins
- public static BaseUnityPlugin[] FindPlugins() => Object.FindObjectsOfType(typeof(BaseUnityPlugin)).Cast().ToArray();
+ public static BaseUnityPlugin[] FindPlugins()
+ {
+ List plugins = new List();
+ foreach(var plugin in BepInEx.Bootstrap.Chainloader.PluginInfos)
+ {
+ plugins.Add(plugin.Value.Instance);
+ }
+
+ return plugins.ToArray();
+ }
public static bool IsNumber(this object value) => value is sbyte
|| value is byte
diff --git a/ControllerButtonSwitch/BepInExPlugin.cs b/ControllerButtonSwitch/BepInExPlugin.cs
new file mode 100644
index 0000000..92dc772
--- /dev/null
+++ b/ControllerButtonSwitch/BepInExPlugin.cs
@@ -0,0 +1,238 @@
+using BepInEx;
+using BepInEx.Configuration;
+using HarmonyLib;
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace ControllerButtonSwitch
+{
+ [BepInPlugin("aedenthorn.ControllerButtonSwitch", "Controller Button Switch", "0.1.0")]
+ public class BepInExPlugin : BaseUnityPlugin
+ {
+ private static readonly bool isDebug = true;
+ private static BepInExPlugin context;
+ private Harmony harmony;
+
+ public static ConfigEntry modEnabled;
+ public static ConfigEntry gamePadButton;
+ public static ConfigEntry nexusID;
+
+ public static ConfigEntry buttonAttack;
+ public static ConfigEntry buttonSecondAttack;
+ public static ConfigEntry buttonBlock;
+ public static ConfigEntry buttonUse;
+ public static ConfigEntry buttonHide;
+ public static ConfigEntry buttonJump;
+ public static ConfigEntry buttonCrouch;
+ public static ConfigEntry buttonRun;
+ public static ConfigEntry buttonToggleWalk;
+ public static ConfigEntry buttonAutoRun;
+ public static ConfigEntry buttonSit;
+ public static ConfigEntry buttonGPower;
+ public static ConfigEntry buttonAltPlace;
+ public static ConfigEntry buttonForward;
+ public static ConfigEntry buttonLeft;
+ public static ConfigEntry buttonBackward;
+ public static ConfigEntry buttonRight;
+ public static ConfigEntry buttonInventory;
+ public static ConfigEntry buttonMap;
+ public static ConfigEntry buttonMapZoomOut;
+ public static ConfigEntry buttonMapZoomIn;
+ public static ConfigEntry buttonBuildPrev;
+ public static ConfigEntry buttonBuildNext;
+ public static ConfigEntry buttonBuildMenu;
+ public static ConfigEntry buttonRemove;
+ public static ConfigEntry buttonJoyUse;
+ public static ConfigEntry buttonJoyHide;
+ public static ConfigEntry buttonJoyJump;
+ public static ConfigEntry buttonJoySit;
+
+ public static ConfigEntry buttonJoyInventory;
+ public static ConfigEntry buttonJoyRun;
+ public static ConfigEntry buttonJoyCrouch;
+ public static ConfigEntry buttonJoyMap;
+ public static ConfigEntry buttonJoyMenu;
+ public static ConfigEntry buttonJoySecondAttack;
+ public static ConfigEntry buttonJoyAltPlace;
+ public static ConfigEntry buttonJoyRemove;
+ public static ConfigEntry buttonJoyTabLeft;
+ public static ConfigEntry buttonJoyTabRight;
+ public static ConfigEntry buttonJoyButtonA;
+ public static ConfigEntry buttonJoyButtonB;
+ public static ConfigEntry buttonJoyButtonX;
+ public static ConfigEntry buttonJoyButtonY;
+ public static ConfigEntry buttonJoyLStick;
+ public static ConfigEntry buttonJoyRStick;
+
+
+
+ public static ConfigEntry buttonJoyGPower;
+ public static ConfigEntry buttonJoyBlock;
+ public static ConfigEntry buttonJoyAttack;
+ public static ConfigEntry buttonJoyPlace;
+ public static ConfigEntry buttonJoyRotate;
+ public static ConfigEntry buttonJoyLStickLeft;
+ public static ConfigEntry buttonJoyLStickRight;
+ public static ConfigEntry buttonJoyLStickUp;
+ public static ConfigEntry buttonJoyLStickDown;
+ public static ConfigEntry buttonJoyDPadLeft;
+ public static ConfigEntry buttonJoyDPadRight;
+ public static ConfigEntry buttonJoyDPadUp;
+ public static ConfigEntry buttonJoyDPadDown;
+ public static ConfigEntry buttonJoyLTrigger;
+ public static ConfigEntry buttonJoyRTrigger;
+
+ public static ConfigEntry repeatDelaySetting;
+ public static ConfigEntry repeatIntervalSetting;
+
+ 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("Config", "Enabled", true, "Enable this mod");
+ nexusID = Config.Bind("Config", "NexusID", 1105, "Nexus mod ID for updates");
+
+ buttonAttack = Config.Bind("KeysCombat", "Attack", "Mouse0", "Attack button");
+ buttonSecondAttack = Config.Bind("KeysCombat", "SecondAttack", "Mouse2", "SecondAttack button");
+ buttonBlock = Config.Bind("KeysCombat", "Block", "Mouse1", "Block button");
+ buttonUse = Config.Bind("KeysMisc", "Use", "E", "Use button");
+ buttonHide = Config.Bind("KeysMisc", "Hide", "R", "Hide button");
+ buttonJump = Config.Bind("KeysMovement", "Jump", "Space", "Jump button");
+ buttonCrouch = Config.Bind("KeysMovement", "Crouch", "LeftControl", "Crouch button");
+ buttonRun = Config.Bind("KeysMovement", "Run", "LeftShift", "Run button");
+ buttonToggleWalk = Config.Bind("KeysMovement", "ToggleWalk", "C", "ToggleWalk button");
+ buttonAutoRun = Config.Bind("KeysMovement", "AutoRun", "Q", "AutoRun button");
+ buttonSit = Config.Bind("KeysMovement", "Sit", "X", "Sit button");
+ buttonGPower = Config.Bind("KeysMisc", "GPower", "F", "GPower button");
+ buttonAltPlace = Config.Bind("KeysBuild", "AltPlace", "LeftShift", "AltPlace button");
+ buttonForward = Config.Bind("KeysDirection", "Forward", "W,0.3,0.1", "Forward button");
+ buttonLeft = Config.Bind("KeysDirection", "Left", "A,0.3,0.1", "Left button");
+ buttonBackward = Config.Bind("KeysDirection", "Backward", "S,0.3,0.1", "Backward button");
+ buttonRight = Config.Bind("KeysDirection", "Right", "D,0.3,0.1", "Right button");
+ buttonInventory = Config.Bind("KeysMisc", "Inventory", "Tab", "Inventory button");
+ buttonMap = Config.Bind("KeysMap", "Map", "M", "Map button");
+ buttonMapZoomOut = Config.Bind("KeysMap", "MapZoomOut", "Comma", "MapZoomOut button");
+ buttonMapZoomIn = Config.Bind("KeysMap", "MapZoomIn", "Period", "MapZoomIn button");
+ buttonBuildPrev = Config.Bind("KeysBuild", "BuildPrev", "Q", "BuildPrev button");
+ buttonBuildNext = Config.Bind("KeysBuild", "BuildNext", "E", "BuildNext button");
+ buttonBuildMenu = Config.Bind("KeysBuild", "BuildMenu", "Mouse1", "BuildMenu button");
+ buttonRemove = Config.Bind("KeysBuild", "Remove", "Mouse2", "Remove button");
+
+ buttonJoyUse = Config.Bind("JoystickMisc", "JoyUse", "JoystickButton0", "JoyUse button");
+ buttonJoyHide = Config.Bind("JoystickMisc", "JoyHide", "JoystickButton9", "JoyHide button");
+ buttonJoyJump = Config.Bind("JoystickMovement", "JoyJump", "JoystickButton1", "JoyJump button");
+ buttonJoySit = Config.Bind("JoystickMovement", "JoySit", "JoystickButton2", "JoySit button");
+ buttonJoyInventory = Config.Bind("JoystickMisc", "JoyInventory", "JoystickButton3", "JoyInventory button");
+ buttonJoyRun = Config.Bind("JoystickMovement", "JoyRun", "JoystickButton4", "JoyRun button");
+ buttonJoyCrouch = Config.Bind("JoystickMovement", "JoyCrouch", "JoystickButton8", "JoyCrouch button");
+ buttonJoyMap = Config.Bind("JoystickUI", "JoyMap", "JoystickButton6", "JoyMap button");
+ buttonJoyMenu = Config.Bind("JoystickUI", "JoyMenu", "JoystickButton7", "JoyMenu button");
+ buttonJoySecondAttack = Config.Bind("JoystickCombat", "JoySecondAttack", "JoystickButton5", "JoySecondAttack button");
+ buttonJoyAltPlace = Config.Bind("JoystickBuild", "JoyAltPlace", "JoystickButton4", "JoyAltPlace button");
+ buttonJoyRemove = Config.Bind("JoystickBuild", "JoyRemove", "JoystickButton5", "JoyRemove button");
+ buttonJoyTabLeft = Config.Bind("JoystickUI", "JoyTabLeft", "JoystickButton4", "JoyTabLeft button");
+ buttonJoyTabRight = Config.Bind("JoystickUI", "JoyTabRight", "JoystickButton5", "JoyTabRight button");
+ buttonJoyButtonA = Config.Bind("JoystickButtons", "JoyButtonA", "JoystickButton0", "JoyButtonA button");
+ buttonJoyButtonB = Config.Bind("JoystickButtons", "JoyButtonB", "JoystickButton1", "JoyButtonB button");
+ buttonJoyButtonX = Config.Bind("JoystickButtons", "JoyButtonX", "JoystickButton2", "JoyButtonX button");
+ buttonJoyButtonY = Config.Bind("JoystickButtons", "JoyButtonY", "JoystickButton3", "JoyButtonY button");
+ buttonJoyLStick = Config.Bind("JoystickButtons", "JoyLStick", "JoystickButton8", "JoyLStick button");
+ buttonJoyRStick = Config.Bind("JoystickButtons", "JoyRStick", "JoystickButton9", "JoyRStick button");
+
+ buttonJoyGPower = Config.Bind("JoystickMisc", "JoyGPower", "JoyAxis 7,0,0,true", "JoyGPower button");
+ buttonJoyBlock = Config.Bind("JoystickCombat", "JoyBlock", "JoyAxis 3,0,0,true", "JoyBlock button");
+ buttonJoyAttack = Config.Bind("JoystickCombat", "JoyAttack", "JoyAxis 3,0,0,false", "JoyAttack button");
+ buttonJoyRotate = Config.Bind("JoystickBuild", "JoyRotate", "JoyAxis 3,0,0,true", "JoyRotate button");
+ buttonJoyPlace = Config.Bind("JoystickBuild", "JoyPlace", "JoyAxis 10,0,0,false", "JoyPlace button");
+ buttonJoyLStickLeft = Config.Bind("JoystickPads", "JoyLStickLeft", "JoyAxis 1,0.3,0.1,true", "JoyLStickLeft button");
+ buttonJoyLStickRight = Config.Bind("JoystickPads", "JoyLStickRight", "JoyAxis 1,0.3,0.1,false", "JoyLStickRight button");
+ buttonJoyLStickUp = Config.Bind("JoystickPads", "JoyLStickUp", "JoyAxis 2,0.3,0.1,true", "JoyLStickUp button");
+ buttonJoyLStickDown = Config.Bind("JoystickPads", "JoyLStickDown", "JoyAxis 2,0.3,0.1,false", "JoyLStickDown button");
+ buttonJoyDPadLeft = Config.Bind("JoystickPads", "JoyDPadLeft", "JoyAxis 6,0.3,0.1,true", "JoyDPadLeft button");
+ buttonJoyDPadRight = Config.Bind("JoystickPads", "JoyDPadRight", "JoyAxis 6,0.3,0.1,false", "JoyDPadRight button");
+ buttonJoyDPadUp = Config.Bind("JoystickPads", "JoyDPadUp", "JoyAxis 7,0.3,0.1,true", "JoyDPadUp button");
+ buttonJoyDPadDown = Config.Bind("JoystickPads", "JoyDPadDown", "JoyAxis 7,0.3,0.1,false", "JoyDPadDown button");
+ buttonJoyLTrigger = Config.Bind("JoystickButtons", "JoyLTrigger", "JoyAxis 3,0,0,true", "JoyLTrigger button");
+ buttonJoyRTrigger = Config.Bind("JoystickButtons", "JoyRTrigger", "JoyAxis 3,0,0,false", "JoyRTrigger button");
+
+ harmony = new Harmony(Info.Metadata.GUID);
+ harmony.PatchAll();
+ }
+
+ private void OnDestroy()
+ {
+ Dbgl("Destroying plugin");
+ harmony?.UnpatchAll();
+ }
+
+ static void SetButtons()
+ {
+ if (!modEnabled.Value || ZInput.instance == null)
+ return;
+
+ ZInput zInput = ZInput.instance;
+ Dictionary m_buttons = Traverse.Create(zInput).Field("m_buttons").GetValue>();
+
+ m_buttons.Clear();
+
+ using (var enumerator = context.Config.GetEnumerator())
+ {
+ while (enumerator.MoveNext())
+ {
+ if (enumerator.Current.Key.Section == "Config")
+ continue;
+ ButtonInfo info = new ButtonInfo(enumerator.Current.Key.Key, (ConfigEntry)enumerator.Current.Value);
+ if (Enum.TryParse(info.key, out KeyCode keyCode))
+ zInput.AddButton(info.button, keyCode, info.repeatDelay, info.repeatInterval);
+ else
+ zInput.AddButton(info.button, info.key, info.inverted, info.repeatDelay, info.repeatInterval);
+ }
+ }
+ zInput.Save();
+ Dbgl("Finished setting buttons");
+ }
+
+ [HarmonyPatch(typeof(ZInput), "Load")]
+ static class ZInput_Load_Patch
+ {
+ static void Prefix(ZInput __instance)
+ {
+ if (modEnabled.Value)
+ SetButtons();
+ }
+ }
+ [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();
+ SetButtons();
+ 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;
+ }
+ if (text.ToLower().Equals($"dump keycodes"))
+ {
+ var codes = Enum.GetNames(typeof(KeyCode));
+ Dbgl($"{codes.Length} KeyCodes:\r\n\r\n" + string.Join("\r\n", codes));
+ Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
+ Traverse.Create(__instance).Method("AddString", new object[] { $"KeyCodes dumped to Player.log" }).GetValue();
+ return false;
+ }
+ return true;
+ }
+ }
+ }
+}
diff --git a/ControllerButtonSwitch/ButtonInfo.cs b/ControllerButtonSwitch/ButtonInfo.cs
new file mode 100644
index 0000000..9b57474
--- /dev/null
+++ b/ControllerButtonSwitch/ButtonInfo.cs
@@ -0,0 +1,29 @@
+using BepInEx.Configuration;
+
+namespace ControllerButtonSwitch
+{
+ internal class ButtonInfo
+ {
+ internal string button;
+ internal string key;
+ internal float repeatDelay = 0;
+ internal float repeatInterval = 0;
+ internal bool inverted = false;
+
+ public ButtonInfo(string name, ConfigEntry entry)
+ {
+ button = name;
+ string[] parts = entry.Value.Split(',');
+ key = parts[0];
+ if (parts.Length == 1)
+ return;
+ repeatDelay = float.Parse(parts[1]);
+ if (parts.Length == 2)
+ return;
+ repeatInterval = float.Parse(parts[2]);
+ if (parts.Length == 3)
+ return;
+ inverted = bool.Parse(parts[3]);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ControllerButtonSwitch/ControllerButtonSwitch.csproj b/ControllerButtonSwitch/ControllerButtonSwitch.csproj
new file mode 100644
index 0000000..250eb8c
--- /dev/null
+++ b/ControllerButtonSwitch/ControllerButtonSwitch.csproj
@@ -0,0 +1,6 @@
+
+
+ 1.0.0
+
+
+
\ No newline at end of file
diff --git a/ControllerButtonSwitch/Properties/AssemblyInfo.cs b/ControllerButtonSwitch/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..c4e5c27
--- /dev/null
+++ b/ControllerButtonSwitch/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 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("ControllerButtonSwitch")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ControllerButtonSwitch")]
+[assembly: AssemblyCopyright("Copyright © 2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a775ed6f-5fd3-4315-bd97-537bf9999300")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// 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")]
diff --git a/DiscardInventoryItem/BepInExPlugin.cs b/DiscardInventoryItem/BepInExPlugin.cs
index 89dff0f..33a4eca 100644
--- a/DiscardInventoryItem/BepInExPlugin.cs
+++ b/DiscardInventoryItem/BepInExPlugin.cs
@@ -1,13 +1,15 @@
using BepInEx;
+using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
+using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace DiscardInventoryItem
{
- [BepInPlugin("aedenthorn.DiscardInventoryItem", "Discard Inventory Items", "0.3.6")]
+ [BepInPlugin("aedenthorn.DiscardInventoryItem", "Discard Inventory Items", "0.4.1")]
public class BepInExPlugin: BaseUnityPlugin
{
private static readonly bool isDebug = true;
@@ -18,6 +20,7 @@ public class BepInExPlugin: BaseUnityPlugin
public static ConfigEntry nexusID;
private static BepInExPlugin context;
+ private static Assembly epicLootAssembly;
public static void Dbgl(string str = "", bool pref = true)
{
@@ -38,6 +41,12 @@ private void Awake()
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), null);
}
+ private void Start()
+ {
+ if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.epicloot"))
+ epicLootAssembly = Chainloader.PluginInfos["randyknapp.mods.epicloot"].Instance.GetType().Assembly;
+
+ }
[HarmonyPatch(typeof(InventoryGui), "UpdateItemDrag")]
static class UpdateItemDrag_Patch
@@ -51,35 +60,59 @@ static void Postfix(InventoryGui __instance, ItemDrop.ItemData ___m_dragItem, In
if (returnResources.Value > 0)
{
Recipe recipe = ObjectDB.instance.GetRecipe(___m_dragItem);
-
- if(recipe != null)
- Dbgl($"Recipe stack: {recipe.m_amount} num of stacks: {___m_dragAmount / recipe.m_amount}");
-
- if (recipe != null && ___m_dragAmount / recipe.m_amount > 0)
+
+ if (recipe != null)
{
- for (int i = 0; i < ___m_dragAmount / recipe.m_amount; i++)
+ Dbgl($"Recipe stack: {recipe.m_amount} num of stacks: {___m_dragAmount / recipe.m_amount}");
+
+
+ var reqs = recipe.m_resources.ToList();
+
+ bool isMagic = false;
+ if (epicLootAssembly != null)
{
- foreach (Piece.Requirement req in recipe.m_resources)
+ isMagic = (bool)epicLootAssembly.GetType("EpicLoot.ItemDataExtensions").GetMethod("IsMagic", BindingFlags.Public | BindingFlags.Static).Invoke(null, new[] { ___m_dragItem });
+ }
+ if (isMagic)
+ {
+ int rarity = (int)epicLootAssembly.GetType("EpicLoot.ItemDataExtensions").GetMethod("GetRarity", BindingFlags.Public | BindingFlags.Static).Invoke(null, new[] { ___m_dragItem });
+ List> magicReqs = (List>)epicLootAssembly.GetType("EpicLoot.Crafting.EnchantTabController").GetMethod("GetEnchantCosts", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { ___m_dragItem, rarity });
+ foreach (var kvp in magicReqs)
{
- int quality = ___m_dragItem.m_quality;
- for(int j = quality; j > 0; j--)
+ reqs.Add(new Piece.Requirement()
{
- GameObject prefab = ObjectDB.instance.m_items.FirstOrDefault(item => item.GetComponent().m_itemData.m_shared.m_name == req.m_resItem.m_itemData.m_shared.m_name);
- ItemDrop.ItemData newItem = prefab.GetComponent().m_itemData;
- int numToAdd = Mathf.RoundToInt(req.GetAmount(j) * returnResources.Value);
- Dbgl($"Returning {numToAdd}/{req.GetAmount(j)} {prefab.name}");
- while (numToAdd > 0)
- {
- int stack = Mathf.Min(req.m_resItem.m_itemData.m_shared.m_maxStackSize, numToAdd);
- numToAdd -= stack;
+ m_amount = kvp.Value,
+ m_resItem = kvp.Key
+ });
+ }
+ }
- if (Player.m_localPlayer.GetInventory().AddItem(prefab.name, stack, req.m_resItem.m_itemData.m_quality, req.m_resItem.m_itemData.m_variant, 0, "") == null)
+ if (___m_dragAmount / recipe.m_amount > 0)
+ {
+ for (int i = 0; i < ___m_dragAmount / recipe.m_amount; i++)
+ {
+ foreach (Piece.Requirement req in reqs)
+ {
+ int quality = ___m_dragItem.m_quality;
+ for (int j = quality; j > 0; j--)
+ {
+ GameObject prefab = ObjectDB.instance.m_items.FirstOrDefault(item => item.GetComponent().m_itemData.m_shared.m_name == req.m_resItem.m_itemData.m_shared.m_name);
+ ItemDrop.ItemData newItem = prefab.GetComponent().m_itemData;
+ int numToAdd = Mathf.RoundToInt(req.GetAmount(j) * returnResources.Value);
+ Dbgl($"Returning {numToAdd}/{req.GetAmount(j)} {prefab.name}");
+ while (numToAdd > 0)
{
- ItemDrop component = Instantiate(prefab, Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward + Player.m_localPlayer.transform.up, Player.m_localPlayer.transform.rotation).GetComponent();
- component.m_itemData = newItem.Clone();
- component.m_itemData.m_dropPrefab = prefab;
- component.m_itemData.m_stack = stack;
- Traverse.Create(component).Method("Save").GetValue();
+ int stack = Mathf.Min(req.m_resItem.m_itemData.m_shared.m_maxStackSize, numToAdd);
+ numToAdd -= stack;
+
+ if (Player.m_localPlayer.GetInventory().AddItem(prefab.name, stack, req.m_resItem.m_itemData.m_quality, req.m_resItem.m_itemData.m_variant, 0, "") == null)
+ {
+ ItemDrop component = Instantiate(prefab, Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward + Player.m_localPlayer.transform.up, Player.m_localPlayer.transform.rotation).GetComponent();
+ component.m_itemData = newItem.Clone();
+ component.m_itemData.m_dropPrefab = prefab;
+ component.m_itemData.m_stack = stack;
+ Traverse.Create(component).Method("Save").GetValue();
+ }
}
}
}
diff --git a/InventoryHUD/BepInExPlugin.cs b/InventoryHUD/BepInExPlugin.cs
index 6779c89..8599724 100644
--- a/InventoryHUD/BepInExPlugin.cs
+++ b/InventoryHUD/BepInExPlugin.cs
@@ -1,16 +1,14 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
-using System.Collections.Generic;
using System.IO;
-using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
namespace InventoryHUD
{
- [BepInPlugin("aedenthorn.InventoryHUD", "InventoryHUD", "0.1.0")]
+ [BepInPlugin("aedenthorn.InventoryHUD", "InventoryHUD", "0.2.0")]
public class BepInExPlugin : BaseUnityPlugin
{
private static readonly bool isDebug = true;
@@ -62,7 +60,7 @@ private void Awake()
extraSlots = Config.Bind("General", "ExtraSlots", 0, "Extra slots added by mods outside of the actual player inventory. Use this for mods that add extra inventories or other hacky things. E.g. Equipment and Quick Slots mods adds eight extra slots outside of the actual player inventory. Set this to 8 if you use that mod.");
- infoStringOffset = Config.Bind("InfoString", "InfoStringOffset", new Vector2(-64,0), "Inventory info string offset");
+ infoStringOffset = Config.Bind("Info", "InfoStringOffset", new Vector2(-64,0), "Inventory info string offset");
infoString = Config.Bind("Info", "InfoString", "{0}/{1}\r\n{2}/{3}", "Inventory info string to show. {0} is replaced by current number of items. {1} is replaced by number of slots total. {2} is replaced by current weight. {3} is replaced by total weight. See string.Format API for advanced usage.");
infoStringSize = Config.Bind("Info", "InfoStringSize", 12, "Inventory info string size.");
infoStringFont = Config.Bind("Info", "InfoStringFont", "AveriaSerifLibre-Bold", "Inventory info string font.");
@@ -230,7 +228,7 @@ static void Prefix(Hud __instance)
Inventory inv = Player.m_localPlayer.GetInventory();
Vector3 hudPos = new Vector3(hudPosition.Value.x, hudPosition.Value.y, 0);
float weight = inv.GetTotalWeight();
- float totalWeight = Player.m_localPlayer.m_maxCarryWeight;
+ float totalWeight = Player.m_localPlayer.GetMaxCarryWeight();
if (fullObject != null)
{
float hudScale = GameObject.Find("GUI").GetComponent().scaleFactor;
diff --git a/Recycle/AedenthornUtils.cs b/Recycle/AedenthornUtils.cs
new file mode 100644
index 0000000..f8b100f
--- /dev/null
+++ b/Recycle/AedenthornUtils.cs
@@ -0,0 +1,33 @@
+using UnityEngine;
+
+public class AedenthornUtils
+{
+ public static bool IgnoreKeyPresses(bool extra = false)
+ {
+ if (!extra)
+ return ZNetScene.instance == null || Player.m_localPlayer == null || Minimap.IsOpen() || Console.IsVisible() || TextInput.IsVisible() || ZNet.instance.InPasswordDialog() || Chat.instance?.HasFocus() == true;
+ return ZNetScene.instance == null || Player.m_localPlayer == null || Minimap.IsOpen() || Console.IsVisible() || TextInput.IsVisible() || ZNet.instance.InPasswordDialog() || Chat.instance?.HasFocus() == true || StoreGui.IsVisible() || InventoryGui.IsVisible() || Menu.IsVisible() || TextViewer.instance?.IsVisible() == true;
+ }
+ public static bool CheckKeyDown(string value)
+ {
+ try
+ {
+ return Input.GetKeyDown(value.ToLower());
+ }
+ catch
+ {
+ return false;
+ }
+ }
+ public static bool CheckKeyHeld(string value, bool req = true)
+ {
+ try
+ {
+ return Input.GetKey(value.ToLower());
+ }
+ catch
+ {
+ return !req;
+ }
+ }
+}
diff --git a/Recycle/BepInExPlugin.cs b/Recycle/BepInExPlugin.cs
new file mode 100644
index 0000000..dbb22e5
--- /dev/null
+++ b/Recycle/BepInExPlugin.cs
@@ -0,0 +1,126 @@
+using BepInEx;
+using BepInEx.Configuration;
+using HarmonyLib;
+using System.Linq;
+using System.Reflection;
+using UnityEngine;
+
+namespace Recycle
+{
+ [BepInPlugin("aedenthorn.Recycle", "Recycle", "0.1.0")]
+ public class BepInExPlugin: BaseUnityPlugin
+ {
+ private static readonly bool isDebug = true;
+
+ public static ConfigEntry modKey;
+ public static ConfigEntry modEnabled;
+ public static ConfigEntry returnResources;
+ public static ConfigEntry nexusID;
+
+ private static BepInExPlugin context;
+
+ public static void Dbgl(string str = "", bool pref = true)
+ {
+ if (isDebug)
+ Debug.Log((pref ? typeof(BepInExPlugin).Namespace + " " : "") + str);
+ }
+ private void Awake()
+ {
+ context = this;
+
+ modKey = Config.Bind("General", "DiscardHotkey", "left alt", "The modifier key to recycle on click");
+ modEnabled = Config.Bind("General", "Enabled", true, "Enable this mod");
+ returnResources = Config.Bind("General", "ReturnResources", 0f, "Fraction of resources to return (0.0 - 1.0)");
+ nexusID = Config.Bind("General", "NexusID", 45, "Nexus mod ID for updates");
+
+ if (!modEnabled.Value)
+ return;
+
+ Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), null);
+ }
+
+ [HarmonyPatch(typeof(InventoryGui), "UpdateInventory")]
+ static class UpdateInventory_Patch
+ {
+ static void Postfix(InventoryGui __instance, ItemDrop.ItemData ___m_dragItem, Inventory ___m_dragInventory, int ___m_dragAmount, ref GameObject ___m_dragGo)
+ {
+ if(AedenthornUtils.CheckKeyHeld(modKey.Value, false) && ___m_dragItem != null && ___m_dragInventory.ContainsItem(___m_dragItem))
+ {
+ Dbgl($"Recycling {___m_dragAmount}/{___m_dragItem.m_stack} {___m_dragItem.m_dropPrefab.name}");
+
+ if (returnResources.Value > 0)
+ {
+ Recipe recipe = ObjectDB.instance.GetRecipe(___m_dragItem);
+
+ if(recipe != null)
+ Dbgl($"Recipe stack: {recipe.m_amount} num of stacks: {___m_dragAmount / recipe.m_amount}");
+
+ if (recipe != null && ___m_dragAmount / recipe.m_amount > 0)
+ {
+ for (int i = 0; i < ___m_dragAmount / recipe.m_amount; i++)
+ {
+ foreach (Piece.Requirement req in recipe.m_resources)
+ {
+ int quality = ___m_dragItem.m_quality;
+ for(int j = quality; j > 0; j--)
+ {
+ GameObject prefab = ObjectDB.instance.m_items.FirstOrDefault(item => item.GetComponent().m_itemData.m_shared.m_name == req.m_resItem.m_itemData.m_shared.m_name);
+ ItemDrop.ItemData newItem = prefab.GetComponent().m_itemData;
+ int numToAdd = Mathf.RoundToInt(req.GetAmount(j) * returnResources.Value);
+ Dbgl($"Returning {numToAdd}/{req.GetAmount(j)} {prefab.name}");
+ while (numToAdd > 0)
+ {
+ int stack = Mathf.Min(req.m_resItem.m_itemData.m_shared.m_maxStackSize, numToAdd);
+ numToAdd -= stack;
+
+ if (Player.m_localPlayer.GetInventory().AddItem(prefab.name, stack, req.m_resItem.m_itemData.m_quality, req.m_resItem.m_itemData.m_variant, 0, "") == null)
+ {
+ ItemDrop component = Instantiate(prefab, Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward + Player.m_localPlayer.transform.up, Player.m_localPlayer.transform.rotation).GetComponent();
+ component.m_itemData = newItem.Clone();
+ component.m_itemData.m_dropPrefab = prefab;
+ component.m_itemData.m_stack = stack;
+ Traverse.Create(component).Method("Save").GetValue();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (___m_dragAmount == ___m_dragItem.m_stack)
+ {
+ Player.m_localPlayer.RemoveFromEquipQueue(___m_dragItem);
+ Player.m_localPlayer.UnequipItem(___m_dragItem, false);
+ ___m_dragInventory.RemoveItem(___m_dragItem);
+ }
+ else
+ ___m_dragInventory.RemoveItem(___m_dragItem, ___m_dragAmount);
+ Destroy(___m_dragGo);
+ ___m_dragGo = null;
+ __instance.GetType().GetMethod("UpdateCraftingPanel", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { false });
+ }
+ }
+ }
+ [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("discardinventoryitem reset"))
+ {
+ context.Config.Reload();
+ context.Config.Save();
+
+ Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
+ Traverse.Create(__instance).Method("AddString", new object[] { "Discard Inventory Item config reloaded" }).GetValue();
+ return false;
+ }
+ return true;
+ }
+ }
+ }
+}
diff --git a/Recycle/Properties/AssemblyInfo.cs b/Recycle/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..ee6e7ed
--- /dev/null
+++ b/Recycle/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 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("Recycle")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Recycle")]
+[assembly: AssemblyCopyright("Copyright © 2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("c7ba4a36-003d-4ca4-94b4-3bcc8bb05448")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// 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")]
diff --git a/Recycle/Recycle.csproj b/Recycle/Recycle.csproj
new file mode 100644
index 0000000..250eb8c
--- /dev/null
+++ b/Recycle/Recycle.csproj
@@ -0,0 +1,6 @@
+
+
+ 1.0.0
+
+
+
\ No newline at end of file
diff --git a/ValheimMods.sln b/ValheimMods.sln
index 4e9708b..cbde8b4 100644
--- a/ValheimMods.sln
+++ b/ValheimMods.sln
@@ -160,9 +160,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeathTweaks", "DeathTweaks\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TerraformTweaks", "TerraformTweaks\TerraformTweaks.csproj", "{3C71E421-2A98-4B06-B708-888E5E77D7F3}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerrainReset", "TerrainReset\TerrainReset.csproj", "{C0BD6D8D-50BD-4C80-BD59-1AFB17E146C3}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TerrainReset", "TerrainReset\TerrainReset.csproj", "{C0BD6D8D-50BD-4C80-BD59-1AFB17E146C3}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InventoryHUD", "InventoryHUD\InventoryHUD.csproj", "{2A3431AE-002D-4B07-B681-21942166995C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InventoryHUD", "InventoryHUD\InventoryHUD.csproj", "{2A3431AE-002D-4B07-B681-21942166995C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Recycle", "Recycle\Recycle.csproj", "{C7BA4A36-003D-4CA4-94B4-3BCC8BB05448}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControllerButtonSwitch", "ControllerButtonSwitch\ControllerButtonSwitch.csproj", "{A775ED6F-5FD3-4315-BD97-537BF9999300}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -478,6 +482,14 @@ Global
{2A3431AE-002D-4B07-B681-21942166995C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A3431AE-002D-4B07-B681-21942166995C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A3431AE-002D-4B07-B681-21942166995C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C7BA4A36-003D-4CA4-94B4-3BCC8BB05448}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C7BA4A36-003D-4CA4-94B4-3BCC8BB05448}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C7BA4A36-003D-4CA4-94B4-3BCC8BB05448}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C7BA4A36-003D-4CA4-94B4-3BCC8BB05448}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A775ED6F-5FD3-4315-BD97-537BF9999300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A775ED6F-5FD3-4315-BD97-537BF9999300}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A775ED6F-5FD3-4315-BD97-537BF9999300}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A775ED6F-5FD3-4315-BD97-537BF9999300}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE