Decompiled source of InGame ModManager v1.0.1

ValheimModManager.dll

Decompiled 21 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ValheimModManager")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KomiSanNs InGame ModManager")]
[assembly: AssemblyTitle("ValheimModManager")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ValheimModManager
{
	[BepInPlugin("com.komisann.valheimmodmanager", "KomiSanN InGame ModManager", "1.0.0")]
	public class ModManagerPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(FejdStartup), "SetupGui")]
		private class MainMenuGuiPatch
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static UnityAction <>9__0_0;

				internal void <Postfix>b__0_0()
				{
					((BaseUnityPlugin)Instance).Logger.LogInfo((object)"ModManager-Button geklickt -> Öffne transparentes Menü!");
					showMenu = !showMenu;
					if ((Object)(object)EventSystem.current != (Object)null)
					{
						EventSystem.current.SetSelectedGameObject((GameObject)null);
					}
				}
			}

			private static void Postfix(FejdStartup __instance)
			{
				//IL_024e: Unknown result type (might be due to invalid IL or missing references)
				//IL_026b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0279: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ab: Expected O, but got Unknown
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)"--- SetupGui aufgerufen! Erstelle ModManager-Button ---");
				try
				{
					Button[] array = Resources.FindObjectsOfTypeAll<Button>();
					Button val = null;
					Button[] array2 = array;
					foreach (Button val2 in array2)
					{
						if (((Component)val2).gameObject.activeInHierarchy && (((Object)val2).name.ToLower().Contains("quit") || ((Object)val2).name.ToLower().Contains("start") || ((Object)val2).name.ToLower().Contains("credits")))
						{
							val = val2;
							break;
						}
					}
					if (!((Object)(object)val != (Object)null))
					{
						return;
					}
					Transform parent = ((Component)val).transform.parent;
					Transform val3 = Object.Instantiate<Transform>(((Component)val).transform, parent);
					((Object)val3).name = "Button_ModManager";
					Button[] components = ((Component)val3).GetComponents<Button>();
					Button[] array3 = components;
					foreach (Button val4 in array3)
					{
						Object.DestroyImmediate((Object)(object)val4);
					}
					Component[] components2 = ((Component)val3).GetComponents<Component>();
					foreach (Component val5 in components2)
					{
						string text = ((object)val5).GetType().Name.ToLower();
						if (text.Contains("button") && !text.Contains("transform"))
						{
							Object.DestroyImmediate((Object)(object)val5);
						}
					}
					Component[] componentsInChildren = ((Component)val3).GetComponentsInChildren<Component>();
					Component[] array4 = componentsInChildren;
					foreach (Component val6 in array4)
					{
						string name = ((object)val6).GetType().Name;
						if (name.Contains("TMP_Text") || name.Contains("TextMeshPro"))
						{
							PropertyInfo property = ((object)val6).GetType().GetProperty("text");
							if (property != null)
							{
								property.SetValue(val6, "Mod Manager", null);
								break;
							}
						}
						else
						{
							Text val7 = (Text)(object)((val6 is Text) ? val6 : null);
							if (val7 != null)
							{
								val7.text = "Mod Manager";
								break;
							}
						}
					}
					Button val8 = ((Component)val3).gameObject.AddComponent<Button>();
					if ((Object)(object)val != (Object)null)
					{
						((Selectable)val8).transition = ((Selectable)val).transition;
						((Selectable)val8).targetGraphic = (Graphic)(object)((Component)val3).GetComponent<Image>();
						((Selectable)val8).colors = ((Selectable)val).colors;
						((Selectable)val8).spriteState = ((Selectable)val).spriteState;
					}
					ButtonClickedEvent onClick = val8.onClick;
					object obj = <>c.<>9__0_0;
					if (obj == null)
					{
						UnityAction val9 = delegate
						{
							((BaseUnityPlugin)Instance).Logger.LogInfo((object)"ModManager-Button geklickt -> Öffne transparentes Menü!");
							showMenu = !showMenu;
							if ((Object)(object)EventSystem.current != (Object)null)
							{
								EventSystem.current.SetSelectedGameObject((GameObject)null);
							}
						};
						<>c.<>9__0_0 = val9;
						obj = (object)val9;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
					val3.localPosition += new Vector3(0f, -60f, 0f);
					((BaseUnityPlugin)Instance).Logger.LogInfo((object)"ModManager-Button erfolgreich radikal bereinigt und scharfgeschaltet!");
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)("Fehler beim Button-Klonen: " + ex.Message));
				}
			}
		}

		public static ModManagerPlugin Instance;

		private readonly Harmony harmony = new Harmony("com.komisann.valheimmodmanager");

		private static bool showMenu;

		private Rect windowRect;

		private Vector2 scrollPosition = Vector2.zero;

		private bool initializedPosition = false;

		private GUIStyle windowStyle;

		private GUIStyle titleStyle;

		private GUIStyle boxStyle;

		private GUIStyle buttonStyle;

		private GUIStyle closeButtonStyle;

		private GUIStyle warningBoxStyle;

		private void Awake()
		{
			Instance = this;
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ModManager erfolgreich geladen! Warte auf SetupGui...");
		}

		private void OnGUI()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (showMenu)
			{
				if (!initializedPosition)
				{
					float num = 600f;
					float num2 = 740f;
					float num3 = ((float)Screen.width - num) / 2f;
					float num4 = ((float)Screen.height - num2) / 2f;
					windowRect = new Rect(num3, num4, num, num2);
					initializedPosition = true;
				}
				if (windowStyle == null)
				{
					InitCustomStyles();
				}
				windowRect = GUI.Window(9999, windowRect, new WindowFunction(DrawModManagerMenu), "", windowStyle);
			}
			else
			{
				initializedPosition = false;
			}
		}

		private void InitCustomStyles()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Expected O, but got Unknown
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			windowStyle = new GUIStyle(GUI.skin.window);
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, new Color(0.08f, 0.08f, 0.1f, 0.95f));
			val.Apply();
			windowStyle.normal.background = val;
			windowStyle.focused.background = val;
			windowStyle.onNormal.background = val;
			windowStyle.padding = new RectOffset(15, 15, 15, 15);
			titleStyle = new GUIStyle(GUI.skin.label);
			titleStyle.normal.textColor = new Color(1f, 0.64f, 0f);
			titleStyle.fontSize = 20;
			titleStyle.richText = true;
			boxStyle = new GUIStyle(GUI.skin.box);
			Texture2D val2 = new Texture2D(1, 1);
			val2.SetPixel(0, 0, new Color(0.15f, 0.15f, 0.18f, 0.6f));
			val2.Apply();
			boxStyle.normal.background = val2;
			boxStyle.margin = new RectOffset(0, 0, 4, 4);
			boxStyle.padding = new RectOffset(10, 10, 8, 8);
			closeButtonStyle = new GUIStyle(GUI.skin.button);
			closeButtonStyle.normal.textColor = Color.red;
			closeButtonStyle.fontSize = 14;
			buttonStyle = new GUIStyle(GUI.skin.button);
			buttonStyle.fontSize = 12;
			warningBoxStyle = new GUIStyle(GUI.skin.box);
			Texture2D val3 = new Texture2D(1, 1);
			val3.SetPixel(0, 0, new Color(0.22f, 0.14f, 0.05f, 0.75f));
			val3.Apply();
			warningBoxStyle.normal.background = val3;
			warningBoxStyle.padding = new RectOffset(12, 12, 10, 10);
			warningBoxStyle.margin = new RectOffset(0, 0, 5, 15);
		}

		private void DrawModManagerMenu(int windowID)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.Label("<b>⚔ VALHEIM MOD MANAGER ⚔</b>", titleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if (GUI.Button(new Rect(((Rect)(ref windowRect)).width - 35f, 10f, 25f, 25f), "X", closeButtonStyle))
			{
				showMenu = false;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(20f);
			GUILayout.BeginVertical(warningBoxStyle, Array.Empty<GUILayoutOption>());
			string text = "<b>⚠\ufe0f HINWEIS ZUR LIVE-DEAKTIVIERUNG / LIVE DEACTIVATION NOTE:</b>\n<color=#ffcc00>Bei reinen Inhalts-Mods (z.B. neue Rüstungen, Waffen oder Bauteile) können Objekte aus einem bereits geladenen Spielstand weiterhin sichtbar sein, bis das Spiel neu gestartet wird.\n\nFor content-only mods (e.g., custom armor, weapons, or build pieces), objects from an already loaded save file may remain visible until the game is restarted.</color>";
			GUILayout.Label(text, new GUIStyle(GUI.skin.label)
			{
				richText = true,
				wordWrap = true,
				fontSize = 11
			}, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			Dictionary<string, PluginInfo> pluginInfos = Chainloader.PluginInfos;
			GUILayout.Label($"<color=#aaaaaa>Verwaltete Modifikationen / Managed Modifications:</color> <color=#ffaa00><b>{pluginInfos.Count}</b></color>", GUI.skin.label, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(((Rect)(ref windowRect)).width - 30f),
				GUILayout.Height(((Rect)(ref windowRect)).height - 270f)
			});
			foreach (PluginInfo value in pluginInfos.Values)
			{
				GUILayout.BeginHorizontal(boxStyle, Array.Empty<GUILayoutOption>());
				BaseUnityPlugin instance = value.Instance;
				bool flag = (Object)(object)instance != (Object)null && ((Behaviour)instance).enabled;
				GUILayout.Label($"<color=#ffffff><b>{value.Metadata.Name}</b></color> <color=#888888>v{value.Metadata.Version}</color>", Array.Empty<GUILayoutOption>());
				GUILayout.FlexibleSpace();
				if (flag)
				{
					GUILayout.Label("<color=#44ff44>● AKTIV </color>", Array.Empty<GUILayoutOption>());
					if (GUILayout.Button("Deactivate", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }) && (Object)(object)instance != (Object)null)
					{
						((Behaviour)instance).enabled = false;
						((BaseUnityPlugin)Instance).Logger.LogInfo((object)(value.Metadata.Name + " wurde LIVE deaktiviert."));
					}
				}
				else
				{
					GUILayout.Label("<color=#ff4444>○ INAKTIV</color>", Array.Empty<GUILayoutOption>());
					if (GUILayout.Button("Activate", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }) && (Object)(object)instance != (Object)null)
					{
						((Behaviour)instance).enabled = true;
						((BaseUnityPlugin)Instance).Logger.LogInfo((object)(value.Metadata.Name + " wurde LIVE aktiviert."));
					}
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 40f));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ValheimModManager";

		public const string PLUGIN_NAME = "KomiSanNs InGame ModManager";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}