Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Valheim Studio v0.15.7
plugins/ValheimStudio/ValheimAxiom.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.UI; using ValheimAxiom.Cameras; using ValheimAxiom.Core; using ValheimAxiom.Studio.Selection; using ValheimAxiom.Studio.Terrain; using ValheimAxiom.UI.Studio; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("ValheimAxiom")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+30baf9763cc876e5e05ee9345dec54278895f309")] [assembly: AssemblyProduct("ValheimAxiom")] [assembly: AssemblyTitle("ValheimAxiom")] [assembly: AssemblyVersion("1.0.0.0")] [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 ValheimAxiom { public sealed class BuilderMode : MonoBehaviour { private bool _mouseLook; private float _yaw; private float _pitch; private Camera _gameCamera; private Camera _editorCamera; private GameObject _editorCameraObject; private Transform _lockedPlayerTransform; private Behaviour _lockedPlayerBehaviour; private bool _lockedPlayerBehaviourWasEnabled; private Vector3 _lockedPlayerPosition; private Quaternion _lockedPlayerRotation; public static BuilderMode Instance { get; private set; } public bool IsActive { get; private set; } public string StatusText { get; private set; } = "Bereit"; public Camera EditorCamera { get { if (!((Object)(object)_editorCamera != (Object)null)) { return Camera.main; } return _editorCamera; } } private void Awake() { Instance = this; } private void Update() { if (Input.GetKeyDown((KeyCode)303)) { if (IsActive) { SetActive(active: false); } else { SetActive(active: true); } } if (IsActive) { ForceEditorCursor(); FreezePlayerInPlace(); CloseVanillaBuildMenus(); UpdateEditorCamera(); } } private void LateUpdate() { if (IsActive) { ForceEditorCursor(); FreezePlayerInPlace(); CloseVanillaBuildMenus(); } } private void FixedUpdate() { if (IsActive) { FreezePlayerInPlace(); } } public void ForceEditorCursor() { Cursor.visible = true; Cursor.lockState = (CursorLockMode)0; } public void SetActive(bool active) { if (active != IsActive) { IsActive = active; EditorWindow.SetVisible(active); if (active) { LockPlayer(); EnterEditorCameraMode(); CloseVanillaBuildMenus(); StatusText = "Axiom-Baumodus aktiv: freie Kamera. Spielinput blockiert, ESC bleibt Pause."; } else { ExitEditorCameraMode(); UnlockPlayer(); _mouseLook = false; StatusText = "Axiom-Baumodus aus"; } } } private void LockPlayer() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) _lockedPlayerTransform = GetLocalPlayerTransform(); if (!((Object)(object)_lockedPlayerTransform == (Object)null)) { _lockedPlayerPosition = _lockedPlayerTransform.position; _lockedPlayerRotation = _lockedPlayerTransform.rotation; ZeroPlayerVelocity(((Component)_lockedPlayerTransform).gameObject); ref Behaviour lockedPlayerBehaviour = ref _lockedPlayerBehaviour; Component component = ((Component)_lockedPlayerTransform).GetComponent(AccessTools.TypeByName("Player")); lockedPlayerBehaviour = (Behaviour)(object)((component is Behaviour) ? component : null); if ((Object)(object)_lockedPlayerBehaviour != (Object)null) { _lockedPlayerBehaviourWasEnabled = _lockedPlayerBehaviour.enabled; _lockedPlayerBehaviour.enabled = false; } } } private void UnlockPlayer() { if ((Object)(object)_lockedPlayerBehaviour != (Object)null) { _lockedPlayerBehaviour.enabled = _lockedPlayerBehaviourWasEnabled; _lockedPlayerBehaviour = null; } _lockedPlayerTransform = null; } private void FreezePlayerInPlace() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_lockedPlayerTransform == (Object)null) { LockPlayer(); } if (!((Object)(object)_lockedPlayerTransform == (Object)null)) { _lockedPlayerTransform.position = _lockedPlayerPosition; _lockedPlayerTransform.rotation = _lockedPlayerRotation; ZeroPlayerVelocity(((Component)_lockedPlayerTransform).gameObject); } } private static Transform GetLocalPlayerTransform() { try { object? obj = AccessTools.Field(AccessTools.TypeByName("Player"), "m_localPlayer")?.GetValue(null); Component val = (Component)((obj is Component) ? obj : null); return ((Object)(object)val != (Object)null) ? val.transform : null; } catch { return null; } } private static void ZeroPlayerVelocity(GameObject go) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)go == (Object)null) { return; } try { Rigidbody component = go.GetComponent<Rigidbody>(); if ((Object)(object)component != (Object)null) { component.velocity = Vector3.zero; try { ((object)component).GetType().GetProperty("linearVelocity")?.SetValue(component, Vector3.zero, null); } catch { } component.angularVelocity = Vector3.zero; } } catch { } } private static void CloseVanillaBuildMenus() { try { Type type = AccessTools.TypeByName("Hud"); object obj = AccessTools.Field(type, "m_instance")?.GetValue(null); if (obj == null) { return; } string[] array = new string[4] { "HidePieceSelection", "ClosePieceSelection", "CloseBuildMenu", "HideBuildMenu" }; foreach (string text in array) { MethodInfo methodInfo = AccessTools.Method(type, text, (Type[])null, (Type[])null); if (methodInfo != null && methodInfo.GetParameters().Length == 0) { methodInfo.Invoke(obj, null); } } array = new string[4] { "m_buildSelection", "m_pieceSelectionWindow", "m_pieceSelectionRoot", "m_buildHud" }; foreach (string text2 in array) { FieldInfo fieldInfo = AccessTools.Field(type, text2); object? obj2 = ((fieldInfo != null) ? fieldInfo.GetValue(obj) : null); GameObject val = (GameObject)((obj2 is GameObject) ? obj2 : null); if ((Object)(object)val != (Object)null) { val.SetActive(false); } Component val2 = (Component)((obj2 is Component) ? obj2 : null); if ((Object)(object)val2 != (Object)null) { val2.gameObject.SetActive(false); } } } catch { } } private void EnterEditorCameraMode() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) ForceEditorCursor(); _gameCamera = Camera.main; if ((Object)(object)_gameCamera == (Object)null) { StatusText = "Keine Valheim-Kamera gefunden."; return; } Vector3 position = ((Component)_gameCamera).transform.position; Quaternion rotation = ((Component)_gameCamera).transform.rotation; Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles; _yaw = eulerAngles.y; _pitch = NormalizePitch(eulerAngles.x); _editorCameraObject = new GameObject("ValheimAxiom_EditorCamera"); _editorCameraObject.transform.position = position; _editorCameraObject.transform.rotation = rotation; _editorCamera = _editorCameraObject.AddComponent<Camera>(); _editorCamera.fieldOfView = _gameCamera.fieldOfView; _editorCamera.nearClipPlane = _gameCamera.nearClipPlane; _editorCamera.farClipPlane = _gameCamera.farClipPlane; _editorCamera.clearFlags = _gameCamera.clearFlags; _editorCamera.backgroundColor = _gameCamera.backgroundColor; _editorCamera.cullingMask = _gameCamera.cullingMask; _editorCamera.depth = _gameCamera.depth + 20f; ((Behaviour)_gameCamera).enabled = false; } private void ExitEditorCameraMode() { if ((Object)(object)_gameCamera != (Object)null) { ((Behaviour)_gameCamera).enabled = true; } if ((Object)(object)_editorCameraObject != (Object)null) { Object.Destroy((Object)(object)_editorCameraObject); } _editorCameraObject = null; _editorCamera = null; _gameCamera = null; Cursor.visible = false; Cursor.lockState = (CursorLockMode)1; } private void UpdateEditorCamera() { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) Camera val = (((Object)(object)_editorCamera != (Object)null) ? _editorCamera : Camera.main); if (!((Object)(object)val == (Object)null)) { if (Input.GetMouseButtonDown(1)) { _mouseLook = true; } if (Input.GetMouseButtonUp(1)) { _mouseLook = false; } ForceEditorCursor(); if (_mouseLook) { _yaw += Input.GetAxis("Mouse X") * 3f; _pitch -= Input.GetAxis("Mouse Y") * 3f; _pitch = Mathf.Clamp(_pitch, -85f, 85f); ((Component)val).transform.rotation = Quaternion.Euler(_pitch, _yaw, 0f); } float num = ((Plugin.BuilderFlySpeed != null) ? Plugin.BuilderFlySpeed.Value : 18f); if (Input.GetKey((KeyCode)304)) { num *= 3f; } if (Input.GetKey((KeyCode)306)) { num *= 0.35f; } Vector3 val2 = Vector3.zero; if (Input.GetKey((KeyCode)119)) { val2 += ((Component)val).transform.forward; } if (Input.GetKey((KeyCode)115)) { val2 -= ((Component)val).transform.forward; } if (Input.GetKey((KeyCode)100)) { val2 += ((Component)val).transform.right; } if (Input.GetKey((KeyCode)97)) { val2 -= ((Component)val).transform.right; } if (Input.GetKey((KeyCode)101)) { val2 += Vector3.up; } if (Input.GetKey((KeyCode)113)) { val2 -= Vector3.up; } if (((Vector3)(ref val2)).sqrMagnitude > 0.001f) { Transform transform = ((Component)val).transform; transform.position += ((Vector3)(ref val2)).normalized * num * Time.deltaTime; } } } public Ray GetEditorRay() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) Camera val = (((Object)(object)_editorCamera != (Object)null) ? _editorCamera : Camera.main); if ((Object)(object)val == (Object)null) { return new Ray(Vector3.zero, Vector3.forward); } return val.ScreenPointToRay(Input.mousePosition); } private static float NormalizePitch(float pitch) { if (pitch > 180f) { pitch -= 360f; } return pitch; } public static bool IsHammerEquipped() { try { Type type = AccessTools.TypeByName("Player"); if (type == null) { return false; } object obj = AccessTools.Field(type, "m_localPlayer")?.GetValue(null); if (obj == null) { return false; } object obj2 = AccessTools.Method(type, "GetRightItem", (Type[])null, (Type[])null)?.Invoke(obj, null); if (obj2 == null) { return false; } string text = GetItemDebugText(obj2).ToLowerInvariant(); return text.Contains("hammer") || text.Contains("$item_hammer") || text.Contains("item_hammer") || text.Contains("bauhammer"); } catch (Exception ex) { Debug.LogWarning((object)("[ValheimAxiom] Hammer-Erkennung fehlgeschlagen: " + ex.Message)); return false; } } private static string GetItemDebugText(object item) { string text = string.Empty; try { text = text + " " + item.ToString(); } catch { } try { object obj2 = item.GetType().GetField("m_shared", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(item); if (obj2 != null) { text = text + " " + ((obj2.GetType().GetField("m_name", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj2) as string) ?? string.Empty); text = text + " " + ((obj2.GetType().GetField("m_description", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj2) as string) ?? string.Empty); } } catch { } try { object obj4 = item.GetType().GetField("m_dropPrefab", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(item); GameObject val = (GameObject)((obj4 is GameObject) ? obj4 : null); if (val != null) { text = text + " " + ((Object)val).name; } else if (obj4 != null) { text = text + " " + obj4.ToString(); } } catch { } return text; } } public sealed class BuildPiecesBrowser : MonoBehaviour { private sealed class BuildPieceInfo { public readonly string Category; public readonly string DisplayName; public readonly string PrefabName; public readonly Texture2D Icon; public readonly GameObject Prefab; public BuildPieceInfo(string category, string displayName, string prefabName, Texture2D icon, GameObject prefab) { Category = category; DisplayName = displayName; PrefabName = prefabName; Icon = icon; Prefab = prefab; } } public string Search = string.Empty; private readonly List<BuildPieceInfo> _pieces = new List<BuildPieceInfo>(); private Vector2 _scroll; private float _lastRefresh; private GUIStyle _categoryStyle; private GUIStyle _entryButton; private GUIStyle _selectedButton; private GUIStyle _labelSmall; private Texture2D _emptyIcon; private Texture2D _selectedBg; public static BuildPiecesBrowser Instance { get; private set; } public bool IsOpen { get; set; } = true; public string SelectedPrefabName { get; private set; } = "wood_wall"; public string SelectedDisplayName { get; private set; } = "Holzwand"; public GameObject SelectedPrefab { get; private set; } public string StatusText { get; private set; } = "Bereit"; private void Awake() { Instance = this; } private void Update() { if (!((Object)(object)BuilderMode.Instance == (Object)null) && BuilderMode.Instance.IsActive && Time.realtimeSinceStartup - _lastRefresh > 3f && _pieces.Count == 0) { RefreshFromHammer(); } } public void DrawBrowser() { //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) EnsureStyles(); GUILayout.BeginVertical(Array.Empty<GUILayoutOption>()); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (GUILayout.Button(IsOpen ? "Palette" : "Palette öffnen", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) })) { IsOpen = !IsOpen; if (IsOpen) { RefreshFromHammer(); } } if (GUILayout.Button("↻", (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(38f), GUILayout.Height(28f) })) { RefreshFromHammer(); } GUILayout.EndHorizontal(); GUILayout.Label("Aktiv: " + SelectedDisplayName, _labelSmall, Array.Empty<GUILayoutOption>()); if (!IsOpen) { GUILayout.EndVertical(); return; } GUILayout.Space(4f); Search = GUILayout.TextField(Search ?? string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }); _scroll = GUILayout.BeginScrollView(_scroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(Mathf.Max(140f, (float)Screen.height - 225f)) }); string text = null; foreach (BuildPieceInfo filteredPiece in GetFilteredPieces()) { if (filteredPiece.Category != text) { GUILayout.Space(8f); GUILayout.Label(filteredPiece.Category, _categoryStyle, Array.Empty<GUILayoutOption>()); text = filteredPiece.Category; } bool flag = filteredPiece.PrefabName == SelectedPrefabName; GUILayout.BeginHorizontal(flag ? GUI.skin.box : GUIStyle.none, Array.Empty<GUILayoutOption>()); GUILayout.Label((Texture)(object)(((Object)(object)filteredPiece.Icon != (Object)null) ? filteredPiece.Icon : _emptyIcon), (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(42f), GUILayout.Height(42f) }); if (GUILayout.Button(filteredPiece.DisplayName, flag ? _selectedButton : _entryButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(42f) })) { SelectPiece(filteredPiece); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.Label(StatusText, _labelSmall, Array.Empty<GUILayoutOption>()); GUILayout.EndVertical(); } private void SelectPiece(BuildPieceInfo p) { SelectedPrefabName = p.PrefabName; SelectedDisplayName = p.DisplayName; SelectedPrefab = p.Prefab; StatusText = p.DisplayName; } private void EnsureStyles() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) if (_entryButton == null) { _selectedBg = MakeTex(new Color(0.08f, 0.28f, 0.58f, 1f)); _categoryStyle = new GUIStyle(GUI.skin.label); _categoryStyle.fontSize = 14; _categoryStyle.normal.textColor = new Color(0.85f, 0.92f, 1f, 1f); _labelSmall = new GUIStyle(GUI.skin.label); _labelSmall.normal.textColor = Color.white; _entryButton = new GUIStyle(GUI.skin.button); _entryButton.normal.textColor = Color.white; _entryButton.hover.textColor = Color.white; _selectedButton = new GUIStyle(GUI.skin.button); _selectedButton.normal.background = _selectedBg; _selectedButton.hover.background = _selectedBg; _selectedButton.active.background = _selectedBg; _selectedButton.normal.textColor = Color.white; _selectedButton.hover.textColor = Color.white; _selectedButton.active.textColor = Color.white; _emptyIcon = MakeTex(new Color(0.12f, 0.12f, 0.12f, 1f)); } } private static Texture2D MakeTex(Color c) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false); val.SetPixel(0, 0, c); val.Apply(); return val; } private IEnumerable<BuildPieceInfo> GetFilteredPieces() { string q = (Search ?? string.Empty).Trim().ToLowerInvariant(); foreach (BuildPieceInfo piece in _pieces) { if (q.Length == 0 || piece.DisplayName.ToLowerInvariant().Contains(q) || piece.PrefabName.ToLowerInvariant().Contains(q) || piece.Category.ToLowerInvariant().Contains(q)) { yield return piece; } } } public void RefreshFromHammer() { _lastRefresh = Time.realtimeSinceStartup; _pieces.Clear(); try { if (GetField(GetField(GetField(GetRightItem(), "m_shared"), "m_buildPieces"), "m_pieces") is IEnumerable enumerable) { foreach (object item in enumerable) { GameObject val = (GameObject)((item is GameObject) ? item : null); if (!((Object)(object)val == (Object)null)) { Component component = val.GetComponent(AccessTools.TypeByName("Piece")); if (!((Object)(object)component == (Object)null)) { string raw = GetField(component, "m_name") as string; string raw2 = Convert.ToString(GetField(component, "m_category")); Texture2D icon = TryGetIcon(component); string displayName = CleanDisplayName(raw, ((Object)val).name); raw2 = CleanCategory(raw2, ((Object)val).name); _pieces.Add(new BuildPieceInfo(raw2, displayName, ((Object)val).name, icon, val)); } } } } } catch (Exception ex) { StatusText = "Hammer-Bauteile konnten nicht gelesen werden: " + ex.Message; } if (_pieces.Count == 0) { AddFallbackPieces(); } _pieces.Sort(delegate(BuildPieceInfo a, BuildPieceInfo b) { int num = CategoryOrder(a.Category).CompareTo(CategoryOrder(b.Category)); if (num != 0) { return num; } int num2 = string.Compare(a.Category, b.Category, StringComparison.OrdinalIgnoreCase); return (num2 != 0) ? num2 : string.Compare(a.DisplayName, b.DisplayName, StringComparison.OrdinalIgnoreCase); }); if ((Object)(object)SelectedPrefab == (Object)null) { BuildPieceInfo buildPieceInfo = _pieces.Find((BuildPieceInfo p) => p.PrefabName == SelectedPrefabName) ?? ((_pieces.Count > 0) ? _pieces[0] : null); if (buildPieceInfo != null) { SelectPiece(buildPieceInfo); } } StatusText = _pieces.Count + " Bauteile geladen."; } private static int CategoryOrder(string cat) { string text = (cat ?? string.Empty).ToLowerInvariant(); if (text.Contains("holz")) { return 10; } if (text.Contains("stein")) { return 20; } if (text.Contains("dach")) { return 30; } if (text.Contains("tür") || text.Contains("tor")) { return 40; } if (text.Contains("möbel")) { return 50; } if (text.Contains("craft")) { return 60; } if (text.Contains("sonst")) { return 90; } return 70; } private static string CleanDisplayName(string raw, string prefabName) { string text = (string.IsNullOrEmpty(raw) ? prefabName : raw); text = text.Replace("$piece_", "").Replace("$item_", "").Replace("piece_", "") .Replace("item_", ""); text = text.Replace("wood", "Holz").Replace("stone", "Stein").Replace("blackmarble", "Schwarzmarmor"); text = text.Replace("wall", "Wand").Replace("floor", "Boden").Replace("beam", "Balken") .Replace("pole", "Pfosten") .Replace("roof", "Dach"); text = text.Replace("door", "Tür").Replace("gate", "Tor").Replace("stairs", "Treppe") .Replace("ladder", "Leiter"); text = text.Replace('_', ' '); while (text.Contains(" ")) { text = text.Replace(" ", " "); } text = text.Trim(); if (text.Length != 0) { return char.ToUpperInvariant(text[0]) + text.Substring(1); } return prefabName; } private static string CleanCategory(string raw, string prefabName) { string text = (prefabName ?? string.Empty).ToLowerInvariant(); if (text.Contains("grausten") || text.Contains("graustein")) { return "Graustein"; } if (text.Contains("wood")) { return "Holz"; } if (text.Contains("stone") || text.Contains("blackmarble") || text.Contains("marble")) { return "Stein"; } if (text.Contains("roof")) { return "Dach"; } if (text.Contains("door") || text.Contains("gate")) { return "Türen & Tore"; } if (string.IsNullOrEmpty(raw)) { return "Sonstiges"; } string text2 = raw.ToLowerInvariant(); if (text2.Contains("building")) { return "Bauen"; } if (text2.Contains("crafting")) { return "Crafting"; } if (text2.Contains("furniture")) { return "Möbel"; } if (text2.Contains("misc")) { return "Sonstiges"; } return raw.Replace('_', ' '); } private static Texture2D TryGetIcon(object piece) { try { object field = GetField(piece, "m_icon"); Sprite val = (Sprite)((field is Sprite) ? field : null); if ((Object)(object)val != (Object)null) { return val.texture; } } catch { } return null; } private static object GetRightItem() { Type type = AccessTools.TypeByName("Player"); object obj = AccessTools.Field(type, "m_localPlayer")?.GetValue(null); return AccessTools.Method(type, "GetRightItem", (Type[])null, (Type[])null)?.Invoke(obj, null); } private static object GetField(object obj, string name) { if (obj == null) { return null; } FieldInfo field = obj.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (!(field != null)) { return null; } return field.GetValue(obj); } private void AddFallbackPieces() { AddFallback("Holz", "Holzwand", "wood_wall"); AddFallback("Holz", "Holzboden 2x2", "wood_floor"); AddFallback("Holz", "Holzbalken", "wood_beam"); AddFallback("Holz", "Holzpfosten", "wood_pole"); AddFallback("Stein", "Steinwand", "stone_wall_2x1"); AddFallback("Stein", "Steinboden", "stone_floor"); AddFallback("Dach", "Strohdach 26", "piece_roof"); AddFallback("Möbel", "Werkbank", "piece_workbench"); StatusText = "Fallback-Liste geladen."; } private void AddFallback(string category, string display, string prefabName) { GameObject prefab = FindPrefab(prefabName); _pieces.Add(new BuildPieceInfo(category, display, prefabName, null, prefab)); } public static GameObject FindPrefab(string name) { try { Type type = AccessTools.TypeByName("ZNetScene"); if (type == null) { return null; } object obj = AccessTools.Field(type, "instance")?.GetValue(null); if (obj == null) { return null; } object? obj2 = AccessTools.Method(type, "GetPrefab", new Type[1] { typeof(string) }, (Type[])null)?.Invoke(obj, new object[1] { name }); return (GameObject)((obj2 is GameObject) ? obj2 : null); } catch { return null; } } } public enum EditorTool { Select, PlacePiece, ShapeSquare, ShapeCircle, Move, Rotate, Scale, Terrain, Paint, Blueprint, Settings } public sealed class EditorInput : MonoBehaviour { internal static ConfigEntry<KeyCode> MoveKey; internal static ConfigEntry<KeyCode> RotateKey; internal static ConfigEntry<KeyCode> ScaleKey; internal static ConfigEntry<KeyCode> ClearSelectionKey; public static EditorInput Instance { get; private set; } public EditorTool CurrentTool { get; private set; } public string WaitingForBinding { get; private set; } private void Awake() { Instance = this; MoveKey = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<KeyCode>("Input", "MoveTool", (KeyCode)103, "Move Tool auswählen."); RotateKey = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<KeyCode>("Input", "RotateTool", (KeyCode)114, "Rotate Tool auswählen."); ScaleKey = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<KeyCode>("Input", "ScaleTool", (KeyCode)116, "Scale Tool auswählen."); ClearSelectionKey = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<KeyCode>("Input", "ClearSelection", (KeyCode)27, "Auswahl aufheben."); } private void Update() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) if (EditorWindow.IsVisible && WaitingForBinding == null) { if (Input.GetKeyDown(MoveKey.Value)) { CurrentTool = EditorTool.Move; } if (Input.GetKeyDown(RotateKey.Value)) { CurrentTool = EditorTool.Rotate; } if (Input.GetKeyDown(ScaleKey.Value)) { CurrentTool = EditorTool.Scale; } } } private void OnGUI() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!EditorWindow.IsVisible || WaitingForBinding == null) { return; } Event current = Event.current; if (current != null && (int)current.type == 4) { KeyCode keyCode = current.keyCode; if ((int)keyCode != 0) { SetBinding(WaitingForBinding, keyCode); WaitingForBinding = null; Plugin.SaveConfigNow(); current.Use(); } } } public void SetTool(EditorTool tool) { CurrentTool = tool; } public void StartRebind(string bindingName) { WaitingForBinding = bindingName; } public static bool IsClearSelectionPressed() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (ClearSelectionKey != null) { return Input.GetKeyDown(ClearSelectionKey.Value); } return false; } private static void SetBinding(string bindingName, KeyCode key) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) switch (bindingName) { case "MoveTool": MoveKey.Value = key; break; case "RotateTool": RotateKey.Value = key; break; case "ScaleTool": ScaleKey.Value = key; break; case "ClearSelection": ClearSelectionKey.Value = key; break; } } } public sealed class EditorStagingMarker : MonoBehaviour { } public sealed class EditorWindow : MonoBehaviour { private sealed class GuiEnabledScope : IDisposable { private readonly bool _old; public GuiEnabledScope(bool enabled) { _old = GUI.enabled; GUI.enabled = enabled; } public void Dispose() { GUI.enabled = _old; } } private static bool _visible; private Rect _toolbarRect = new Rect(8f, 28f, 112f, 500f); private Rect _mainRect = new Rect(128f, 28f, 310f, 250f); private Rect _rightRect = new Rect(0f, 70f, 330f, 640f); private Vector2 _toolbarScroll; private Vector2 _mainScroll; private GUIStyle _window; private GUIStyle _button; private GUIStyle _activeButton; private GUIStyle _title; private GUIStyle _section; private Texture2D _bg; private Texture2D _panel; private Texture2D _blue; private Texture2D _cursor; private string _status = "Bereit"; public static bool IsVisible => _visible; public static Rect CurrentMainRect { get; private set; } public static Rect CurrentToolbarRect { get; private set; } public static Rect CurrentRightRect { get; private set; } public static bool IsMouseOverEditorGui { get { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (_visible) { Rect val = CurrentMainRect; if (!((Rect)(ref val)).Contains(EventSafeMousePosition())) { val = CurrentToolbarRect; if (!((Rect)(ref val)).Contains(EventSafeMousePosition())) { val = CurrentRightRect; return ((Rect)(ref val)).Contains(EventSafeMousePosition()); } } return true; } return false; } } public static void SetVisible(bool visible) { _visible = visible; } private static Vector2 EventSafeMousePosition() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) return new Vector2(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y); } private void OnGUI() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: 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_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) if (_visible) { EnsureStyles(); if ((Object)(object)BuilderMode.Instance != (Object)null) { BuilderMode.Instance.ForceEditorCursor(); } if (((Rect)(ref _rightRect)).x <= 0f || ((Rect)(ref _rightRect)).x > (float)(Screen.width - 60)) { ((Rect)(ref _rightRect)).x = (float)Screen.width - ((Rect)(ref _rightRect)).width - 8f; } _toolbarRect = GUI.Window(934200, _toolbarRect, new WindowFunction(DrawToolbar), "", _window); _mainRect = GUI.Window(934201, _mainRect, new WindowFunction(DrawWindow), "", _window); _rightRect = GUI.Window(934202, _rightRect, new WindowFunction(DrawRightPanel), "", _window); _toolbarRect = ResizeHandle(_toolbarRect, 88f, 250f, 170f, Screen.height - 20); _mainRect = ResizeHandle(_mainRect, 280f, 150f, 520f, Screen.height - 20); _rightRect = ResizeHandle(_rightRect, 260f, 260f, 540f, Screen.height - 20); CurrentToolbarRect = _toolbarRect; CurrentMainRect = _mainRect; CurrentRightRect = _rightRect; DrawSoftwareCursor(); } } private void EnsureStyles() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Expected O, but got Unknown //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Expected O, but got Unknown //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Expected O, but got Unknown if (_window == null) { _bg = MakeTex(new Color(0.018f, 0.02f, 0.024f, 0.96f)); _panel = MakeTex(new Color(0.05f, 0.055f, 0.065f, 0.98f)); _blue = MakeTex(new Color(0.08f, 0.25f, 0.58f, 1f)); _cursor = MakeTex(Color.white); _window = new GUIStyle(GUI.skin.window); _window.normal.background = _bg; _window.padding = new RectOffset(8, 8, 8, 8); _window.normal.textColor = Color.white; _button = new GUIStyle(GUI.skin.button); _button.normal.textColor = Color.white; _button.hover.textColor = Color.white; _button.fontSize = 12; _activeButton = new GUIStyle(_button); _activeButton.normal.background = _blue; _activeButton.hover.background = _blue; _activeButton.active.background = _blue; _title = new GUIStyle(GUI.skin.label); _title.fontSize = 18; _title.normal.textColor = Color.white; _section = new GUIStyle(GUI.skin.box); _section.normal.background = _panel; _section.normal.textColor = Color.white; _section.padding = new RectOffset(8, 8, 8, 8); } } private static Texture2D MakeTex(Color c) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false); val.SetPixel(0, 0, c); val.Apply(); return val; } private void DrawSoftwareCursor() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) Vector2 val = EventSafeMousePosition(); GUI.DrawTexture(new Rect(val.x, val.y, 8f, 8f), (Texture)(object)_cursor); } private void DrawToolbar(int id) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) EditorInput instance = EditorInput.Instance; GUILayout.Label("AXIOM", _title, Array.Empty<GUILayoutOption>()); if ((Object)(object)instance == (Object)null) { GUILayout.Label("Input fehlt", Array.Empty<GUILayoutOption>()); return; } _toolbarScroll = GUILayout.BeginScrollView(_toolbarScroll, Array.Empty<GUILayoutOption>()); DrawToolButton(instance, EditorTool.Select, "Select"); GUILayout.Space(8f); GUILayout.Label("Bauen", Array.Empty<GUILayoutOption>()); DrawToolButton(instance, EditorTool.PlacePiece, "Teil"); GUILayout.Space(8f); GUILayout.Label("Formen", Array.Empty<GUILayoutOption>()); DrawToolButton(instance, EditorTool.ShapeSquare, "Quadrat"); DrawToolButton(instance, EditorTool.ShapeCircle, "Kreis"); GUILayout.Space(8f); GUILayout.Label("Transform", Array.Empty<GUILayoutOption>()); DrawToolButton(instance, EditorTool.Move, "Move"); DrawToolButton(instance, EditorTool.Rotate, "Rotate"); DrawToolButton(instance, EditorTool.Scale, "Scale"); GUILayout.Space(8f); GUILayout.Label("Welt", Array.Empty<GUILayoutOption>()); DrawToolButton(instance, EditorTool.Terrain, "Terrain"); DrawToolButton(instance, EditorTool.Paint, "Paint"); DrawToolButton(instance, EditorTool.Blueprint, "Blueprint"); DrawToolButton(instance, EditorTool.Settings, "Prefs"); GUILayout.EndScrollView(); GUI.DragWindow(new Rect(0f, 0f, 10000f, 18f)); } private void DrawToolButton(EditorInput input, EditorTool tool, string label) { bool flag = input.CurrentTool == tool; if (GUILayout.Button(label, flag ? _activeButton : _button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) })) { input.SetTool(tool); } } private void DrawWindow(int id) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) GUILayout.Label("Valheim Editor", _title, Array.Empty<GUILayoutOption>()); _mainScroll = GUILayout.BeginScrollView(_mainScroll, Array.Empty<GUILayoutOption>()); EditorInput instance = EditorInput.Instance; BuilderMode instance2 = BuilderMode.Instance; if ((Object)(object)instance2 != (Object)null) { GUILayout.Label("Baumodus: " + (instance2.IsActive ? "AKTIV" : "AUS"), Array.Empty<GUILayoutOption>()); } if ((Object)(object)instance != (Object)null) { GUILayout.Label("Tool: " + instance.CurrentTool, Array.Empty<GUILayoutOption>()); } if ((Object)(object)instance2 != (Object)null) { GUILayout.Label(instance2.StatusText, Array.Empty<GUILayoutOption>()); } DrawBuildRuleToggles(); DrawSnapSettings(); DrawPiecePlacement(); DrawShapeBuilder(); DrawObjectSelection(); GUILayout.Label("Status: " + _status, Array.Empty<GUILayoutOption>()); GUILayout.EndScrollView(); GUI.DragWindow(new Rect(0f, 0f, 10000f, 18f)); } private void DrawRightPanel(int id) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) BuildPiecesBrowser instance = BuildPiecesBrowser.Instance; if ((Object)(object)instance != (Object)null) { instance.DrawBrowser(); } GUI.DragWindow(new Rect(0f, 0f, 10000f, 18f)); } private void DrawBuildRuleToggles() { GUILayout.BeginVertical(_section, Array.Empty<GUILayoutOption>()); bool value = Plugin.RespectVanillaBuildRules.Value; bool flag = GUILayout.Toggle(value, "Vanilla-Bauregeln", Array.Empty<GUILayoutOption>()); if (flag != value) { Plugin.RespectVanillaBuildRules.Value = flag; Plugin.SaveConfigNow(); _status = (flag ? "Vanilla-Bauregeln: AN" : "FreeBuild: AN"); } using (new GuiEnabledScope(!Plugin.RespectVanillaBuildRules.Value)) { UpdateToggle("Keine Stabilität", Plugin.NoStability, "No Stability"); UpdateToggle("Buildhöhe ignorieren", Plugin.IgnoreHeightLimit, "Buildhöhe ignorieren"); UpdateToggle("Material ignorieren", Plugin.FreeRequirements, "Free Requirements"); } GUILayout.EndVertical(); } private void DrawSnapSettings() { SnapSystem instance = SnapSystem.Instance; if (!((Object)(object)instance == (Object)null)) { GUILayout.BeginVertical(_section, Array.Empty<GUILayoutOption>()); GUILayout.Label("Snapping", Array.Empty<GUILayoutOption>()); instance.SnapEnabled = GUILayout.Toggle(instance.SnapEnabled, "Snappoints benutzen", Array.Empty<GUILayoutOption>()); instance.SnapRadius = GUILayout.HorizontalSlider(instance.SnapRadius, 0.15f, 2f, Array.Empty<GUILayoutOption>()); GUILayout.Label("Radius: " + instance.SnapRadius.ToString("0.00") + "m", Array.Empty<GUILayoutOption>()); GUILayout.Label(instance.StatusText, Array.Empty<GUILayoutOption>()); GUILayout.EndVertical(); } } private void UpdateToggle(string label, ConfigEntry<bool> entry, string statusLabel) { bool flag = GUILayout.Toggle(entry.Value, label, Array.Empty<GUILayoutOption>()); if (flag != entry.Value) { entry.Value = flag; Plugin.SaveConfigNow(); _status = statusLabel + ": " + (flag ? "AN" : "AUS"); } } private void DrawShapeBuilder() { SquareBuilder instance = SquareBuilder.Instance; if (!((Object)(object)instance == (Object)null)) { GUILayout.BeginVertical(_section, Array.Empty<GUILayoutOption>()); GUILayout.Label("Formen", Array.Empty<GUILayoutOption>()); GUILayout.Label("LMB baut, Mausrad Größe", Array.Empty<GUILayoutOption>()); instance.SquareSize = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)instance.SquareSize, 1f, 30f, Array.Empty<GUILayoutOption>())); GUILayout.Label("Radius/Größe: " + instance.SquareSize, Array.Empty<GUILayoutOption>()); instance.SquareHeight = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)instance.SquareHeight, 1f, 20f, Array.Empty<GUILayoutOption>())); GUILayout.Label("Höhe: " + instance.SquareHeight, Array.Empty<GUILayoutOption>()); instance.PieceSpacing = GUILayout.HorizontalSlider(instance.PieceSpacing, 0.5f, 4f, Array.Empty<GUILayoutOption>()); GUILayout.Label("Abstand: " + instance.PieceSpacing.ToString("0.0"), Array.Empty<GUILayoutOption>()); GUILayout.Label(instance.StatusText, Array.Empty<GUILayoutOption>()); GUILayout.EndVertical(); } } private void DrawPiecePlacement() { PiecePlacement instance = PiecePlacement.Instance; if (!((Object)(object)instance == (Object)null)) { GUILayout.BeginVertical(_section, Array.Empty<GUILayoutOption>()); GUILayout.Label("Platzieren", Array.Empty<GUILayoutOption>()); GUILayout.Label("LMB platziert, Mausrad rotiert", Array.Empty<GUILayoutOption>()); GUILayout.Label("Rotation: " + instance.RotationY.ToString("0") + "°", Array.Empty<GUILayoutOption>()); instance.RotationY = GUILayout.HorizontalSlider(instance.RotationY, 0f, 360f, Array.Empty<GUILayoutOption>()); GUILayout.Label(instance.StatusText, Array.Empty<GUILayoutOption>()); GUILayout.EndVertical(); } } private void DrawObjectSelection() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) GUILayout.BeginVertical(_section, Array.Empty<GUILayoutOption>()); GUILayout.Label("Selection", Array.Empty<GUILayoutOption>()); ObjectSelection instance = ObjectSelection.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.SelectedObject == (Object)null) { GUILayout.Label("Kein Objekt ausgewählt.", Array.Empty<GUILayoutOption>()); } else { Vector3 selectedPosition = instance.GetSelectedPosition(); Vector3 selectedRotationEuler = instance.GetSelectedRotationEuler(); Vector3 selectedScale = instance.GetSelectedScale(); GUILayout.Label("Name: " + instance.GetSelectedName(), Array.Empty<GUILayoutOption>()); GUILayout.Label($"Pos: {selectedPosition.x:0.00}, {selectedPosition.y:0.00}, {selectedPosition.z:0.00}", Array.Empty<GUILayoutOption>()); GUILayout.Label($"Rot: {selectedRotationEuler.x:0}, {selectedRotationEuler.y:0}, {selectedRotationEuler.z:0}", Array.Empty<GUILayoutOption>()); GUILayout.Label($"Scale: {selectedScale.x:0.00}, {selectedScale.y:0.00}, {selectedScale.z:0.00}", Array.Empty<GUILayoutOption>()); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (GUILayout.Button("X-", Array.Empty<GUILayoutOption>())) { instance.Nudge(new Vector3(-0.25f, 0f, 0f)); } if (GUILayout.Button("X+", Array.Empty<GUILayoutOption>())) { instance.Nudge(new Vector3(0.25f, 0f, 0f)); } if (GUILayout.Button("Y-", Array.Empty<GUILayoutOption>())) { instance.Nudge(new Vector3(0f, -0.25f, 0f)); } if (GUILayout.Button("Y+", Array.Empty<GUILayoutOption>())) { instance.Nudge(new Vector3(0f, 0.25f, 0f)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (GUILayout.Button("Z-", Array.Empty<GUILayoutOption>())) { instance.Nudge(new Vector3(0f, 0f, -0.25f)); } if (GUILayout.Button("Z+", Array.Empty<GUILayoutOption>())) { instance.Nudge(new Vector3(0f, 0f, 0.25f)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (GUILayout.Button("Rot -15", Array.Empty<GUILayoutOption>())) { instance.RotateY(-15f); } if (GUILayout.Button("Rot +15", Array.Empty<GUILayoutOption>())) { instance.RotateY(15f); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (GUILayout.Button("Scale -", Array.Empty<GUILayoutOption>())) { instance.ScaleUniform(0.9f); } if (GUILayout.Button("Scale +", Array.Empty<GUILayoutOption>())) { instance.ScaleUniform(1.1f); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (GUILayout.Button("Delete", Array.Empty<GUILayoutOption>())) { instance.DeleteSelected(); } if (GUILayout.Button("Clear", Array.Empty<GUILayoutOption>())) { instance.ClearSelection(); } GUILayout.EndHorizontal(); } if ((Object)(object)instance != (Object)null && !string.IsNullOrEmpty(instance.StatusText)) { GUILayout.Label(instance.StatusText, Array.Empty<GUILayoutOption>()); } GUILayout.EndVertical(); } private static Rect ResizeHandle(Rect rect, float minW, float minH, float maxW, float maxH) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref rect)).xMax - 18f, ((Rect)(ref rect)).yMax - 18f, 18f, 18f); GUI.Label(val, "◢"); Event current = Event.current; if (current != null && (int)current.type == 3 && ((Rect)(ref val)).Contains(current.mousePosition)) { ((Rect)(ref rect)).width = Mathf.Clamp(((Rect)(ref rect)).width + current.delta.x, minW, maxW); ((Rect)(ref rect)).height = Mathf.Clamp(((Rect)(ref rect)).height + current.delta.y, minH, maxH); current.Use(); } return rect; } } internal static class FreeBuildReflection { internal const float HugeSupport = 999999f; private static readonly Dictionary<Type, Dictionary<string, FieldInfo>> FieldCache = new Dictionary<Type, Dictionary<string, FieldInfo>>(); private static float _nextPlacementPatchTime; internal static IEnumerable<MethodInfo> MethodsByReturn(string typeName, Type returnType, params string[] names) { Type type = AccessTools.TypeByName(typeName); if (type == null) { yield break; } HashSet<string> wanted = new HashSet<string>(names); foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(type)) { if (wanted.Contains(declaredMethod.Name) && !(declaredMethod.ReturnType != returnType)) { yield return declaredMethod; } } } internal static IEnumerable<MethodInfo> VoidMethods(string typeName, params string[] names) { Type type = AccessTools.TypeByName(typeName); if (type == null) { yield break; } HashSet<string> wanted = new HashSet<string>(names); foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(type)) { if (wanted.Contains(declaredMethod.Name) && !(declaredMethod.ReturnType != typeof(void))) { yield return declaredMethod; } } } internal static void ForceStableCached(object instance) { if (instance != null) { TrySetFieldCached(instance, "m_support", 999999f); TrySetFieldCached(instance, "m_maxSupport", 999999f); TrySetFieldCached(instance, "m_unsupported", false); } } internal static void TrySetFieldCached(object instance, string fieldName, object value) { try { FieldInfo field = GetField(instance.GetType(), fieldName); if (!(field == null) && (value != null || !field.FieldType.IsValueType)) { if (field.FieldType == typeof(float) && value is float num) { field.SetValue(instance, num); } else if (field.FieldType == typeof(bool) && value is bool flag) { field.SetValue(instance, flag); } else if (value == null || field.FieldType.IsInstanceOfType(value)) { field.SetValue(instance, value); } } } catch { } } private static FieldInfo GetField(Type type, string fieldName) { if (type == null) { return null; } if (!FieldCache.TryGetValue(type, out var value)) { value = new Dictionary<string, FieldInfo>(); FieldCache[type] = value; } if (!value.TryGetValue(fieldName, out var value2)) { Type type2 = type; while (type2 != null && value2 == null) { value2 = type2.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); type2 = type2.BaseType; } value[fieldName] = value2; } return value2; } internal static void ForcePlacementValidThrottled(object player) { if (player == null || !Plugin.FreeBuildEnabled || Time.realtimeSinceStartup < _nextPlacementPatchTime) { return; } _nextPlacementPatchTime = Time.realtimeSinceStartup + 0.25f; try { FieldInfo field = GetField(player.GetType(), "m_placementStatus"); if (field != null && field.FieldType.IsEnum) { object value; try { value = Enum.Parse(field.FieldType, "Valid"); } catch { value = Enum.GetValues(field.FieldType).GetValue(0); } field.SetValue(player, value); } } catch { } } } [HarmonyPatch] public static class WearNTearBoolPatches { public static IEnumerable<MethodBase> TargetMethods() { return FreeBuildReflection.MethodsByReturn("WearNTear", typeof(bool), "HaveSupport", "IsSupported", "CanBeRemoved", "CanBeRotated"); } public static void Postfix(ref bool __result) { if (Plugin.ShouldDisableStability) { __result = true; } } } [HarmonyPatch] public static class WearNTearFloatPatches { public static IEnumerable<MethodBase> TargetMethods() { return FreeBuildReflection.MethodsByReturn("WearNTear", typeof(float), "GetSupport", "GetMaxSupport", "GetWear", "GetHealthPercentage"); } public static void Postfix(MethodBase __originalMethod, ref float __result) { if (Plugin.FreeBuildEnabled) { string text = __originalMethod?.Name ?? string.Empty; if ((text == "GetSupport" || text == "GetMaxSupport") && (Plugin.ShouldDisableStability || Plugin.ShouldIgnoreHeightLimit)) { __result = 999999f; } if (text == "GetWear" && Plugin.ShouldDisableStability) { __result = 0f; } } } } [HarmonyPatch] public static class WearNTearDamagePatches { public static IEnumerable<MethodBase> TargetMethods() { return FreeBuildReflection.VoidMethods("WearNTear", "ApplyDamage", "Destroy", "Remove"); } public static bool Prefix(object __instance) { if (!Plugin.ShouldDisableStability) { return true; } FreeBuildReflection.ForceStableCached(__instance); return true; } } [HarmonyPatch] public static class PlayerBoolPatches { public static IEnumerable<MethodBase> TargetMethods() { return FreeBuildReflection.MethodsByReturn("Player", typeof(bool), "HaveRequirements", "CheckCanRemovePiece", "CheckCanBuild"); } public static void Postfix(MethodBase __originalMethod, ref bool __result) { if (Plugin.FreeBuildEnabled && (!((__originalMethod?.Name ?? string.Empty) == "HaveRequirements") || Plugin.ShouldIgnoreRequirements)) { __result = true; } } } [HarmonyPatch] public static class PlayerPlacementGhostPatches { public static IEnumerable<MethodBase> TargetMethods() { return FreeBuildReflection.VoidMethods("Player", "UpdatePlacement", "UpdatePlacementGhost", "SetupPlacementGhost"); } public static void Postfix(object __instance) { FreeBuildReflection.ForcePlacementValidThrottled(__instance); } } [HarmonyPatch] public static class PrivateAreaPatches { public static IEnumerable<MethodBase> TargetMethods() { return FreeBuildReflection.MethodsByReturn("PrivateArea", typeof(bool), "CheckAccess"); } public static void Postfix(ref bool __result) { if (Plugin.FreeBuildEnabled) { __result = true; } } } internal static class EditorStagingWearNTearHelper { internal static bool IsUnnetworkedStaging(WearNTear wear) { if ((Object)(object)wear == (Object)null) { return false; } GameObject gameObject = ((Component)wear).gameObject; if ((Object)(object)gameObject == (Object)null) { return false; } if ((Object)(object)((Component)wear).GetComponentInParent<EditorStagingMarker>() != (Object)null) { return true; } if (HasStaleWearNetworkView(wear)) { return true; } ZNetView component = gameObject.GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null) { return true; } if (!((Behaviour)component).enabled) { return true; } try { MethodInfo methodInfo = AccessTools.Method(typeof(ZNetView), "GetZDO", (Type[])null, (Type[])null); if (methodInfo == null) { return true; } return methodInfo.Invoke(component, null) == null; } catch { return true; } } private static bool HasStaleWearNetworkView(WearNTear wear) { try { FieldInfo fieldInfo = AccessTools.Field(typeof(WearNTear), "m_nview"); if (fieldInfo == null) { return false; } object value = fieldInfo.GetValue(wear); if (value == null) { return true; } ZNetView val = (ZNetView)((value is ZNetView) ? value : null); if ((Object)(object)val == (Object)null) { return false; } if ((Object)(object)val == (Object)null) { return true; } return (Object)(object)((Component)val).gameObject != (Object)(object)((Component)wear).gameObject; } catch { return false; } } internal static bool ShouldSkipWearUpdate(WearNTear wear) { if ((Object)(object)wear == (Object)null) { return true; } if (IsUnnetworkedStaging(wear)) { return true; } if (!((Behaviour)wear).enabled) { return true; } return false; } } [HarmonyPatch] internal static class WearNTearDamageEditorStagingPatch { private static IEnumerable<MethodBase> TargetMethods() { return FreeBuildReflection.VoidMethods("WearNTear", "Damage"); } private static bool Prefix(WearNTear __instance) { return !EditorStagingWearNTearHelper.IsUnnetworkedStaging(__instance); } } [HarmonyPatch(typeof(WearNTear), "Awake")] public static class WearNTearAwakeEditorStagingPatch { private static bool Prefix(WearNTear __instance) { if ((Object)(object)__instance == (Object)null) { return true; } if (!((Object)(object)((Component)__instance).GetComponentInParent<EditorStagingMarker>() != (Object)null) && !((Object)(object)((Component)__instance).GetComponent<ZNetView>() == (Object)null)) { return true; } FreeBuildReflection.ForceStableCached(__instance); return false; } } [HarmonyPatch(typeof(WearNTear), "GetSupport")] public static class WearNTearGetSupportEditorStagingPatch { private static bool Prefix(WearNTear __instance, ref float __result) { if (!EditorStagingWearNTearHelper.ShouldSkipWearUpdate(__instance)) { return true; } __result = 999999f; return false; } } [HarmonyPatch(typeof(WearNTear), "GetMaxSupport")] public static class WearNTearGetMaxSupportEditorStagingPatch { private static bool Prefix(WearNTear __instance, ref float __result) { if (!EditorStagingWearNTearHelper.ShouldSkipWearUpdate(__instance)) { return true; } __result = 999999f; return false; } } [HarmonyPatch(typeof(WearNTear), "GetHealthPercentage")] public static class WearNTearGetHealthPercentageEditorStagingPatch { private static bool Prefix(WearNTear __instance, ref float __result) { if (!EditorStagingWearNTearHelper.ShouldSkipWearUpdate(__instance)) { return true; } __result = 1f; return false; } } [HarmonyPatch(typeof(Hud), "UpdateCrosshair")] public static class HudUpdateCrosshairEditorStagingPatch { private static bool Prefix() { return !EditorState.IsActive; } } [HarmonyPatch(typeof(WearNTear), "UpdateSupport")] public static class WearNTearUpdateSupportEditorStagingPatch { private static bool Prefix(WearNTear __instance) { return !EditorStagingWearNTearHelper.ShouldSkipWearUpdate(__instance); } } [HarmonyPatch(typeof(WearNTear), "UpdateWear")] public static class WearNTearUpdateWearEditorStagingPatch { private static bool Prefix(WearNTear __instance) { return !EditorStagingWearNTearHelper.ShouldSkipWearUpdate(__instance); } } [HarmonyPatch(typeof(WearNTear), "UpdateCover")] public static class WearNTearUpdateCoverEditorStagingPatch { private static bool Prefix(WearNTear __instance) { return !EditorStagingWearNTearHelper.ShouldSkipWearUpdate(__instance); } } [HarmonyPatch(typeof(WearNTear), "UpdateAshlandsMaterialValues")] public static class WearNTearUpdateAshlandsMaterialValuesEditorStagingPatch { private static bool Prefix(WearNTear __instance) { return !EditorStagingWearNTearHelper.ShouldSkipWearUpdate(__instance); } } [HarmonyPatch] public static class WearNTearUpdaterEditorStagingPatch { private static MethodBase TargetMethod() { Type type = AccessTools.TypeByName("WearNTearUpdater"); if (type == null) { return null; } return AccessTools.Method(type, "UpdateWearNTear", new Type[2] { typeof(float), typeof(float) }, (Type[])null); } private static bool Prefix() { return !EditorState.IsActive; } } [HarmonyPatch] public static class TreeBaseAwakeEditorStagingPatch { private static MethodBase TargetMethod() { Type type = AccessTools.TypeByName("TreeBase"); if (type == null) { return null; } return AccessTools.Method(type, "Awake", (Type[])null, (Type[])null); } private static bool Prefix(MonoBehaviour __instance) { if ((Object)(object)__instance == (Object)null) { return true; } return (Object)(object)((Component)__instance).GetComponentInParent<EditorStagingMarker>() == (Object)null; } } internal static class InputBlockRules { public static bool IsBuilderActive => false; public static bool ShouldBlock(string name) { return false; } } public sealed class ObjectSelection : MonoBehaviour { private GameObject _selectionGlow; private Material _glowMaterial; private readonly List<Material[]> _originalMaterials = new List<Material[]>(); private float _nextStatusTime; public static ObjectSelection Instance { get; private set; } public GameObject SelectedObject { get; private set; } public string StatusText { get; private set; } = "Kein Objekt ausgewählt"; private void Awake() { Instance = this; } private void Update() { if (!((Object)(object)BuilderMode.Instance == (Object)null) && BuilderMode.Instance.IsActive) { EditorInput instance = EditorInput.Instance; if (((Object)(object)instance == (Object)null || instance.CurrentTool == EditorTool.Select) && Input.GetMouseButtonDown(0) && !EditorWindow.IsMouseOverEditorGui) { TrySelectObjectUnderMouse(); } if (Input.GetKeyDown((KeyCode)127) && (Object)(object)SelectedObject != (Object)null) { DeleteSelected(); } if (EditorInput.IsClearSelectionPressed() && (Object)(object)SelectedObject != (Object)null) { ClearSelection(); } UpdateGlowTransform(); } } private void TrySelectObjectUnderMouse() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) Camera val = (((Object)(object)BuilderMode.Instance != (Object)null) ? BuilderMode.Instance.EditorCamera : Camera.main); if ((Object)(object)val == (Object)null) { SetStatus("Keine Editor-Kamera gefunden."); return; } RaycastHit val2 = default(RaycastHit); if (!Physics.Raycast(((Object)(object)BuilderMode.Instance != (Object)null) ? BuilderMode.Instance.GetEditorRay() : val.ScreenPointToRay(Input.mousePosition), ref val2, 500f, -1, (QueryTriggerInteraction)1)) { ClearSelection(); SetStatus("Nichts getroffen."); return; } GameObject val3 = (((Object)(object)((RaycastHit)(ref val2)).collider != (Object)null) ? ((Component)((RaycastHit)(ref val2)).collider).gameObject : ((Component)((RaycastHit)(ref val2)).transform).gameObject); if (!((Object)(object)val3 != (Object)null) || !((Object)val3).name.StartsWith("ValheimAxiom_SelectGlow_")) { GameObject val4 = ResolveValheimObject(val3); if ((Object)(object)val4 == (Object)null) { ClearSelection(); SetStatus("Treffer konnte keinem Objekt zugeordnet werden."); } else { SelectedObject = val4; RebuildSelectionGlow(); SetStatus("Ausgewählt: " + GetDisplayName(val4)); } } } private static GameObject ResolveValheimObject(GameObject hitObject) { if ((Object)(object)hitObject == (Object)null) { return null; } if (((Object)hitObject).name.StartsWith("ValheimAxiom_")) { return null; } string[] array = new string[8] { "Piece", "WearNTear", "TreeBase", "MineRock", "Destructible", "Pickable", "ItemDrop", "ZNetView" }; for (int i = 0; i < array.Length; i++) { Type type = AccessTools.TypeByName(array[i]); if (!(type == null)) { Component componentInParent = hitObject.GetComponentInParent(type); if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.gameObject != (Object)null && !((Object)componentInParent.gameObject).name.StartsWith("ValheimAxiom_")) { return componentInParent.gameObject; } } } return hitObject; } public void ClearSelection() { SelectedObject = null; DestroySelectionGlow(); SetStatus("Auswahl aufgehoben."); } public void DeleteSelected() { if ((Object)(object)SelectedObject == (Object)null) { return; } string displayName = GetDisplayName(SelectedObject); try { GameObject selectedObject = SelectedObject; SelectedObject = null; DestroySelectionGlow(); Object.Destroy((Object)(object)selectedObject); SetStatus("Gelöscht: " + displayName); } catch (Exception ex) { SetStatus("Löschen fehlgeschlagen: " + ex.Message); } } public void Nudge(Vector3 delta) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)SelectedObject == (Object)null)) { Transform transform = SelectedObject.transform; transform.position += delta; TouchNetworkTransform(SelectedObject); SetStatus("Verschoben: " + GetDisplayName(SelectedObject)); } } public void RotateY(float degrees) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)SelectedObject == (Object)null)) { SelectedObject.transform.Rotate(Vector3.up, degrees, (Space)0); TouchNetworkTransform(SelectedObject); SetStatus("Gedreht: " + degrees.ToString("0") + "°"); } } public void ScaleUniform(float factor) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)SelectedObject == (Object)null)) { Transform transform = SelectedObject.transform; transform.localScale *= factor; SetStatus("Skaliert: x" + factor.ToString("0.00")); } } public string GetSelectedName() { if (!((Object)(object)SelectedObject == (Object)null)) { return GetDisplayName(SelectedObject); } return "-"; } public Vector3 GetSelectedPosition() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)SelectedObject == (Object)null)) { return SelectedObject.transform.position; } return Vector3.zero; } public Vector3 GetSelectedRotationEuler() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)SelectedObject == (Object)null)) { Quaternion rotation = SelectedObject.transform.rotation; return ((Quaternion)(ref rotation)).eulerAngles; } return Vector3.zero; } public Vector3 GetSelectedScale() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)SelectedObject == (Object)null)) { return SelectedObject.transform.localScale; } return Vector3.one; } private static string GetDisplayName(GameObject obj) { if ((Object)(object)obj == (Object)null) { return "-"; } string text = ((Object)obj).name ?? "Objekt"; int num = text.IndexOf("(Clone)", StringComparison.OrdinalIgnoreCase); if (num >= 0) { text = text.Substring(0, num).Trim(); } return text; } private void SetStatus(string text) { StatusText = text; _nextStatusTime = Time.realtimeSinceStartup + 4f; } private void LateUpdate() { if (!((Object)(object)BuilderMode.Instance == (Object)null) && BuilderMode.Instance.IsActive) { if (Time.realtimeSinceStartup > _nextStatusTime && (Object)(object)SelectedObject != (Object)null) { StatusText = "Ausgewählt: " + GetDisplayName(SelectedObject); } UpdateGlowTransform(); } } private void RebuildSelectionGlow() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) DestroySelectionGlow(); if ((Object)(object)SelectedObject == (Object)null) { return; } try { _selectionGlow = Object.Instantiate<GameObject>(SelectedObject, SelectedObject.transform.position, SelectedObject.transform.rotation); ((Object)_selectionGlow).name = "ValheimAxiom_SelectGlow_" + GetDisplayName(SelectedObject); _selectionGlow.transform.localScale = SelectedObject.transform.lossyScale; MakeGlowSafe(_selectionGlow); ApplyGlowMaterial(_selectionGlow); } catch (Exception ex) { DestroySelectionGlow(); SetStatus("Auswahl-Glow fehlgeschlagen: " + ex.Message); } } private void UpdateGlowTransform() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)SelectedObject == (Object)null) && !((Object)(object)_selectionGlow == (Object)null)) { _selectionGlow.transform.position = SelectedObject.transform.position; _selectionGlow.transform.rotation = SelectedObject.transform.rotation; _selectionGlow.transform.localScale = SelectedObject.transform.lossyScale; } } private void DestroySelectionGlow() { if ((Object)(object)_selectionGlow != (Object)null) { Object.Destroy((Object)(object)_selectionGlow); } _selectionGlow = null; _originalMaterials.Clear(); } private void MakeGlowSafe(GameObject go) { Collider[] componentsInChildren = go.GetComponentsInChildren<Collider>(true); foreach (Collider val in componentsInChildren) { if ((Object)(object)val != (Object)null) { val.enabled = false; } } Rigidbody[] componentsInChildren2 = go.GetComponentsInChildren<Rigidbody>(true); foreach (Rigidbody val2 in componentsInChildren2) { if ((Object)(object)val2 != (Object)null) { val2.isKinematic = true; } } string[] array = new string[7] { "ZNetView", "WearNTear", "Piece", "Container", "CraftingStation", "ItemDrop", "Destructible" }; for (int i = 0; i < array.Length; i++) { Type type = AccessTools.TypeByName(array[i]); if (type == null) { continue; } Component[] componentsInChildren3 = go.GetComponentsInChildren(type, true); foreach (Component val3 in componentsInChildren3) { if ((Object)(object)val3 != (Object)null) { Object.Destroy((Object)(object)val3); } } } } private void ApplyGlowMaterial(GameObject go) { EnsureGlowMaterial(); if ((Object)(object)_glowMaterial == (Object)null || (Object)(object)go == (Object)null) { return; } Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { Material[] array = (Material[])(object)new Material[val.sharedMaterials.Length]; for (int j = 0; j < array.Length; j++) { array[j] = _glowMaterial; } val.sharedMaterials = array; val.enabled = true; } } } private void EnsureGlowMaterial() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_0068: 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 ((Object)(object)_glowMaterial != (Object)null) { return; } Shader val = Shader.Find("Standard") ?? Shader.Find("Hidden/Internal-Colored"); if ((Object)(object)val == (Object)null) { return; } _glowMaterial = new Material(val); ((Object)_glowMaterial).name = "ValheimAxiom_SelectedBlueGlow"; _glowMaterial.color = new Color(0.05f, 0.45f, 1f, 0.42f); try { _glowMaterial.EnableKeyword("_EMISSION"); _glowMaterial.SetColor("_EmissionColor", new Color(0f, 0.75f, 1f, 1f)); _glowMaterial.SetInt("_SrcBlend", 5); _glowMaterial.SetInt("_DstBlend", 10); _glowMaterial.SetInt("_ZWrite", 0); _glowMaterial.EnableKeyword("_ALPHABLEND_ON"); _glowMaterial.renderQueue = 3000; } catch { } } private static void TouchNetworkTransform(GameObject obj) { } } public sealed class PiecePlacement : MonoBehaviour { public float RotationY; private Vector3 _previewPos; private bool _hasPreview; private bool _isSnapped; private GameObject _previewPrefab; private GameObject _previewObject; private string _previewName; public static PiecePlacement Instance { get; private set; } public string StatusText { get; private set; } = "Bereit"; private void Awake() { Instance = this; } private void Update() { //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)BuilderMode.Instance != (Object)null) || !BuilderMode.Instance.IsActive || !((Object)(object)EditorInput.Instance != (Object)null) || EditorInput.Instance.CurrentTool != EditorTool.PlacePiece) { DestroyPreview(); return; } float axis = Input.GetAxis("Mouse ScrollWheel"); if (Mathf.Abs(axis) > 0.001f && !EditorWindow.IsMouseOverEditorGui) { RotationY += ((axis > 0f) ? 15f : (-15f)); if (RotationY < 0f) { RotationY += 360f; } if (RotationY >= 360f) { RotationY -= 360f; } } _previewPrefab = GetSelectedPrefab(); _hasPreview = TryGetPlacementPoint(out _previewPos); if (_hasPreview && (Object)(object)_previewPrefab != (Object)null && (Object)(object)SnapSystem.Instance != (Object)null) { _previewPos = SnapSystem.Instance.ResolvePlacement(_previewPrefab, _previewPos, Quaternion.Euler(0f, RotationY, 0f), out _isSnapped); } else { _isSnapped = false; } UpdatePreviewObject(); if (Input.GetMouseButtonDown(0) && !EditorWindow.IsMouseOverEditorGui) { PlaceCurrentPiece(); } } private void PlaceCurrentPiece() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_previewPrefab == (Object)null) { StatusText = "Kein Bauteil ausgewählt oder Prefab nicht gefunden."; return; } if (!_hasPreview) { StatusText = "Kein Zielpunkt vor der Kamera."; return; } GameObject val = InstantiateValheimPiece(_previewPrefab, _previewPos, Quaternion.Euler(0f, RotationY, 0f)); if ((Object)(object)val == (Object)null) { StatusText = "Platzieren fehlgeschlagen: " + ((Object)_previewPrefab).name; return; } ((Object)val).name = ((Object)_previewPrefab).name; StatusText = "Platziert: " + CleanName(((Object)_previewPrefab).name) + (_isSnapped ? " (Snap)" : ""); } private void UpdatePreviewObject() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) if (!_hasPreview || (Object)(object)_previewPrefab == (Object)null) { DestroyPreview(); return; } if ((Object)(object)_previewObject == (Object)null || _previewName != ((Object)_previewPrefab).name) { DestroyPreview(); _previewObject = Object.Instantiate<GameObject>(_previewPrefab, _previewPos, Quaternion.Euler(0f, RotationY, 0f)); _previewName = ((Object)_previewPrefab).name; ((Object)_previewObject).name = "ValheimAxiom_Preview_" + ((Object)_previewPrefab).name; MakePreviewSafe(_previewObject); } _previewObject.transform.position = _previewPos; _previewObject.transform.rotation = Quaternion.Euler(0f, RotationY, 0f); } private void DestroyPreview() { if ((Object)(object)_previewObject != (Object)null) { Object.Destroy((Object)(object)_previewObject); } _previewObject = null; _previewName = null; } private GameObject GetSelectedPrefab() { BuildPiecesBrowser instance = BuildPiecesBrowser.Instance; if ((Object)(object)instance != (Object)null) { if ((Object)(object)instance.SelectedPrefab != (Object)null) { return instance.SelectedPrefab; } GameObject val = BuildPiecesBrowser.FindPrefab(instance.SelectedPrefabName); if ((Object)(object)val != (Object)null) { return val; } } return BuildPiecesBrowser.FindPrefab("wood_wall") ?? BuildPiecesBrowser.FindPrefab("wood_floor"); } private bool TryGetPlacementPoint(out Vector3 point) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) point = Vector3.zero; RaycastHit val = default(RaycastHit); if (Physics.Raycast((Ray)(((Object)(object)BuilderMode.Instance != (Object)null) ? BuilderMode.Instance.GetEditorRay() : new Ray(Vector3.zero, Vector3.forward)), ref val, 500f, -1, (QueryTriggerInteraction)1)) { if ((Object)(object)((RaycastHit)(ref val)).collider != (Object)null && ((Object)((Component)((RaycastHit)(ref val)).collider).gameObject).name.StartsWith("ValheimAxiom_")) { Camera val2 = (((Object)(object)BuilderMode.Instance != (Object)null) ? BuilderMode.Instance.EditorCamera : Camera.main); point = (((Object)(object)val2 != (Object)null) ? (((Component)val2).transform.position + ((Component)val2).transform.forward * 6f) : ((RaycastHit)(ref val)).point); return true; } point = ((RaycastHit)(ref val)).point; return true; } Camera val3 = (((Object)(object)BuilderMode.Instance != (Object)null) ? BuilderMode.Instance.EditorCamera : Camera.main); if ((Object)(object)val3 == (Object)null) { return false; } point = ((Component)val3).transform.position + ((Component)val3).transform.forward * 6f; return true; } public static GameObject InstantiateValheimPiece(GameObject prefab, Vector3 pos, Quaternion rot) { //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) try { Type type = AccessTools.TypeByName("ZNetScene"); object obj = ((!(type != null)) ? null : AccessTools.Field(type, "instance")?.GetValue(null)); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Instantiate", new Type[3] { typeof(GameObject), typeof(Vector3), typeof(Quaternion) }, (Type[])null) : null); if (obj != null && methodInfo != null) { object? obj2 = methodInfo.Invoke(obj, new object[3] { prefab, pos, rot }); GameObject val = (GameObject)((obj2 is GameObject) ? obj2 : null); if ((Object)(object)val != (Object)null) { return val; } } } catch { } try { return Object.Instantiate<GameObject>(prefab, pos, rot); } catch { return null; } } private void MakePreviewSafe(GameObject go) { if ((Object)(object)go == (Object)null) { return; } Collider[] componentsInChildren = go.GetComponentsInChildren<Collider>(true); foreach (Collider val in componentsInChildren) { if ((Object)(object)val != (Object)null) { val.enabled = false; } } Rigidbody[] componentsInChildren2 = go.GetComponentsInChildren<Rigidbody>(true); foreach (Rigidbody val2 in componentsInChildren2) { if ((Object)(object)val2 != (Object)null) { val2.isKinematic = true; } } string[] array = new string[5] { "ZNetView", "WearNTear", "Piece", "Container", "CraftingStation" }; for (int i = 0; i < array.Length; i++) { Type type = AccessTools.TypeByName(array[i]); if (type == null) { continue; } Component[] componentsInChildren3 = go.GetComponentsInChildren(type, true); foreach (Component val3 in componentsInChildren3) { if ((Object)(object)val3 != (Object)null) { Object.Destroy((Object)(object)val3); } } } } private static string CleanName(string name) { if (string.IsNullOrEmpty(name)) { return "Bauteil"; } return name.Replace("$piece_", "").Replace("piece_", "").Replace('_', ' '); } } [BepInPlugin("de.danielsaar.valheimaxiom", "Valheim Axiom", "0.15.5")] public sealed class Plugin : BaseUnityPlugin { public const string PluginGuid = "de.danielsaar.valheimaxiom"; public const string PluginName = "Valheim Axiom"; public const string PluginVersion = "0.15.5"; internal static Plugin Instance; internal static ConfigEntry<bool> RespectVanillaBuildRules; internal static ConfigEntry<bool> NoStability; internal static ConfigEntry<bool> IgnoreHeightLimit; internal static ConfigEntry<bool> FreeRequirements; internal static ConfigEntry<float> BuilderFlySpeed; internal static ConfigEntry<int> DefaultSquareSize; internal static ConfigEntry<int> DefaultSquareHeight; private Harmony _harmony; internal static bool FreeBuildEnabled { get { if (RespectVanillaBuildRules != null) { return !RespectVanillaBuildRules.Value; } return false; } } internal static bool ShouldDisableStability { get { if (FreeBuildEnabled && NoStability != null) { return NoStability.Value; } return false; } } internal static bool ShouldIgnoreHeightLimit { get { if (FreeBuildEnabled && IgnoreHeightLimit != null) { return IgnoreHeightLimit.Value; } return false; } } internal static bool ShouldIgnoreRequirements { get { if (FreeBuildEnabled && FreeRequirements != null) { return FreeRequirements.Value; } return false; } } private void Awake() { //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown Instance = this; RespectVanillaBuildRules = ((BaseUnityPlugin)this).Config.Bind<bool>("Build Rules", "RespectVanillaBuildRules", true, "True = normale Valheim Bauregeln. False = Valheim Axiom FreeBuild wird aktiviert."); NoStability = ((BaseUnityPlugin)this).Config.Bind<bool>("Build Rules", "NoStability", true, "Wenn FreeBuild aktiv ist: Bauwerke sollen nicht wegen fehlendem Support einstürzen."); IgnoreHeightLimit = ((BaseUnityPlugin)this).Config.Bind<bool>("Build Rules", "IgnoreHeightLimit", true, "Wenn FreeBuild aktiv ist: Build-/Support-Höhenlimits so weit wie möglich ignorieren."); FreeRequirements = ((BaseUnityPlugin)this).Config.Bind<bool>("Build Rules", "FreeRequirements", false, "Wenn FreeBuild aktiv ist: Materialanforderungen beim Bauen ignorieren."); BuilderFlySpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Builder Mode", "FlySpeed", 18f, "Kamera-Fluggeschwindigkeit im Axiom-Baumodus."); DefaultSquareSize = ((BaseUnityPlugin)this).Config.Bind<int>("Builder Mode", "DefaultSquareSize", 6, "Standard-Radius/Größe für Quadrat-Tool."); DefaultSquareHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Builder Mode", "DefaultSquareHeight", 1, "Standard-Höhe für Quadrat-Tool."); ((Component)this).gameObject.AddComponent<EditorHost>(); new EditorCamera(); _harmony = new Harmony("de.danielsaar.valheimaxiom"); PatchHarmonySafely(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Valheim Axiom 0.15.5 geladen. Undo/Redo-Pfeile oben besitzen frei belegbare Shortcuts; R schaltet Gizmo um; eigener Shortcut für Extrude-Modus ergänzt."); } private void PatchHarmonySafely() { int num = 0; int num2 = 0; Type[] types; try { types = typeof(Plugin).Assembly.GetTypes(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Harmony-Patches konnten nicht geladen werden: Assembly-Typen konnten nicht gelesen werden: " + ex)); return; } foreach (Type type in types) { if (type == null || !HasHarmonyPatchAttribute(type)) { continue; } if (IsLegacyInputPatch(type)) { num2++; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Legacy-Input-Patch übersprungen: " + type.Name)); continue; } try { _harmony.CreateClassProcessor(type).Patch(); num++; } catch (Exception ex2) { num2++; ((BaseUnityPlugin)this).Logger.LogWarning((object)("Harmony-Patch übersprungen: " + type.FullName + " -> " + ex2.GetType().Name + ": " + ex2.Message)); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Harmony-Patches geladen: " + num + ", übersprungen: " + num2 + ".")); } private static bool HasHarmonyPatchAttribute(Type type) { return type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0; } private static bool IsLegacyInputPatch(Type type) { string name = type.Name; switch (name) { default: return name == "PlayerInputHardBlockPatch"; case "ZInputButtonBlockPatch": case "ZInputAxisBlockPatch": case "ZInputMouseButtonBlockPatch": case "ZInputMouseScrollBlockPatch": return true; } } private void LateUpdate() { if ((Object)(object)ZNet.instance != (Object)null) { StudioWorldEnvironment.Tick(ZNet.instance); } } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } internal static void SaveConfigNow() { try { Plugin instance = Instance; if (instance != null) { ConfigFile config = ((BaseUnityPlugin)instance).Config; if (config != null) { config.Save(); } } } catch { } } } public sealed class SnapSystem : MonoBehaviour { public bool SnapEnabled = true; public float SnapRadius = 0.75f; private readonly List<Vector3> _visibleSnapPoints = new List<Vector3>(); private Material _lineMaterial; public static SnapSystem Instance { get; private set; } public string StatusText { get; private set; } = "Snap bereit"; private void Awake() { Instance = this; } public Vector3 ResolvePlacement(GameObject prefab, Vector3 basePoint, Quaternion rotation, out bool snapped) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL