using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Build Ease")] [assembly: AssemblyDescription("Easy UE-style building for Valheim.")] [assembly: AssemblyCompany("Obelisk")] [assembly: AssemblyProduct("Build Ease")] [assembly: AssemblyFileVersion("0.3.16.0")] [assembly: ComVisible(false)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.3.16.0")] namespace Obelisk.UEPlacementEditor; internal static class AAABuildMenuCompatibility { private const string PluginGuid = "Azumatt.AAABuildMenu"; private const string EnhancedBuildMenuTypeName = "AAABuildMenu.EnhancedBuildMenu"; private static readonly FieldRef BuildPieces = AccessTools.FieldRefAccess("m_buildPieces"); private static readonly FieldRef>> AvailablePieces = AccessTools.FieldRefAccess>>("m_availablePieces"); [ThreadStatic] private static int _requirementEvaluationDepth; private static bool _resolved; private static bool _available; private static MethodInfo _applyFilterMethod; private static Func _activeGetter; private static Func _hasActiveFilter; private static Action _setNeedsRefresh; private static Action _setupPlacementGhost; private static FieldInfo _categoryMastersField; private static FieldInfo _selectedPieceField; private static FieldInfo _columnsField; private static Player _forcedPlayer; private static PieceTable _forcedTable; private static Piece _forcedPiece; private static PieceCategory _forcedCategory; private static bool _forcedPieceWasInjected; internal static bool IsRequirementEvaluationActive => _requirementEvaluationDepth > 0; internal static bool IsAvailable { get { EnsureResolved(); return _available; } } internal static MethodBase ApplyFilterMethod { get { EnsureResolved(); return _applyFilterMethod; } } internal static PieceTable GetBuildPieces(Player player) { if (!((Object)(object)player == (Object)null)) { return BuildPieces.Invoke(player); } return null; } internal static bool BeginRequirementEvaluation(Player player, PieceTable pieceTable) { if (!IsRuntimeActive() || !IsLocalEditorTable(player, pieceTable)) { return false; } _requirementEvaluationDepth++; return true; } internal static void EndRequirementEvaluation(bool entered) { if (entered && _requirementEvaluationDepth > 0) { _requirementEvaluationDepth--; } } internal static bool TryHandleFilteredCopySelection(Player player, Piece sampledWorldPiece) { //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0106: 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) //IL_012d: 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_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) if (!CopyPieceExecutionContextPatch.IsCopyPieceCall || !IsRuntimeActive() || !HasActiveFilter() || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || (Object)(object)sampledWorldPiece == (Object)null || (Object)(object)Plugin.Controller == (Object)null || !Plugin.Controller.IsActive) { return false; } PieceTable val = BuildPieces.Invoke(player); if ((Object)(object)val == (Object)null || !TryFindMasterPiece(sampledWorldPiece, out var availablePiece, out var category) || !TryGetCategoryIndex(val, category, out var categoryIndex) || !TryGetCategoryIndex(val, val.GetSelectedCategory(), out var categoryIndex2)) { return false; } List> previousViews = CaptureAvailablePieceViews(val); Vector2Int[] previousIndices = ((val.m_selectedPiece != null) ? ((Vector2Int[])val.m_selectedPiece.Clone()) : Array.Empty()); Piece enhancedSelectedPiece = GetEnhancedSelectedPiece(); Piece selectedPiece = val.GetSelectedPiece(); GameObject placementGhost = EditorController.GetPlacementGhost(player); bool flag = IsMatchingGhost(placementGhost, selectedPiece) && IsFinite(placementGhost.transform.position) && IsFinite(placementGhost.transform.rotation); Vector3 previousGhostPosition = (flag ? placementGhost.transform.position : Vector3.zero); Quaternion previousGhostRotation = (flag ? placementGhost.transform.rotation : Quaternion.identity); PieceTable forcedTable = _forcedTable; Piece forcedPiece = _forcedPiece; PieceCategory forcedCategory = _forcedCategory; bool forcedPieceWasInjected = _forcedPieceWasInjected; try { val.SetCategory(categoryIndex); if (!TryGetSelectedCategoryList(val, out var category2, out var pieces) || category2 != category) { RestorePreviousSelection(player, val, previousViews, previousIndices, categoryIndex2, enhancedSelectedPiece, selectedPiece, flag, previousGhostPosition, previousGhostRotation); return false; } RemovePreviousInjectedPiece(val, category2, pieces); int selectedIndex; bool forcedPieceWasInjected2 = InsertOrSelectPiece(pieces, availablePiece, out selectedIndex); val.SetSelected(ToGridIndex(selectedIndex)); SetEnhancedSelectedPiece(availablePiece); _setupPlacementGhost(player); if (!IsMatchingGhost(EditorController.GetPlacementGhost(player), availablePiece)) { RestorePreviousSelection(player, val, previousViews, previousIndices, categoryIndex2, enhancedSelectedPiece, selectedPiece, flag, previousGhostPosition, previousGhostRotation); return false; } if (forcedPieceWasInjected && (Object)(object)forcedPiece != (Object)null && ((Object)(object)forcedTable != (Object)(object)val || forcedCategory != category2)) { RemoveInjectedPiece(forcedTable, forcedCategory, forcedPiece); } _forcedPlayer = player; _forcedTable = val; _forcedPiece = availablePiece; _forcedCategory = category2; _forcedPieceWasInjected = forcedPieceWasInjected2; return true; } catch (Exception arg) { try { RestorePreviousSelection(player, val, previousViews, previousIndices, categoryIndex2, enhancedSelectedPiece, selectedPiece, flag, previousGhostPosition, previousGhostRotation); } catch { } Plugin.LogError($"AAABuildMenu filtered sampling compatibility failed: {arg}"); return false; } } internal static void AfterApplyFilter(Player player, PieceTable pieceTable) { if (!IsRuntimeActive() || !IsLocalPlayerTable(player, pieceTable)) { return; } try { if (!IsLocalEditorTable(player, pieceTable) || !MaintainForcedSelection(player, pieceTable)) { Piece selectedPiece = pieceTable.GetSelectedPiece(); GameObject placementGhost = EditorController.GetPlacementGhost(player); bool flag = (Object)(object)selectedPiece != (Object)null && !selectedPiece.m_repairPiece && !selectedPiece.m_removePiece; if ((flag && !IsMatchingGhost(placementGhost, selectedPiece)) || (!flag && (Object)(object)placementGhost != (Object)null)) { _setupPlacementGhost(player); } } } catch (Exception arg) { Plugin.LogError($"AAABuildMenu filter reconciliation failed: {arg}"); } } internal static void OnBuildMenuOpening() { ReleaseForcedSelection(requestFilterRefresh: true); } internal static void OnEditorExit() { ReleaseForcedSelection(requestFilterRefresh: true); } private static bool MaintainForcedSelection(Player player, PieceTable pieceTable) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_forcedPiece == (Object)null) { return false; } if (Hud.IsPieceSelectionVisible() || (Object)(object)player != (Object)(object)_forcedPlayer || (Object)(object)pieceTable != (Object)(object)_forcedTable || pieceTable.GetSelectedCategory() != _forcedCategory || (Object)(object)Plugin.Controller == (Object)null || !Plugin.Controller.IsActive) { ReleaseForcedSelection(requestFilterRefresh: true); return false; } if (!TryGetSelectedCategoryList(pieceTable, out var _, out var pieces)) { ReleaseForcedSelection(requestFilterRefresh: true); return false; } _forcedPieceWasInjected = InsertOrSelectPiece(pieces, _forcedPiece, out var selectedIndex); pieceTable.SetSelected(ToGridIndex(selectedIndex)); SetEnhancedSelectedPiece(_forcedPiece); if (!IsMatchingGhost(EditorController.GetPlacementGhost(player), _forcedPiece)) { _setupPlacementGhost(player); } return true; } private static void RemovePreviousInjectedPiece(PieceTable pieceTable, PieceCategory category, List filteredView) { //IL_0021: 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) if (_forcedPieceWasInjected && !((Object)(object)_forcedPiece == (Object)null) && !((Object)(object)pieceTable != (Object)(object)_forcedTable) && category == _forcedCategory) { RemoveMatchingPieces(filteredView, _forcedPiece); } } private static void RemoveInjectedPiece(PieceTable pieceTable, PieceCategory category, Piece piece) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected I4, but got Unknown if (!((Object)(object)pieceTable == (Object)null) && !((Object)(object)piece == (Object)null)) { List> list = AvailablePieces.Invoke(pieceTable); int num = (int)category; if (list != null && num >= 0 && num < list.Count) { RemoveMatchingPieces(list[num], piece); } } } private static void RemoveMatchingPieces(List pieces, Piece piece) { if (pieces == null || (Object)(object)piece == (Object)null) { return; } string prefabName = GetPrefabName(piece); for (int num = pieces.Count - 1; num >= 0; num--) { Piece val = pieces[num]; if ((Object)(object)val != (Object)null && string.Equals(GetPrefabName(val), prefabName, StringComparison.Ordinal)) { pieces.RemoveAt(num); } } } private static void RestorePreviousSelection(Player player, PieceTable pieceTable, List> previousViews, Vector2Int[] previousIndices, int previousCategoryIndex, Piece previousSelectedPiece, Piece previousTableSelectedPiece, bool restoreGhostPose, Vector3 previousGhostPosition, Quaternion previousGhostRotation) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) RestoreAvailablePieceViews(pieceTable, previousViews); if (pieceTable.m_selectedPiece != null && previousIndices != null) { Array.Copy(previousIndices, pieceTable.m_selectedPiece, Math.Min(previousIndices.Length, pieceTable.m_selectedPiece.Length)); } pieceTable.SetCategory(previousCategoryIndex); SetEnhancedSelectedPiece(previousSelectedPiece); _setupPlacementGhost(player); GameObject placementGhost = EditorController.GetPlacementGhost(player); if (restoreGhostPose && IsMatchingGhost(placementGhost, previousTableSelectedPiece)) { placementGhost.transform.SetPositionAndRotation(previousGhostPosition, previousGhostRotation); } } private static bool TryFindMasterPiece(Piece sampledWorldPiece, out Piece availablePiece, out PieceCategory category) { //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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected I4, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected I4, but got Unknown availablePiece = null; category = (PieceCategory)0; if (!(_categoryMastersField.GetValue(null) is IDictionary dictionary)) { return false; } string prefabName = GetPrefabName(sampledWorldPiece); PieceCategory category2 = sampledWorldPiece.m_category; if (TryFindMasterPieceInCategory(dictionary, category2, prefabName, out availablePiece)) { category = (PieceCategory)(int)category2; return true; } foreach (DictionaryEntry item in dictionary) { if (!(item.Key is PieceCategory val) || !(item.Value is IList list)) { continue; } for (int i = 0; i < list.Count; i++) { object? obj = list[i]; Piece val2 = (Piece)((obj is Piece) ? obj : null); if ((Object)(object)val2 != (Object)null && string.Equals(GetPrefabName(val2), prefabName, StringComparison.Ordinal)) { availablePiece = val2; category = (PieceCategory)(int)val; return true; } } } return false; } private static bool TryFindMasterPieceInCategory(IDictionary categoryMasters, PieceCategory category, string prefabName, out Piece availablePiece) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) availablePiece = null; if (!(categoryMasters[category] is IList list)) { return false; } for (int i = 0; i < list.Count; i++) { object? obj = list[i]; Piece val = (Piece)((obj is Piece) ? obj : null); if ((Object)(object)val != (Object)null && string.Equals(GetPrefabName(val), prefabName, StringComparison.Ordinal)) { availablePiece = val; return true; } } return false; } private static bool TryGetCategoryIndex(PieceTable pieceTable, PieceCategory category, out int categoryIndex) { //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) categoryIndex = -1; if ((Object)(object)pieceTable == (Object)null || pieceTable.m_categories == null) { return false; } for (int i = 0; i < pieceTable.m_categories.Count; i++) { if (pieceTable.m_categories[i] == category) { categoryIndex = i; return true; } } return false; } private static List> CaptureAvailablePieceViews(PieceTable pieceTable) { List> list = AvailablePieces.Invoke(pieceTable); List> list2 = new List>(list?.Count ?? 0); if (list == null) { return list2; } for (int i = 0; i < list.Count; i++) { List list3 = list[i]; list2.Add((list3 != null) ? new List(list3) : null); } return list2; } private static void RestoreAvailablePieceViews(PieceTable pieceTable, List> snapshot) { List> list = AvailablePieces.Invoke(pieceTable); if (list == null || snapshot == null) { return; } while (list.Count > snapshot.Count) { list.RemoveAt(list.Count - 1); } for (int i = 0; i < snapshot.Count; i++) { List list2 = snapshot[i]; if (i >= list.Count) { list.Add((list2 != null) ? new List(list2) : new List()); continue; } List list3 = list[i]; if (list3 == null) { list[i] = ((list2 != null) ? new List(list2) : new List()); continue; } list3.Clear(); if (list2 != null) { list3.AddRange(list2); } } } private static bool TryGetSelectedCategoryList(PieceTable pieceTable, out PieceCategory category, out List pieces) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected I4, but got Unknown category = (PieceCategory)(int)pieceTable.GetSelectedCategory(); List> list = AvailablePieces.Invoke(pieceTable); int num = (int)category; if (list == null || num < 0 || num >= list.Count) { pieces = null; return false; } pieces = list[num]; return pieces != null; } private static bool InsertOrSelectPiece(List filteredView, Piece piece, out int selectedIndex) { string prefabName = GetPrefabName(piece); int num = -1; for (int num2 = filteredView.Count - 1; num2 >= 0; num2--) { Piece val = filteredView[num2]; if (!((Object)(object)val == (Object)null) && string.Equals(GetPrefabName(val), prefabName, StringComparison.Ordinal)) { num = num2; filteredView.RemoveAt(num2); } } selectedIndex = ((num >= 0) ? Mathf.Min(num, filteredView.Count) : 0); filteredView.Insert(selectedIndex, piece); return num < 0; } private static Vector2Int ToGridIndex(int linearIndex) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) int num = 15; if (_columnsField != null && _columnsField.GetValue(null) is int num2) { num = Mathf.Clamp(num2, 1, 64); } return new Vector2Int(linearIndex % num, linearIndex / num); } private static bool IsMatchingGhost(GameObject ghost, Piece piece) { if ((Object)(object)ghost != (Object)null && (Object)(object)piece != (Object)null && (Object)(object)ghost.GetComponent() != (Object)null) { return string.Equals(Utils.GetPrefabName(ghost), GetPrefabName(piece), StringComparison.Ordinal); } return false; } private static bool IsFinite(Vector3 value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0041: Unknown result type (might be due to invalid IL or missing references) if (!float.IsNaN(value.x) && !float.IsInfinity(value.x) && !float.IsNaN(value.y) && !float.IsInfinity(value.y) && !float.IsNaN(value.z)) { return !float.IsInfinity(value.z); } return false; } private static bool IsFinite(Quaternion value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) if (!float.IsNaN(value.x) && !float.IsInfinity(value.x) && !float.IsNaN(value.y) && !float.IsInfinity(value.y) && !float.IsNaN(value.z) && !float.IsInfinity(value.z) && !float.IsNaN(value.w)) { return !float.IsInfinity(value.w); } return false; } private static string GetPrefabName(Piece piece) { if (!((Object)(object)piece == (Object)null)) { return Utils.GetPrefabName(((Component)piece).gameObject); } return string.Empty; } private static Piece GetEnhancedSelectedPiece() { object? value = _selectedPieceField.GetValue(null); return (Piece)((value is Piece) ? value : null); } private static void SetEnhancedSelectedPiece(Piece piece) { _selectedPieceField.SetValue(null, piece); } private static bool HasActiveFilter() { try { return _hasActiveFilter(); } catch { return false; } } private static bool IsRuntimeActive() { if (!IsAvailable) { return false; } try { return _activeGetter(); } catch { return false; } } private static bool IsLocalEditorTable(Player player, PieceTable pieceTable) { if (IsLocalPlayerTable(player, pieceTable) && (Object)(object)Plugin.Controller != (Object)null) { return Plugin.Controller.IsActive; } return false; } private static bool IsLocalPlayerTable(Player player, PieceTable pieceTable) { if ((Object)(object)player != (Object)null && (Object)(object)player == (Object)(object)Player.m_localPlayer && (Object)(object)pieceTable != (Object)null) { return (Object)(object)BuildPieces.Invoke(player) == (Object)(object)pieceTable; } return false; } private static void ReleaseForcedSelection(bool requestFilterRefresh) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) bool flag = (Object)(object)_forcedPiece != (Object)null; _forcedPlayer = null; _forcedTable = null; _forcedPiece = null; _forcedCategory = (PieceCategory)0; _forcedPieceWasInjected = false; if (requestFilterRefresh && flag && IsAvailable) { try { _setNeedsRefresh(obj: true); } catch { } } } private static void EnsureResolved() { if (_resolved) { return; } _resolved = true; if (!Chainloader.PluginInfos.ContainsKey("Azumatt.AAABuildMenu")) { return; } try { Type type = OptionalModTypeResolver.FindLoadedType("AAABuildMenu.EnhancedBuildMenu"); _applyFilterMethod = ((type == null) ? null : AccessTools.Method(type, "ApplyFilter", new Type[3] { typeof(Player), typeof(PieceTable), typeof(bool) }, (Type[])null)); MethodInfo methodInfo = ((type == null) ? null : AccessTools.PropertyGetter(type, "Active")); MethodInfo methodInfo2 = ((type == null) ? null : AccessTools.Method(type, "HasActiveFilter", Type.EmptyTypes, (Type[])null)); MethodInfo methodInfo3 = ((type == null) ? null : AccessTools.PropertySetter(type, "NeedsRefresh")); _categoryMastersField = ((type == null) ? null : AccessTools.Field(type, "_categoryMasters")); _selectedPieceField = ((type == null) ? null : AccessTools.Field(type, "SelectedPiece")); _columnsField = ((type == null) ? null : AccessTools.Field(type, "Columns")); MethodInfo methodInfo4 = AccessTools.Method(typeof(Player), "SetupPlacementGhost", Type.EmptyTypes, (Type[])null); if (_applyFilterMethod == null || methodInfo == null || methodInfo2 == null || methodInfo3 == null || _categoryMastersField == null || _selectedPieceField == null || _columnsField == null || methodInfo4 == null) { Plugin.LogError("AAABuildMenu was detected, but its compatibility API does not match version 1.0.1; integration is disabled."); return; } _activeGetter = AccessTools.MethodDelegate>(methodInfo, (object)null, true); _hasActiveFilter = AccessTools.MethodDelegate>(methodInfo2, (object)null, true); _setNeedsRefresh = AccessTools.MethodDelegate>(methodInfo3, (object)null, true); _setupPlacementGhost = AccessTools.MethodDelegate>(methodInfo4, (object)null, true); _available = _activeGetter != null && _hasActiveFilter != null && _setNeedsRefresh != null && _setupPlacementGhost != null; } catch (Exception arg) { _available = false; Plugin.LogError($"AAABuildMenu compatibility initialization failed: {arg}"); } } } [HarmonyPatch] internal static class AAABuildMenuApplyFilterPatch { private static bool Prepare() { return AAABuildMenuCompatibility.IsAvailable; } private static MethodBase TargetMethod() { return AAABuildMenuCompatibility.ApplyFilterMethod; } private static void Prefix(Player __0, PieceTable __1, out bool __state) { __state = AAABuildMenuCompatibility.BeginRequirementEvaluation(__0, __1); } [HarmonyPriority(0)] private static void Postfix(Player __0, PieceTable __1) { AAABuildMenuCompatibility.AfterApplyFilter(__0, __1); } private static Exception Finalizer(Exception __exception, bool __state) { AAABuildMenuCompatibility.EndRequirementEvaluation(__state); return __exception; } } [HarmonyPatch] internal static class AAABuildMenuHudUpdateBuildRequirementPatch { private static bool Prepare() { return AAABuildMenuCompatibility.IsAvailable; } private static MethodBase TargetMethod() { return AccessTools.Method(typeof(Hud), "UpdateBuild", new Type[2] { typeof(Player), typeof(bool) }, (Type[])null); } [HarmonyPriority(800)] private static void Prefix(Player __0, out bool __state) { PieceTable buildPieces = AAABuildMenuCompatibility.GetBuildPieces(__0); __state = AAABuildMenuCompatibility.BeginRequirementEvaluation(__0, buildPieces); } private static Exception Finalizer(Exception __exception, bool __state) { AAABuildMenuCompatibility.EndRequirementEvaluation(__state); return __exception; } } [HarmonyPatch] internal static class AAABuildMenuCopySelectionPatch { private static bool Prepare() { return AAABuildMenuCompatibility.IsAvailable; } private static MethodBase TargetMethod() { return AccessTools.Method(typeof(Player), "SetSelectedPiece", new Type[1] { typeof(Piece) }, (Type[])null); } [HarmonyPriority(0)] private static bool Prefix(Player __instance, Piece __0, ref bool __result) { if (!AAABuildMenuCompatibility.TryHandleFilteredCopySelection(__instance, __0)) { return true; } __result = true; return false; } } [HarmonyPatch] internal static class AAABuildMenuBuildMenuOpenPatch { private static bool Prepare() { return AAABuildMenuCompatibility.IsAvailable; } private static MethodBase TargetMethod() { return AccessTools.Method(typeof(Hud), "TogglePieceSelection", (Type[])null, (Type[])null); } private static void Prefix() { if (!Hud.IsPieceSelectionVisible()) { AAABuildMenuCompatibility.OnBuildMenuOpening(); } } } internal enum EditMode { Translate, Rotate } internal enum CoordinateSpace { World, Local } internal sealed class EditorController : MonoBehaviour { private enum TargetStatusKind { NoGhost, SpecialPiece, Piece } private struct PlacementRotationSnapshot { internal int PlaceRotation; internal float ScrollCurrentAmount; internal float RotatePieceTimer; internal bool PerfectPlacementAvailable; internal bool PerfectPlacementHadEntry; internal Vector3 PerfectPlacementRotation; } internal sealed class DemolitionPickupTransaction { internal readonly HashSet ExistingDropIds = new HashSet(); internal readonly Dictionary RemainingResources = new Dictionary(); internal Vector3 Center; internal float ExpiresAt; } private static readonly FieldRef PlacementGhost = AccessTools.FieldRefAccess("m_placementGhost"); private static readonly FieldRef PlacementMarker = AccessTools.FieldRefAccess("m_placementMarkerInstance"); private static readonly FieldRef PlacementStatus = AccessTools.FieldRefAccess("m_placementStatus"); private static readonly FieldRef PlaceRayMask = AccessTools.FieldRefAccess("m_placeRayMask"); private static readonly FieldRef RemoveRayMask = AccessTools.FieldRefAccess("m_removeRayMask"); private static readonly FieldRef MaximumPlaceDistance = AccessTools.FieldRefAccess("m_maxPlaceDistance"); private static readonly FieldRef PlaceRotation = AccessTools.FieldRefAccess("m_placeRotation"); private static readonly FieldRef EnableAutoPickup = AccessTools.StaticFieldRefAccess(AccessTools.Field(typeof(Player), "m_enableAutoPickup")); private static readonly FieldRef ScrollCurrentAmount = AccessTools.FieldRefAccess("m_scrollCurrAmount"); private static readonly FieldRef RotatePieceTimer = AccessTools.FieldRefAccess("m_rotatePieceTimer"); private static readonly MethodInfo UpdatePlacementMethod = AccessTools.Method(typeof(Player), "UpdatePlacement", new Type[2] { typeof(bool), typeof(float) }, (Type[])null); private static readonly Action UpdatePlacementInvoker = CreateUpdatePlacementInvoker(); private static readonly string[] HotbarButtons = new string[8] { "Hotbar1", "Hotbar2", "Hotbar3", "Hotbar4", "Hotbar5", "Hotbar6", "Hotbar7", "Hotbar8" }; private static readonly KeyCode[] HotbarKeys; private static bool _externalModeResolversInitialized; private static Func _perfectPlacementBuildingMode; private static Func _perfectPlacementEditingMode; private static Func _buildCameraMode; private static bool _moveBuildPiecesPresent; private static bool _moveBuildPiecesResolved; private static Func _moveBuildPiecesEnabled; private static Func _moveBuildPiecesBlocksBuildAction; private static Func _moveBuildPiecesBuildModeHotkey; private static Func _moveBuildPiecesWorldModeHotkey; private static Func _moveBuildPiecesMixedModeHotkey; private static FieldInfo _moveBuildPiecesPendingRequest; private static IDictionary _perfectPlacementPlayersData; private static FieldRef _perfectPlacementPlaceRotation; private const float RightMouseClickTime = 0.28f; private const float RightMouseLookThreshold = 0.35f; private const float BuildSnapDistance = 0.5f; private const float BuildSnapSearchRadius = 10f; private const int MaximumSnapPieceBufferSize = 16384; private const int MaximumClippingBufferSize = 32768; private const float DemolitionPickupRadius = 3f; private const float DemolitionPickupInterval = 0.1f; private const float DemolitionPickupDuration = 5f; private const float HammerEquipTimeout = 8f; private const float CameraRayFollowPositionEpsilonSquared = 1E-06f; private const float CameraRayFollowDirectionDotThreshold = 0.9999995f; private const float TranslationStepEpsilon = 0.001f; private const int ToolbarWindowId = 20260714; private static readonly Color CameraLightColor; private static readonly GUILayoutOption HeaderWidth; private static readonly GUILayoutOption TranslateWidth; private static readonly GUILayoutOption RotateWidth; private static readonly GUILayoutOption SpaceWidth; private static readonly GUILayoutOption SnapWidth; private static readonly GUILayoutOption CameraLightWidth; private static readonly GUILayoutOption CameraRayFollowWidth; private static readonly GUILayoutOption ResetWidth; private static readonly GUILayoutOption ExitWidth; private static readonly Rect ToolbarDragRect; private readonly List _nearbyCharacters = new List(16); private readonly List _sourceSnapPoints = new List(32); private readonly List _destinationSnapPoints = new List(128); private readonly List _nearbyPieces = new List(64); private readonly HashSet _nearbyPieceSet = new HashSet(); private readonly HashSet _demolitionPickupDrops = new HashSet(); private readonly List _demolitionPickupTransactions = new List(8); private readonly PlacementGhostVisual _placementGhostVisual = new PlacementGhostVisual(); private Collider[] _targetColliders = Array.Empty(); private Renderer[] _targetGeometryRenderers = Array.Empty(); private Collider[] _snapPieceBuffer = (Collider[])(object)new Collider[256]; private Collider[] _clippingBuffer = (Collider[])(object)new Collider[256]; private Collider[] _demolitionPickupBuffer = (Collider[])(object)new Collider[128]; private RaycastHit[] _surfaceRaycastBuffer = (RaycastHit[])(object)new RaycastHit[64]; private int _itemLayerMask; private int _pieceLayerMask; private GizmoRenderer _gizmo; private Camera _editorCamera; private GameObject _targetGhost; private Piece _targetPiece; private Piece _targetSelectedPiece; private Piece _observedSelectedPiece; private bool _observedSelectedPieceCompatible; private bool _hasCachedPlacementStatus; private PlacementStatus _cachedPlacementStatus; private Vector3 _desiredPosition; private Quaternion _desiredRotation; private bool _copiedPieceThisPlacementUpdate; private bool _hasSampledPlacementRotation; private bool _sampledCopySucceededThisPlacementUpdate; private int _sampledPlaceRotation; private Quaternion _sampledPlacementRotation; private EditMode _mode; private CoordinateSpace _space; private bool _surfaceSnapEnabled; private bool _cameraRayFollowEnabled; private bool _cameraRayFollowUpdatePending; private bool _hasCameraRayFollowInput; private Vector3 _lastCameraRayFollowOrigin; private Vector3 _lastCameraRayFollowDirection; private bool _hasTemporaryPivot; private bool _surfaceSupportInvalid; private Vector3 _temporaryPivotLocal; private bool _active; private bool _placementUpdateFailed; private bool _editorEntryPending; private bool _pendingEquipIssued; private bool _pendingOwnEquipAction; private Player _pendingEntryPlayer; private Inventory _pendingEntryInventory; private ItemData _pendingEntryHammer; private float _pendingEntryDeadline; private bool _rightMouseActive; private bool _rightMouseMoved; private bool _rightMouseMenuWasVisible; private float _rightMouseDownTime; private float _rightMouseLookMagnitude; private Vector3 _rightMouseStartCameraPosition; private float _rightMouseStartYaw; private float _rightMouseStartPitch; private bool _cameraCapturedLastFrame; private bool _cameraPositionDirty; private Vector3 _cameraPosition; private float _cameraYaw; private float _cameraPitch; private float _cameraSpeedScale = 1f; private Light _cameraLight; private volatile bool _cameraLightSettingsDirty; private volatile bool _ghostPreviewSettingsDirty; private bool _blueGhostPreviewEnabled; private volatile bool _toolbarLabelsDirty; private EditorLanguage _language = EditorLanguage.English; private bool _languageInitialized; private float _nextDemolitionPickupTime; private float _lastDemolitionPickupErrorTime = float.NegativeInfinity; private Player _distancePlayer; private bool _insidePlacementUpdate; private float _originalPlaceDistance; private float _appliedPlaceDistance; private int _uiInputBlockedThroughFrame = -1; private int _placementInputBlockedThroughFrame = -1; private int _reserveHotkeysThroughFrame = -1; private Rect _toolbarRect = new Rect(10f, 10f, 1290f, 86f); private WindowFunction _toolbarWindowFunction; private bool _toolbarDragging; private TargetStatusKind _targetStatusKind; private string _targetStatusPieceToken; private string _targetStatusText = string.Empty; private string _spaceButtonLabel; private string _surfaceSnapButtonLabel; private string _cameraLightButtonLabel; private string _cameraRayFollowButtonLabel; private string _exitButtonLabel; private GizmoAxis _dragAxis; private Plane _dragPlane; private Vector3 _dragWorldAxis; private Vector3 _dragStartRootPosition; private Vector3 _dragStartPivot; private Vector3 _dragStartPlanePoint; private Quaternion _dragStartRotation; private float _dragStartAxisParameter; private Vector3 _dragStartVector; private bool _dragUsesScreenSpace; private Vector2 _dragStartMouse; private Vector2 _dragScreenDirection; private float _dragScreenScale; private float _dragBoundsTranslationStep; private float _dragSnapPointTranslationStep; private static int _suppressMenuFrame; private static int _buildMenuConsumedEscapeFrame; internal bool IsActive => _active; internal bool HasGizmoTarget { get { if ((Object)(object)_targetGhost != (Object)null) { return (Object)(object)_targetPiece != (Object)null; } return false; } } internal Transform TargetTransform { get { if (!HasGizmoTarget) { return null; } return _targetGhost.transform; } } internal Vector3 GizmoPivot { get { //IL_0029: 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_003b: 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) if (!HasGizmoTarget || !_hasTemporaryPivot) { if (!HasGizmoTarget) { return Vector3.zero; } return _targetGhost.transform.position; } return _targetGhost.transform.TransformPoint(_temporaryPivotLocal); } } internal Camera EditorCamera { get { if ((Object)(object)_editorCamera == (Object)null) { _editorCamera = ResolveGameCamera(); } return _editorCamera; } } internal EditMode Mode => _mode; internal CoordinateSpace Space => _space; internal float ActiveEditorRange => GetEditorRange(); internal bool ShouldExtendBuildStationRange { get { if (!_active || (Object)(object)Player.m_localPlayer == (Object)null) { return false; } if (IsEditorBlockedInCurrentInterior(Player.m_localPlayer)) { return false; } if (AAABuildMenuCompatibility.IsRequirementEvaluationActive) { return true; } if (!_insidePlacementUpdate) { return false; } Piece selectedPiece = Player.m_localPlayer.GetSelectedPiece(); if ((Object)(object)selectedPiece != (Object)null && !selectedPiece.m_repairPiece) { return !selectedPiece.m_removePiece; } return false; } } internal bool ShouldRenderEditorOverlay { get { if (_active && !IsGameUiBlockingEditorInput()) { return !Hud.IsPieceSelectionVisible(); } return false; } } private bool ShouldRenderToolbar { get { if (ShouldRenderEditorOverlay) { return Plugin.ShowToolbar.Value; } return false; } } internal bool ShouldReserveEditorHotkeys { get { if (!_active && !_editorEntryPending) { return Time.frameCount <= _reserveHotkeysThroughFrame; } return true; } } internal bool ShouldOwnEscapeInput => ShouldRenderEditorOverlay; internal static bool SuppressMenuThisFrame => Time.frameCount == _suppressMenuFrame; internal static bool BuildMenuConsumedEscapeThisFrame => Time.frameCount == _buildMenuConsumedEscapeFrame; private bool IsEditorInputSuppressed { get { if (!IsGameUiBlockingEditorInput()) { return Time.frameCount <= _uiInputBlockedThroughFrame; } return true; } } private bool IsCameraCaptured { get { if (_active && !IsEditorInputSuppressed) { return _rightMouseActive; } return false; } } private void Awake() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown _itemLayerMask = LayerMask.GetMask(new string[1] { "item" }); _pieceLayerMask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" }); _toolbarWindowFunction = new WindowFunction(DrawToolbarWindow); _gizmo = ((Component)this).gameObject.AddComponent(); _gizmo.Controller = this; ((Behaviour)_gizmo).enabled = false; Plugin.ToggleEditorKey.SettingChanged += OnToolbarHotkeySettingChanged; Plugin.ToggleSurfaceSnapKey.SettingChanged += OnToolbarHotkeySettingChanged; Plugin.ToggleCoordinateSpaceKey.SettingChanged += OnToolbarHotkeySettingChanged; Plugin.ToggleCameraLightKey.SettingChanged += OnToolbarHotkeySettingChanged; Plugin.ToggleCameraRayFollowKey.SettingChanged += OnToolbarHotkeySettingChanged; Plugin.CameraLightRange.SettingChanged += OnCameraLightSettingChanged; Plugin.CameraLightIntensity.SettingChanged += OnCameraLightSettingChanged; Plugin.BlueGhostPreview.SettingChanged += OnGhostPreviewSettingChanged; _blueGhostPreviewEnabled = Plugin.BlueGhostPreview.Value; Localization.OnLanguageChange = (Action)Delegate.Combine(Localization.OnLanguageChange, new Action(OnGameLanguageChanged)); } private void OnDestroy() { Localization.OnLanguageChange = (Action)Delegate.Remove(Localization.OnLanguageChange, new Action(OnGameLanguageChanged)); CancelPendingEditorEntry(removeOwnedEquipAction: true); _placementGhostVisual.Restore(); DestroyCameraLight(); Plugin.ToggleEditorKey.SettingChanged -= OnToolbarHotkeySettingChanged; Plugin.ToggleSurfaceSnapKey.SettingChanged -= OnToolbarHotkeySettingChanged; Plugin.ToggleCoordinateSpaceKey.SettingChanged -= OnToolbarHotkeySettingChanged; Plugin.ToggleCameraLightKey.SettingChanged -= OnToolbarHotkeySettingChanged; Plugin.ToggleCameraRayFollowKey.SettingChanged -= OnToolbarHotkeySettingChanged; Plugin.CameraLightRange.SettingChanged -= OnCameraLightSettingChanged; Plugin.CameraLightIntensity.SettingChanged -= OnCameraLightSettingChanged; Plugin.BlueGhostPreview.SettingChanged -= OnGhostPreviewSettingChanged; _toolbarWindowFunction = null; } private void Update() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) if (_toolbarDragging && (!Plugin.ShowToolbar.Value || !Input.GetMouseButton(0))) { _toolbarDragging = false; } if (_cameraLightSettingsDirty) { _cameraLightSettingsDirty = false; ApplyCameraLightSettings(); } if (_ghostPreviewSettingsDirty) { _ghostPreviewSettingsDirty = false; ApplyGhostPreviewSetting(); } if (_toolbarLabelsDirty) { _toolbarLabelsDirty = false; RefreshToolbarLabels(); } UpdateDemolitionAutoPickupSafe(); if (EditorInputFirewall.IsEditorShortcutDown(Plugin.ToggleEditorKey.Value) && !IsGameUiBlockingEditorInput()) { _reserveHotkeysThroughFrame = Time.frameCount; if (_active) { ExitEditor(); } else if (_editorEntryPending) { CancelPendingEditorEntry(removeOwnedEquipAction: true); } else { BeginEditorEntry(); } return; } if (_editorEntryPending) { UpdatePendingEditorEntry(); } if (!_active) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)GameCamera.instance == (Object)null || ((Character)localPlayer).IsDead() || ((Character)localPlayer).InCutscene() || ((Character)localPlayer).IsTeleporting() || !((Character)localPlayer).InPlaceMode()) { ExitEditor(); return; } if (IsEditorBlockedInCurrentInterior(localPlayer)) { ExitEditor(); ((Character)localPlayer).Message((MessageType)2, "$msg_notindungeon", 0, (Sprite)null); return; } if (IsConflictingEditorActive()) { ExitEditor(); ((Character)localPlayer).Message((MessageType)1, _language.DisableConflictingEditor, 0, (Sprite)null); return; } if (IsGameUiBlockingEditorInput()) { _uiInputBlockedThroughFrame = Time.frameCount + 1; SuspendEditorInput(); return; } if (Time.frameCount <= _uiInputBlockedThroughFrame) { SuspendEditorInput(); return; } RefreshPlacementGhostReference(localPlayer); if (Input.GetKeyDown((KeyCode)27)) { if (!BuildMenuConsumedEscapeThisFrame && !Hud.IsPieceSelectionVisible()) { ReserveEscapeInput(); ExitEditor(); } return; } UpdateRightMouseGesture(); if (Hud.IsPieceSelectionVisible()) { CancelDrag(); return; } bool flag = HandleCameraRayFollowShortcut(); if (!flag) { flag = HandleCameraLightShortcut(); } if (IsCameraCaptured) { CancelDrag(); return; } if (!flag) { HandleEditorShortcuts(); } HandlePointer(); } private void SuspendEditorInput() { _toolbarDragging = false; _rightMouseActive = false; _rightMouseMoved = false; _cameraCapturedLastFrame = false; CancelDrag(); if ((Object)(object)_gizmo != (Object)null) { _gizmo.HoveredAxis = GizmoAxis.None; } } private void UpdateRightMouseGesture() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_00b2: Unknown result type (might be due to invalid IL or missing references) if (Input.GetMouseButtonDown(1)) { _rightMouseActive = true; _rightMouseMoved = false; _rightMouseMenuWasVisible = Hud.IsPieceSelectionVisible(); _rightMouseDownTime = Time.unscaledTime; _rightMouseLookMagnitude = 0f; _rightMouseStartCameraPosition = _cameraPosition; _rightMouseStartYaw = _cameraYaw; _rightMouseStartPitch = _cameraPitch; if (_rightMouseMenuWasVisible) { Hud.HidePieceSelection(); } } if (!_rightMouseActive || !Input.GetMouseButtonUp(1)) { return; } float num = Time.unscaledTime - _rightMouseDownTime; bool num2 = !_rightMouseMoved && num <= 0.28f; _rightMouseActive = false; _cameraCapturedLastFrame = false; if (num2) { _cameraPosition = _rightMouseStartCameraPosition; _cameraYaw = _rightMouseStartYaw; _cameraPitch = _rightMouseStartPitch; _cameraPositionDirty = true; if (!_rightMouseMenuWasVisible) { ToggleBuildMenu(); } } _rightMouseMenuWasVisible = false; } private void HandleEditorShortcuts() { //IL_0005: 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) if (EditorInputFirewall.IsEditorShortcutDown(Plugin.ToggleCoordinateSpaceKey.Value)) { ToggleCoordinateSpace(); } else if (EditorInputFirewall.IsEditorShortcutDown(Plugin.ToggleSurfaceSnapKey.Value)) { ToggleSurfaceSnapping(); } else if (Input.GetKeyDown((KeyCode)119)) { SetEditMode(EditMode.Translate); } else if (Input.GetKeyDown((KeyCode)101) || Input.GetKeyDown((KeyCode)114)) { SetEditMode(EditMode.Rotate); } } private bool HandleCameraLightShortcut() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (!EditorInputFirewall.IsEditorShortcutDown(Plugin.ToggleCameraLightKey.Value)) { return false; } ToggleCameraLight(); return true; } private bool HandleCameraRayFollowShortcut() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (!EditorInputFirewall.IsEditorShortcutDown(Plugin.ToggleCameraRayFollowKey.Value)) { return false; } ToggleCameraRayFollow(); return true; } private void SetEditMode(EditMode mode) { if (_mode != mode) { CancelDrag(); _mode = mode; } } private void ToggleCoordinateSpace() { //IL_0028: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0077: 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) //IL_007c: 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) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: 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_008e: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) Transform val = (HasGizmoTarget ? _targetGhost.transform : null); Vector3 val2 = (((Object)(object)val != (Object)null) ? val.position : Vector3.zero); Quaternion val3 = (((Object)(object)val != (Object)null) ? val.rotation : Quaternion.identity); int num; int num2; if ((Object)(object)val != (Object)null && IsFinite(val2)) { num = (IsFinite(val3) ? 1 : 0); if (num != 0) { num2 = (_hasTemporaryPivot ? 1 : 0); goto IL_006b; } } else { num = 0; } num2 = 0; goto IL_006b; IL_006b: bool flag = (byte)num2 != 0; bool flag2 = flag; Vector3 val4 = (flag2 ? GizmoPivot : val2); if (flag2 && !IsFinite(val4)) { flag2 = false; val4 = val2; } if (num != 0) { _desiredPosition = val2; _desiredRotation = val3; } CancelDrag(); _space = ((_space == CoordinateSpace.World) ? CoordinateSpace.Local : CoordinateSpace.World); RefreshToolbarLabels(); _placementInputBlockedThroughFrame = Mathf.Max(_placementInputBlockedThroughFrame, Time.frameCount); if (num != 0 && HasGizmoTarget) { _targetGhost.transform.SetPositionAndRotation(val2, val3); _desiredPosition = val2; _desiredRotation = val3; if (flag2) { SetTemporaryPivot(val4); } else if (flag) { ClearTemporaryPivot(clearSurfaceSupport: false); } } } private void ToggleSurfaceSnapping() { CancelDrag(); _surfaceSnapEnabled = !_surfaceSnapEnabled; _placementInputBlockedThroughFrame = Mathf.Max(_placementInputBlockedThroughFrame, Time.frameCount); if (!_surfaceSnapEnabled) { ClearTemporaryPivot(clearSurfaceSupport: false); if (HasGizmoTarget && (Object)(object)Player.m_localPlayer != (Object)null) { ValidateEditedGhost(Player.m_localPlayer, _targetPiece, flashGuardStone: false); } } if (_cameraRayFollowEnabled) { _cameraRayFollowUpdatePending = true; } RefreshToolbarLabels(); } private void ToggleCameraLight() { if ((Object)(object)_cameraLight != (Object)null) { DestroyCameraLight(); } else { CreateCameraLight(); } RefreshToolbarLabels(); } private void ToggleCameraRayFollow() { CancelDrag(); _cameraRayFollowEnabled = !_cameraRayFollowEnabled; _cameraRayFollowUpdatePending = _cameraRayFollowEnabled; _hasCameraRayFollowInput = false; _placementInputBlockedThroughFrame = Mathf.Max(_placementInputBlockedThroughFrame, Time.frameCount); RefreshToolbarLabels(); } private void CreateCameraLight() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_004e: 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) //IL_0092: Unknown result type (might be due to invalid IL or missing references) DestroyCameraLight(); Camera editorCamera = EditorCamera; if ((Object)(object)editorCamera == (Object)null) { Plugin.LogError("Could not create camera light: editor camera is unavailable"); return; } GameObject val = null; try { val = new GameObject("Build Ease Camera Light") { hideFlags = (HideFlags)61 }; val.transform.SetParent(((Component)editorCamera).transform, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; _cameraLight = val.AddComponent(); ((Behaviour)_cameraLight).enabled = false; _cameraLight.type = (LightType)2; _cameraLight.color = CameraLightColor; _cameraLight.renderMode = (LightRenderMode)0; ApplyCameraLightSettings(); ((Behaviour)_cameraLight).enabled = true; } catch (Exception arg) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } _cameraLight = null; Plugin.LogError($"Could not create camera light: {arg}"); } } private void DestroyCameraLight() { GameObject val = null; if ((Object)(object)_cameraLight != (Object)null) { ((Behaviour)_cameraLight).enabled = false; val = ((Component)_cameraLight).gameObject; } _cameraLight = null; if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } } private void ApplyCameraLightSettings() { if (!((Object)(object)_cameraLight == (Object)null)) { _cameraLight.range = GetSafeConfigValue(Plugin.CameraLightRange.Value, 100f, 1f, 100f); _cameraLight.intensity = GetSafeConfigValue(Plugin.CameraLightIntensity.Value, 1.5f, 0f, 10f); _cameraLight.shadows = (LightShadows)0; _cameraLight.shadowStrength = 0f; } } private void HandlePointer() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) Camera editorCamera = EditorCamera; if ((Object)(object)editorCamera == (Object)null) { return; } if (_dragAxis != GizmoAxis.None) { if (Input.GetMouseButton(0)) { ContinueDrag(editorCamera); } else { CancelDrag(); } } else if (!IsPointerOverToolbar()) { _gizmo.HoveredAxis = (HasGizmoTarget ? _gizmo.HitTest(editorCamera, Input.mousePosition) : GizmoAxis.None); if (Input.GetMouseButtonDown(0) && _gizmo.HoveredAxis != GizmoAxis.None) { _placementInputBlockedThroughFrame = Mathf.Max(_placementInputBlockedThroughFrame, Time.frameCount); BeginDrag(editorCamera, _gizmo.HoveredAxis); } } } private bool BeginDrag(Camera camera, GizmoAxis axis) { //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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_0123: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0143: 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_0184: 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_0354: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_036a: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_037f: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) if (!HasGizmoTarget) { return false; } if (axis == GizmoAxis.Center && _mode != EditMode.Translate) { return false; } Vector3 gizmoPivot = GizmoPivot; _dragStartRootPosition = _targetGhost.transform.position; _dragStartPivot = gizmoPivot; _dragStartRotation = _targetGhost.transform.rotation; _dragUsesScreenSpace = false; _dragBoundsTranslationStep = 0f; _dragSnapPointTranslationStep = 0f; _dragStartMouse = Vector2.op_Implicit(Input.mousePosition); Ray val = camera.ScreenPointToRay(Input.mousePosition); if (axis == GizmoAxis.Center) { _dragPlane = new Plane(((Component)camera).transform.forward, gizmoPivot); float num = default(float); if (!((Plane)(ref _dragPlane)).Raycast(val, ref num)) { return false; } _dragStartPlanePoint = ((Ray)(ref val)).GetPoint(num); _dragAxis = axis; _gizmo.ActiveAxis = axis; return true; } _dragWorldAxis = GetWorldAxis(axis); if (_mode == EditMode.Translate) { _dragBoundsTranslationStep = GetProjectedTargetSize(_dragWorldAxis); _dragSnapPointTranslationStep = GetProjectedSnapPointSpan(_dragWorldAxis); if (Mathf.Abs(Vector3.Dot(_dragWorldAxis, ((Component)camera).transform.forward)) > 0.96f) { float num2 = Mathf.Max(0.5f, camera.WorldToScreenPoint(gizmoPivot).z); float num3 = 2f * num2 * Mathf.Tan(camera.fieldOfView * ((float)Math.PI / 180f) * 0.5f); _dragUsesScreenSpace = true; _dragScreenDirection = Vector2.up * ((Vector3.Dot(_dragWorldAxis, ((Component)camera).transform.forward) >= 0f) ? 1f : (-1f)); _dragScreenScale = num3 / Mathf.Max(1f, (float)Screen.height); } if (_dragUsesScreenSpace) { _dragAxis = axis; _gizmo.ActiveAxis = axis; return true; } Vector3 val2 = Vector3.Cross(_dragWorldAxis, Vector3.Cross(((Component)camera).transform.forward, _dragWorldAxis)); if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f) { val2 = Vector3.Cross(_dragWorldAxis, ((Component)camera).transform.up); } if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f) { return false; } _dragPlane = new Plane(((Vector3)(ref val2)).normalized, gizmoPivot); float num4 = default(float); if (!((Plane)(ref _dragPlane)).Raycast(val, ref num4)) { return false; } _dragStartAxisParameter = Vector3.Dot(((Ray)(ref val)).GetPoint(num4) - gizmoPivot, _dragWorldAxis); } else { if (Mathf.Abs(Vector3.Dot(_dragWorldAxis, ((Component)camera).transform.forward)) < 0.12f) { Vector3 val3 = camera.WorldToScreenPoint(gizmoPivot); Vector3 val4 = camera.WorldToScreenPoint(gizmoPivot + _dragWorldAxis) - val3; Vector2 val5 = default(Vector2); ((Vector2)(ref val5))..ctor(val4.x, val4.y); _dragUsesScreenSpace = true; Vector2 dragScreenDirection; if (!(((Vector2)(ref val5)).sqrMagnitude > 0.001f)) { dragScreenDirection = Vector2.right; } else { Vector2 val6 = new Vector2(0f - val5.y, val5.x); dragScreenDirection = ((Vector2)(ref val6)).normalized; } _dragScreenDirection = dragScreenDirection; _dragScreenScale = 0.35f; } if (_dragUsesScreenSpace) { _dragAxis = axis; _gizmo.ActiveAxis = axis; return true; } _dragPlane = new Plane(_dragWorldAxis, gizmoPivot); float num5 = default(float); if (!((Plane)(ref _dragPlane)).Raycast(val, ref num5)) { return false; } Vector3 val7 = ((Ray)(ref val)).GetPoint(num5) - gizmoPivot; if (((Vector3)(ref val7)).sqrMagnitude < 0.0001f) { return false; } _dragStartVector = ((Vector3)(ref val7)).normalized; } _dragAxis = axis; _gizmo.ActiveAxis = axis; return true; } private void ContinueDrag(Camera camera) { //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: 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_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: 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_0277: 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_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_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0154: 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_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) if (!HasGizmoTarget) { CancelDrag(); return; } bool flag; Vector3 val3; if (_dragAxis == GizmoAxis.Center) { flag = ContinueCenterDrag(camera); } else if (_mode == EditMode.Translate) { float num; if (_dragUsesScreenSpace) { num = Vector2.Dot(Vector2.op_Implicit(Input.mousePosition) - _dragStartMouse, _dragScreenDirection) * _dragScreenScale; } else { Ray val = camera.ScreenPointToRay(Input.mousePosition); float num2 = default(float); if (!((Plane)(ref _dragPlane)).Raycast(val, ref num2)) { return; } num = Vector3.Dot(((Ray)(ref val)).GetPoint(num2) - _dragStartPivot, _dragWorldAxis) - _dragStartAxisParameter; } float num3 = 0f; if (IsBoundsStepModifierHeld()) { num3 = _dragBoundsTranslationStep; } else if (IsShiftHeld()) { num3 = ((_dragSnapPointTranslationStep > 0.001f) ? _dragSnapPointTranslationStep : _dragBoundsTranslationStep); } if (num3 > 0.001f) { num = Mathf.Round(num / num3) * num3; } Vector3 val2 = _dragStartRootPosition + _dragWorldAxis * num; flag = false; if (IsFinite(val2)) { val3 = _targetGhost.transform.position - val2; if (((Vector3)(ref val3)).sqrMagnitude > 1E-08f) { _targetGhost.transform.position = val2; _desiredPosition = val2; _surfaceSupportInvalid = false; flag = true; } } } else { float num4; if (_dragUsesScreenSpace) { num4 = Vector2.Dot(Vector2.op_Implicit(Input.mousePosition) - _dragStartMouse, _dragScreenDirection) * _dragScreenScale; } else { Ray val4 = camera.ScreenPointToRay(Input.mousePosition); float num5 = default(float); if (!((Plane)(ref _dragPlane)).Raycast(val4, ref num5)) { return; } Vector3 val5 = ((Ray)(ref val4)).GetPoint(num5) - _dragStartPivot; if (((Vector3)(ref val5)).sqrMagnitude <= 0.0001f) { return; } num4 = Vector3.SignedAngle(_dragStartVector, ((Vector3)(ref val5)).normalized, _dragWorldAxis); } float num6 = (IsShiftHeld() ? 90f : GetRotationStep()); if (num6 > 0f) { num4 = Mathf.Round(num4 / num6) * num6; } Quaternion val6 = Quaternion.AngleAxis(num4, _dragWorldAxis); Quaternion val7 = val6 * _dragStartRotation; Vector3 val8 = _dragStartPivot + val6 * (_dragStartRootPosition - _dragStartPivot); flag = false; if (IsFinite(val7) && IsFinite(val8)) { if (!(Quaternion.Angle(_targetGhost.transform.rotation, val7) > 0.001f)) { val3 = _targetGhost.transform.position - val8; if (!(((Vector3)(ref val3)).sqrMagnitude > 1E-08f)) { goto IL_02fa; } } _targetGhost.transform.SetPositionAndRotation(val8, val7); _desiredPosition = val8; _desiredRotation = val7; if (!_hasTemporaryPivot) { _surfaceSupportInvalid = false; } flag = true; } } goto IL_02fa; IL_02fa: if (flag && _cameraRayFollowEnabled) { _cameraRayFollowUpdatePending = true; } if (flag && (Object)(object)Player.m_localPlayer != (Object)null) { ValidateEditedGhost(Player.m_localPlayer, _targetPiece, flashGuardStone: false); } } private bool ContinueCenterDrag(Camera camera) { //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_002b: 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_000a: 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_0015: 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_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_0051: 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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0059: 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) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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_007d: 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) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) if (_surfaceSnapEnabled) { return TryUpdateSurfaceSnap(camera.ScreenPointToRay(Input.mousePosition), _dragStartRotation); } Ray val = camera.ScreenPointToRay(Input.mousePosition); float num = default(float); if (!((Plane)(ref _dragPlane)).Raycast(val, ref num)) { return false; } Vector3 val2 = ((Ray)(ref val)).GetPoint(num) - _dragStartPlanePoint; Vector3 val3 = _dragStartRootPosition + val2; if (IsFinite(val3)) { Vector3 val4 = _targetGhost.transform.position - val3; if (!(((Vector3)(ref val4)).sqrMagnitude <= 1E-08f)) { ClearTemporaryPivot(); _targetGhost.transform.position = val3; _desiredPosition = val3; return true; } } return false; } private bool TryUpdateSurfaceSnap(Ray ray, Quaternion rotation) { //IL_0011: 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) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0197: 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_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: 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_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0135: 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_014a: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_026d: 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_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !TryGetSurfaceHit(localPlayer, ray, out var result)) { return false; } Transform transform = _targetGhost.transform; Vector3 position = transform.position; Vector3 gizmoPivot = GizmoPivot; bool surfaceSupportInvalid = _surfaceSupportInvalid; Piece val = (((Object)(object)((RaycastHit)(ref result)).collider != (Object)null) ? ((Component)((RaycastHit)(ref result)).collider).GetComponentInParent() : null); WearNTear val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent() : null); bool flag = (Object)(object)val2 != (Object)null && !val2.m_supports; Vector3 val3 = ((RaycastHit)(ref result)).point + ((RaycastHit)(ref result)).normal * 50f; transform.SetPositionAndRotation(val3, rotation); bool flag2 = false; float num = float.MaxValue; Vector3 val4 = ((RaycastHit)(ref result)).point; Collider[] targetColliders = _targetColliders; Vector3 val8; foreach (Collider val5 in targetColliders) { if ((Object)(object)val5 == (Object)null || !val5.enabled || !((Component)val5).gameObject.activeInHierarchy || val5.isTrigger) { continue; } MeshCollider val6 = (MeshCollider)(object)((val5 is MeshCollider) ? val5 : null); if (val6 == null || val6.convex) { Vector3 val7 = val5.ClosestPoint(((RaycastHit)(ref result)).point); val8 = val7 - ((RaycastHit)(ref result)).point; float sqrMagnitude = ((Vector3)(ref val8)).sqrMagnitude; if (IsFinite(val7) && sqrMagnitude < num) { flag2 = true; num = sqrMagnitude; val4 = val7; } } } Vector3 val9 = (flag2 ? (((RaycastHit)(ref result)).point + (val3 - val4)) : ((RaycastHit)(ref result)).point); if (!IsFinite(val9)) { transform.SetPositionAndRotation(position, rotation); return false; } if (!IsPositionWithinEditorRange(localPlayer, val9)) { transform.SetPositionAndRotation(position, rotation); return false; } transform.SetPositionAndRotation(val9, rotation); Vector3 val10 = ((RaycastHit)(ref result)).point; if (TryFindClosestBuildSnap(out var source, out var destination)) { Vector3 val11 = destination.position - (source.position - val9); if (IsFinite(val11) && IsPositionWithinEditorRange(localPlayer, val11) && !IsOverlappingOtherPiece(val11, rotation)) { val9 = (transform.position = val11); val10 = destination.position; } } _desiredPosition = val9; _desiredRotation = rotation; SetTemporaryPivot(val10); _surfaceSupportInvalid = flag; val8 = position - val9; if (!(((Vector3)(ref val8)).sqrMagnitude > 1E-08f)) { val8 = gizmoPivot - val10; if (!(((Vector3)(ref val8)).sqrMagnitude > 1E-08f)) { return surfaceSupportInvalid != flag; } } return true; } private bool TryGetSurfaceHit(Player player, Ray ray, out RaycastHit result) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) float num = (((Object)(object)_targetPiece != (Object)null) ? Mathf.Max(0f, (float)_targetPiece.m_extraPlacementDistance) : 0f); float num2 = Mathf.Clamp(Vector3.Distance(((Ray)(ref ray)).origin, ((Component)player).transform.position) + GetEditorRange() + num + 5f, 10f, 500f); int num3; while (true) { num3 = Physics.RaycastNonAlloc(ray, _surfaceRaycastBuffer, num2, PlaceRayMask.Invoke(player), (QueryTriggerInteraction)0); if (num3 < _surfaceRaycastBuffer.Length || _surfaceRaycastBuffer.Length >= 2048) { break; } Array.Resize(ref _surfaceRaycastBuffer, _surfaceRaycastBuffer.Length * 2); } bool result2 = false; float num4 = float.MaxValue; result = default(RaycastHit); for (int i = 0; i < num3; i++) { RaycastHit val = _surfaceRaycastBuffer[i]; Collider collider = ((RaycastHit)(ref val)).collider; if (!((Object)(object)collider == (Object)null) && !((Object)(object)collider.attachedRigidbody != (Object)null) && !((Object)(object)((Component)collider).transform == (Object)(object)_targetGhost.transform) && !((Component)collider).transform.IsChildOf(_targetGhost.transform) && !(((RaycastHit)(ref val)).distance >= num4)) { result = val; num4 = ((RaycastHit)(ref val)).distance; result2 = true; } } return result2; } private bool TryFindClosestBuildSnap(out Transform source, out Transform destination) { //IL_0049: 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_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) _sourceSnapPoints.Clear(); _destinationSnapPoints.Clear(); _nearbyPieces.Clear(); _nearbyPieceSet.Clear(); _targetPiece.GetSnapPoints(_sourceSnapPoints); int num = FillSnapPieceBuffer(_targetGhost.transform.position); for (int i = 0; i < num; i++) { Collider val = _snapPieceBuffer[i]; Piece val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInParent() : null); if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)_targetPiece) && _nearbyPieceSet.Add(val2)) { val2.GetSnapPoints(_destinationSnapPoints); _nearbyPieces.Add(val2); } } source = null; destination = null; float num2 = 0.25f; float num3 = float.MaxValue; foreach (Transform sourceSnapPoint in _sourceSnapPoints) { if ((Object)(object)sourceSnapPoint == (Object)null) { continue; } foreach (Transform destinationSnapPoint in _destinationSnapPoints) { if (!((Object)(object)destinationSnapPoint == (Object)null) && !((Object)(object)destinationSnapPoint == (Object)(object)sourceSnapPoint) && !destinationSnapPoint.IsChildOf(_targetGhost.transform)) { Vector3 val3 = sourceSnapPoint.position - destinationSnapPoint.position; float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude; if (sqrMagnitude <= num2 && sqrMagnitude < num3) { num3 = sqrMagnitude; source = sourceSnapPoint; destination = destinationSnapPoint; } } } } if ((Object)(object)source != (Object)null) { return (Object)(object)destination != (Object)null; } return false; } private int FillSnapPieceBuffer(Vector3 center) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) int num; while (true) { num = Physics.OverlapSphereNonAlloc(center, 10f, _snapPieceBuffer, _pieceLayerMask, (QueryTriggerInteraction)0); if (num < _snapPieceBuffer.Length || _snapPieceBuffer.Length >= 16384) { break; } Array.Resize(ref _snapPieceBuffer, Mathf.Min(_snapPieceBuffer.Length * 2, 16384)); } return num; } private bool IsOverlappingOtherPiece(Vector3 position, Quaternion rotation) { //IL_0030: 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) //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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) foreach (Piece nearbyPiece in _nearbyPieces) { if (!((Object)(object)nearbyPiece == (Object)null) && !((Object)(object)nearbyPiece == (Object)(object)_targetPiece)) { Vector3 val = position - ((Component)nearbyPiece).transform.position; if (!(((Vector3)(ref val)).sqrMagnitude >= 0.0025f) && Utils.CustomStartsWith(((Object)((Component)nearbyPiece).gameObject).name, ((Object)_targetGhost).name) && (!_targetPiece.m_allowRotatedOverlap || Quaternion.Angle(((Component)nearbyPiece).transform.rotation, rotation) <= 10f)) { return true; } } } return false; } private void SetTemporaryPivot(Vector3 worldPosition) { //IL_0008: 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_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_003b: 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) if (!HasGizmoTarget || !IsFinite(worldPosition)) { ClearTemporaryPivot(); return; } Vector3 val = _targetGhost.transform.InverseTransformPoint(worldPosition); if (!IsFinite(val)) { ClearTemporaryPivot(); return; } _temporaryPivotLocal = val; _hasTemporaryPivot = true; } private void ClearTemporaryPivot(bool clearSurfaceSupport = true) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) _hasTemporaryPivot = false; if (clearSurfaceSupport) { _surfaceSupportInvalid = false; } _temporaryPivotLocal = Vector3.zero; } private static bool IsPositionWithinEditorRange(Player player, Vector3 position) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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) float editorRange = GetEditorRange(); if ((Object)(object)player != (Object)null) { Vector3 val = position - ((Component)player).transform.position; return ((Vector3)(ref val)).sqrMagnitude <= editorRange * editorRange; } return false; } private static float GetRotationStep() { float value = Plugin.RotationSnap.Value; if (float.IsNaN(value) || float.IsInfinity(value)) { return 5f; } if (value <= 0f) { return 0f; } return Mathf.Clamp(value, 0.1f, 360f); } private static bool IsShiftHeld() { if (!Input.GetKey((KeyCode)304)) { return Input.GetKey((KeyCode)303); } return true; } private static bool IsBoundsStepModifierHeld() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) KeyCode value = Plugin.BoundsStepModifier.Value; if ((int)value != 0) { return Input.GetKey(value); } return false; } private void CancelDrag() { _dragAxis = GizmoAxis.None; _dragUsesScreenSpace = false; _dragBoundsTranslationStep = 0f; _dragSnapPointTranslationStep = 0f; if ((Object)(object)_gizmo != (Object)null) { _gizmo.ActiveAxis = GizmoAxis.None; } } internal void UpdatePlayerPlacement(Player player, float dt) { //IL_01fd: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: 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_0180: 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) _copiedPieceThisPlacementUpdate = false; _hasSampledPlacementRotation = false; _sampledCopySucceededThisPlacementUpdate = false; if (!_active || (Object)(object)player != (Object)(object)Player.m_localPlayer || _placementUpdateFailed || IsGameUiBlockingEditorInput() || Time.frameCount <= _uiInputBlockedThroughFrame || Time.frameCount <= _placementInputBlockedThroughFrame) { return; } HandlePlayerHotkeys(player); if (!((Character)player).InPlaceMode()) { ExitEditor(); return; } bool flag = IsVanillaCopyRequested(); if (Input.GetMouseButton(1) || _rightMouseActive || _dragAxis != GizmoAxis.None || IsPointerOverToolbar() || (!flag && IsPointerOverGizmo())) { return; } if (UpdatePlacementInvoker == null) { _placementUpdateFailed = true; Plugin.LogError("Player.UpdatePlacement(bool,float) was not found"); ExitEditor(); return; } try { bool flag2 = HasGizmoTarget && !Hud.IsPieceSelectionVisible(); PlacementRotationSnapshot snapshot = (flag2 ? CapturePlacementRotation(player) : default(PlacementRotationSnapshot)); Transform val = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).transform : null); Quaternion rotation = default(Quaternion); bool flag3 = false; if ((Object)(object)val != (Object)null && ShouldRenderEditorOverlay && !Hud.IsPieceSelectionVisible()) { Camera editorCamera = EditorCamera; if ((Object)(object)editorCamera != (Object)null) { Ray val2 = editorCamera.ScreenPointToRay(Input.mousePosition); if (IsFinite(((Ray)(ref val2)).direction)) { Vector3 direction = ((Ray)(ref val2)).direction; if (((Vector3)(ref direction)).sqrMagnitude > 0.0001f) { rotation = val.rotation; val.rotation = Quaternion.LookRotation(((Ray)(ref val2)).direction, ((Component)editorCamera).transform.up); flag3 = true; } } } } _insidePlacementUpdate = true; try { UpdatePlacementInvoker(player, arg2: true, dt); } finally { _insidePlacementUpdate = false; if (_sampledCopySucceededThisPlacementUpdate && _hasSampledPlacementRotation) { FinalizeSampledPlacementState(player); } else if (flag2 && !_copiedPieceThisPlacementUpdate) { RestorePlacementRotation(player, snapshot); } _copiedPieceThisPlacementUpdate = false; _hasSampledPlacementRotation = false; _sampledCopySucceededThisPlacementUpdate = false; if (flag3 && (Object)(object)val != (Object)null) { val.rotation = rotation; } } } catch (Exception arg) { _placementUpdateFailed = true; Plugin.LogError($"Player.UpdatePlacement failed: {arg}"); ((Character)player).Message((MessageType)1, _language.PlacementError, 0, (Sprite)null); ExitEditor(); } } private static void HandlePlayerHotkeys(Player player) { for (int i = 0; i < HotbarButtons.Length; i++) { if (Input.GetKeyDown(HotbarKeys[i]) || ZInput.GetButtonDown(HotbarButtons[i])) { player.UseHotbarItem(i + 1); break; } } if ((ZInput.GetButtonDown("Hide") || ZInput.GetButtonDown("JoyHide")) && !((Character)player).InAttack()) { ((Humanoid)player).HideHandItems(false, true); } } private static bool IsVanillaCopyRequested() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) bool num = (ZInput.GetButtonDown("Remove") || ZInput.GetButtonDown("JoyRemove")) && (ZInput.GetButton("AltPlace") || ZInput.GetButton("JoyAltKeys")) && ((int)ZInput.InputLayout == 0 || !ZInput.IsGamepadActive()); bool flag = ZInput.GetButton("JoyAltKeys") && (ZInput.GetButtonDown("Attack") || ZInput.GetButtonDown("JoyPlace")) && !Hud.InRadial(); return num || flag; } internal bool ShouldBlockVanillaPlacement(Player player) { if (!_active || (Object)(object)player != (Object)(object)Player.m_localPlayer) { return false; } if (IsEditorBlockedInCurrentInterior(player)) { ((Character)player).Message((MessageType)2, "$msg_notindungeon", 0, (Sprite)null); return true; } if (IsCurrentGhostOutsideEditorRange(player)) { ((Character)player).Message((MessageType)2, "$msg_invalidplacement", 0, (Sprite)null); return true; } if (Time.frameCount <= _placementInputBlockedThroughFrame || IsCameraCaptured || _dragAxis != GizmoAxis.None || IsPointerOverToolbar() || IsPointerOverGizmo()) { return true; } return false; } internal void OnVanillaPlacementSucceeded(Player player) { //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) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0055: 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) if (_active && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && HasGizmoTarget) { Transform transform = _targetGhost.transform; Vector3 position = transform.position; Quaternion rotation = transform.rotation; if (!IsFinite(position) || !IsFinite(rotation)) { ClearPlacementGhostTarget(); return; } _desiredPosition = position; _desiredRotation = rotation; FreezeCameraRayFollowInput(); CancelDrag(); _hasCachedPlacementStatus = false; ValidateEditedGhost(player, _targetPiece, flashGuardStone: false); } } internal bool TryCaptureSampledPiecePose(Player player, Piece source, out Vector3 position, out Quaternion rotation) { //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_000d: 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_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_0059: 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) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) position = Vector3.zero; rotation = Quaternion.identity; if (!_active || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || (Object)(object)source == (Object)null) { return false; } position = ((Component)source).transform.position; rotation = ((Component)source).transform.rotation; if (IsFinite(position)) { return IsFinite(rotation); } return false; } internal void OnVanillaPieceSampled(Player player, Vector3 position, Quaternion rotation) { //IL_001e: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00ac: 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) if (!_active || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || !IsFinite(position) || !IsFinite(rotation)) { return; } _copiedPieceThisPlacementUpdate = true; _hasSampledPlacementRotation = true; _sampledPlacementRotation = rotation; ClearPlacementGhostTarget(); GameObject placementGhost = GetPlacementGhost(player); Piece selectedPiece = player.GetSelectedPiece(); if (!((Object)(object)placementGhost == (Object)null) && !((Object)(object)selectedPiece == (Object)null) && IsSelectedPieceGizmoCompatible(selectedPiece)) { SetPlacementGhostTarget(placementGhost, selectedPiece); if (HasGizmoTarget) { _desiredPosition = position; _desiredRotation = rotation; _surfaceSupportInvalid = false; _hasCachedPlacementStatus = false; _targetGhost.transform.SetPositionAndRotation(position, rotation); } } } internal void OnVanillaCopyCompleted(Player player, bool succeeded) { if (succeeded && _hasSampledPlacementRotation && _active && !((Object)(object)player == (Object)null) && !((Object)(object)player != (Object)(object)Player.m_localPlayer)) { _sampledPlaceRotation = PlaceRotation.Invoke(player); _sampledCopySucceededThisPlacementUpdate = true; if (!_insidePlacementUpdate) { FinalizeSampledPlacementState(player); _copiedPieceThisPlacementUpdate = false; _hasSampledPlacementRotation = false; _sampledCopySucceededThisPlacementUpdate = false; } } } private void FinalizeSampledPlacementState(Player player) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) PlaceRotation.Invoke(player) = _sampledPlaceRotation; ScrollCurrentAmount.Invoke(player) = 0f; RotatePieceTimer.Invoke(player) = 0f; SynchronizePerfectPlacementRotation(player, _sampledPlacementRotation); } private void RefreshPlacementGhostReference(Player player) { GameObject placementGhost = GetPlacementGhost(player); Piece selectedPiece = player.GetSelectedPiece(); if ((Object)(object)_targetSelectedPiece != (Object)null && (Object)(object)selectedPiece != (Object)(object)_targetSelectedPiece) { ClearPlacementGhostTarget(); } else if ((Object)(object)_targetSelectedPiece != (Object)null && (Object)(object)placementGhost != (Object)null && (Object)(object)placementGhost != (Object)(object)_targetGhost && !TryRetargetPlacementGhost(placementGhost, selectedPiece)) { ClearPlacementGhostTarget(); } else if ((Object)(object)_targetSelectedPiece != (Object)null && (Object)(object)placementGhost == (Object)null && (Object)(object)_targetGhost == (Object)null && _targetGhost != null) { DetachDestroyedPlacementGhost(); } if ((Object)(object)_targetSelectedPiece == (Object)null && (Object)(object)placementGhost == (Object)null) { SetTargetStatus(TargetStatusKind.NoGhost); } } internal void ApplyGhostOverride(Player player, bool flashGuardStone) { //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Invalid comparison between Unknown and I4 //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_016f: 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_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) if (!_active || (Object)(object)player != (Object)(object)Player.m_localPlayer) { return; } GameObject placementGhost = GetPlacementGhost(player); if (_blueGhostPreviewEnabled) { _placementGhostVisual.Sync(placementGhost); } Piece selectedPiece = player.GetSelectedPiece(); if ((Object)(object)_targetSelectedPiece != (Object)null && (Object)(object)_targetSelectedPiece != (Object)(object)selectedPiece) { ClearPlacementGhostTarget(); } else if ((Object)(object)_targetSelectedPiece != (Object)null && (Object)(object)placementGhost != (Object)(object)_targetGhost) { if ((Object)(object)placementGhost == (Object)null) { return; } if (!TryRetargetPlacementGhost(placementGhost, selectedPiece)) { ClearPlacementGhostTarget(); } } else if ((Object)(object)_targetSelectedPiece != (Object)null && (Object)(object)_targetGhost == (Object)null && _targetGhost != null) { DetachDestroyedPlacementGhost(); } bool flag = IsSelectedPieceGizmoCompatible(selectedPiece); if ((Object)(object)_targetSelectedPiece == (Object)null && (Object)(object)placementGhost != (Object)null && flag && (int)player.GetPlacementStatus() != 12) { SetPlacementGhostTarget(placementGhost, selectedPiece); } if (!HasGizmoTarget || (Object)(object)placementGhost != (Object)(object)_targetGhost) { if ((Object)(object)placementGhost != (Object)null && (Object)(object)selectedPiece != (Object)null && !flag) { SetTargetStatus(TargetStatusKind.SpecialPiece); } return; } Transform transform = _targetGhost.transform; Vector3 val = transform.position - _desiredPosition; if (((Vector3)(ref val)).sqrMagnitude > 1E-08f || Quaternion.Angle(transform.rotation, _desiredRotation) > 0.001f) { transform.SetPositionAndRotation(_desiredPosition, _desiredRotation); } if (!_targetGhost.activeSelf) { _targetGhost.SetActive(true); } GameObject val2 = PlacementMarker.Invoke(player); if ((Object)(object)val2 != (Object)null && val2.activeSelf) { val2.SetActive(false); } if (!_hasCachedPlacementStatus || flashGuardStone) { ValidateEditedGhost(player, _targetPiece, flashGuardStone); } else { RestoreCachedPlacementStatus(player, _targetPiece); } } internal bool ShouldSkipVanillaGhostUpdate(Player player) { if (_active && (Object)(object)player == (Object)(object)Player.m_localPlayer && HasGizmoTarget && (Object)(object)GetPlacementGhost(player) == (Object)(object)_targetGhost) { return (Object)(object)player.GetSelectedPiece() == (Object)(object)_targetSelectedPiece; } return false; } internal bool TryGetFinalPlacementPose(Player player, Piece selectedPiece, out Vector3 position, out Quaternion rotation) { //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_000d: 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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: 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) position = Vector3.zero; rotation = Quaternion.identity; if (!_active || (Object)(object)player != (Object)(object)Player.m_localPlayer || !HasGizmoTarget || (Object)(object)selectedPiece == (Object)null || (Object)(object)selectedPiece != (Object)(object)_targetSelectedPiece || (Object)(object)GetPlacementGhost(player) != (Object)(object)_targetGhost || !IsFinite(_desiredPosition) || !IsFinite(_desiredRotation)) { return false; } position = _desiredPosition; rotation = _desiredRotation; return true; } internal void EnforceEditorRange(Player player) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (_active && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && IsCurrentGhostOutsideEditorRange(player)) { PlacementStatus.Invoke(player) = (PlacementStatus)1; GameObject placementGhost = GetPlacementGhost(player); Piece val = (((Object)(object)placementGhost != (Object)null) ? placementGhost.GetComponent() : null); if ((Object)(object)val != (Object)null) { val.SetInvalidPlacementHeightlight(true); } if ((Object)(object)placementGhost == (Object)(object)_targetGhost) { _cachedPlacementStatus = (PlacementStatus)1; _hasCachedPlacementStatus = true; } } } private void SetPlacementGhostTarget(GameObject ghost, Piece selectedPiece) { //IL_003d: 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_004e: 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) ClearTemporaryPivot(); _targetGhost = ghost; _targetPiece = ghost.GetComponent(); _targetSelectedPiece = selectedPiece; if ((Object)(object)_targetPiece == (Object)null) { ClearPlacementGhostTarget(); return; } _desiredPosition = ghost.transform.position; _desiredRotation = ghost.transform.rotation; if (_cameraRayFollowEnabled) { _cameraRayFollowUpdatePending = true; } _targetColliders = ghost.GetComponentsInChildren(true); _targetGeometryRenderers = ghost.GetComponentsInChildren(true); SetTargetStatus(TargetStatusKind.Piece, GetPieceStatusToken(_targetPiece, ghost)); CancelDrag(); } private bool TryRetargetPlacementGhost(GameObject ghost, Piece selectedPiece) { //IL_0026: 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_008b: 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) if ((Object)(object)ghost == (Object)null || (Object)(object)_targetSelectedPiece == (Object)null || (Object)(object)selectedPiece != (Object)(object)_targetSelectedPiece || !IsFinite(_desiredPosition) || !IsFinite(_desiredRotation)) { return false; } Piece component = ghost.GetComponent(); if ((Object)(object)component == (Object)null || !IsSelectedPieceGizmoCompatible(selectedPiece)) { return false; } _targetGhost = ghost; _targetPiece = component; _targetColliders = ghost.GetComponentsInChildren(true); _targetGeometryRenderers = ghost.GetComponentsInChildren(true); ghost.transform.SetPositionAndRotation(_desiredPosition, _desiredRotation); _hasCachedPlacementStatus = false; SetTargetStatus(TargetStatusKind.Piece, GetPieceStatusToken(_targetPiece, ghost)); CancelDrag(); return true; } private void ReleasePlacementGhost() { if (_cameraRayFollowEnabled) { _cameraRayFollowEnabled = false; _cameraRayFollowUpdatePending = false; _hasCameraRayFollowInput = false; RefreshToolbarLabels(); } ClearPlacementGhostTarget(); } private void DetachDestroyedPlacementGhost() { _targetGhost = null; _targetPiece = null; _targetColliders = Array.Empty(); _targetGeometryRenderers = Array.Empty(); _hasCachedPlacementStatus = false; CancelDrag(); if ((Object)(object)_gizmo != (Object)null) { _gizmo.HoveredAxis = GizmoAxis.None; } } private void ClearPlacementGhostTarget() { ClearTemporaryPivot(); _targetGhost = null; _targetPiece = null; _targetSelectedPiece = null; _hasCachedPlacementStatus = false; _targetColliders = Array.Empty(); _targetGeometryRenderers = Array.Empty(); SetTargetStatus(TargetStatusKind.NoGhost); CancelDrag(); if ((Object)(object)_gizmo != (Object)null) { _gizmo.HoveredAxis = GizmoAxis.None; } } private void SetTargetStatus(TargetStatusKind kind, string pieceToken = null) { if (_targetStatusKind != kind || !string.Equals(_targetStatusPieceToken, pieceToken, StringComparison.Ordinal)) { _targetStatusKind = kind; _targetStatusPieceToken = pieceToken; RefreshTargetStatusText(); } } private void RefreshTargetStatusText() { string text; switch (_targetStatusKind) { case TargetStatusKind.SpecialPiece: text = _language.SpecialPiece; break; case TargetStatusKind.Piece: { string text2 = _targetStatusPieceToken ?? string.Empty; if (text2.IndexOf('$') >= 0) { string text3 = Localization.instance.Localize(text2); if (!string.IsNullOrEmpty(text3)) { text2 = text3; } } text = _language.PiecePrefix + text2; break; } default: text = _language.NoGhost; break; } _targetStatusText = text + _language.ToolbarHelp; } private static string GetPieceStatusToken(Piece piece, GameObject ghost) { if ((Object)(object)piece != (Object)null && !string.IsNullOrEmpty(piece.m_name)) { return piece.m_name; } if (!((Object)(object)ghost != (Object)null)) { return string.Empty; } return ((Object)ghost).name.Replace("(Clone)", string.Empty); } private void ValidateEditedGhost(Player player, Piece piece, bool flashGuardStone) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_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) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00db: 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_00f4: Expected I4, but got Unknown //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Invalid comparison between Unknown and I4 //IL_00d8: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)piece == (Object)null)) { Vector3 position = ((Component)piece).transform.position; PlacementStatus val = (PlacementStatus)0; float editorRange = GetEditorRange(); Vector3 val2 = position - ((Component)player).transform.position; if (((Vector3)(ref val2)).sqrMagnitude > editorRange * editorRange) { val = (PlacementStatus)1; } if (_surfaceSupportInvalid) { val = (PlacementStatus)1; } if (IsEditorBlockedInCurrentInterior(player)) { val = (PlacementStatus)11; } if ((int)piece.m_onlyInBiome != 0 && (Heightmap.FindBiome(position) & piece.m_onlyInBiome) == 0) { val = (PlacementStatus)8; } if (Location.IsInsideNoBuildLocation(position)) { val = (PlacementStatus)3; } PrivateArea component = ((Component)piece).GetComponent(); float num = (((Object)(object)component != (Object)null) ? component.m_radius : 0f); if (!PrivateArea.CheckAccess(position, num, flashGuardStone, (Object)(object)component != (Object)null)) { val = (PlacementStatus)4; } if (CheckEditedGhostVsCharacters(((Component)piece).gameObject, position)) { val = (PlacementStatus)2; } if (piece.m_noClipping && TestEditedGhostClipping(player, ((Component)piece).gameObject, 0.2f)) { val = (PlacementStatus)1; } _cachedPlacementStatus = val; _hasCachedPlacementStatus = true; PlacementStatus.Invoke(player) = (PlacementStatus)(int)val; piece.SetInvalidPlacementHeightlight((int)val > 0); } } private void RestoreCachedPlacementStatus(Player player, Piece piece) { //IL_0001: 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_0018: Expected I4, but got Unknown //IL_0019: Invalid comparison between Unknown and I4 //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 PlacementStatus placementStatus = player.GetPlacementStatus(); PlacementStatus.Invoke(player) = (PlacementStatus)(int)_cachedPlacementStatus; bool num = (int)placementStatus > 0; bool flag = (int)_cachedPlacementStatus > 0; if (num != flag) { piece.SetInvalidPlacementHeightlight(flag); } } private bool CheckEditedGhostVsCharacters(GameObject ghost, Vector3 position) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: 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) _nearbyCharacters.Clear(); Character.GetCharactersInRange(position, 30f, _nearbyCharacters); Collider[] targetColliders = _targetColliders; Vector3 val4 = default(Vector3); float num = default(float); foreach (Collider val in targetColliders) { if ((Object)(object)val == (Object)null || !val.enabled || !((Component)val).gameObject.activeInHierarchy || val.isTrigger || (Object)(object)((Component)val).gameObject == (Object)(object)ghost) { continue; } MeshCollider val2 = (MeshCollider)(object)((val is MeshCollider) ? val : null); if (val2 != null && !val2.convex) { continue; } foreach (Character nearbyCharacter in _nearbyCharacters) { CapsuleCollider val3 = (((Object)(object)nearbyCharacter != (Object)null) ? nearbyCharacter.GetCollider() : null); if (!((Object)(object)val3 == (Object)null) && ((Collider)val3).enabled && ((Component)val3).gameObject.activeInHierarchy && Physics.ComputePenetration(val, ((Component)val).transform.position, ((Component)val).transform.rotation, (Collider)(object)val3, ((Component)val3).transform.position, ((Component)val3).transform.rotation, ref val4, ref num)) { return true; } } } return false; } private bool TestEditedGhostClipping(Player player, GameObject ghost, float maxPenetration) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0178: 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) int num; while (true) { num = Physics.OverlapSphereNonAlloc(ghost.transform.position, 10f, _clippingBuffer, PlaceRayMask.Invoke(player), (QueryTriggerInteraction)0); if (num < _clippingBuffer.Length || _clippingBuffer.Length >= 32768) { break; } Array.Resize(ref _clippingBuffer, Mathf.Min(_clippingBuffer.Length * 2, 32768)); } Collider[] array = _clippingBuffer; if (num == _clippingBuffer.Length) { array = Physics.OverlapSphere(ghost.transform.position, 10f, PlaceRayMask.Invoke(player), (QueryTriggerInteraction)0); num = array.Length; int newSize = num + Mathf.Max(256, num / 2); Array.Resize(ref array, newSize); _clippingBuffer = array; } Collider[] targetColliders = _targetColliders; Vector3 val3 = default(Vector3); float num2 = default(float); foreach (Collider val in targetColliders) { if ((Object)(object)val == (Object)null || !val.enabled || !((Component)val).gameObject.activeInHierarchy) { continue; } for (int j = 0; j < num; j++) { Collider val2 = array[j]; if (!((Object)(object)val2 == (Object)null) && val2.enabled && ((Component)val2).gameObject.activeInHierarchy && !((Object)(object)((Component)val2).transform == (Object)(object)ghost.transform) && !((Component)val2).transform.IsChildOf(ghost.transform) && Physics.ComputePenetration(val, ((Component)val).transform.position, ((Component)val).transform.rotation, val2, ((Component)val2).transform.position, ((Component)val2).transform.rotation, ref val3, ref num2) && num2 > maxPenetration) { return true; } } } return false; } internal static bool IsGizmoCompatiblePiece(Piece piece) { if ((Object)(object)piece != (Object)null && !piece.m_groundPiece && !piece.m_groundOnly && !piece.m_cultivatedGroundOnly && !piece.m_vegetationGroundOnly && !piece.m_waterPiece && !piece.m_onlyInTeleportArea && (!(piece.m_blockRadius > 0f) || piece.m_blockingPieces == null || piece.m_blockingPieces.Count <= 0) && (Object)(object)piece.m_mustConnectTo == (Object)null && !piece.m_repairPiece && !piece.m_removePiece && !piece.m_isUpgrade && !piece.m_harvest && (Object)(object)((Component)piece).GetComponentInChildren(true) == (Object)null && (Object)(object)((Component)piece).GetComponentInChildren(true) == (Object)null) { return (Object)(object)((Component)piece).GetComponentInChildren(true) == (Object)null; } return false; } private bool IsSelectedPieceGizmoCompatible(Piece piece) { if ((Object)(object)_observedSelectedPiece != (Object)(object)piece) { _observedSelectedPiece = piece; _observedSelectedPieceCompatible = IsGizmoCompatiblePiece(piece); } return _observedSelectedPieceCompatible; } private void BeginEditorEntry() { Player localPlayer = Player.m_localPlayer; RefreshEditorLanguage(); if ((Object)(object)localPlayer == (Object)null || (Object)(object)GameCamera.instance == (Object)null || (Object)(object)ResolveGameCamera() == (Object)null || ((Character)localPlayer).IsDead() || ((Character)localPlayer).InCutscene() || ((Character)localPlayer).IsTeleporting() || IsGameUiBlockingEditorInput()) { return; } if (IsConflictingEditorActive()) { ((Character)localPlayer).Message((MessageType)1, _language.DisableConflictingEditor, 0, (Sprite)null); return; } if (IsBuildingHammer(((Humanoid)localPlayer).RightItem) && ((Character)localPlayer).InPlaceMode()) { if (!RejectBlockedInteriorEditorEntry(localPlayer)) { EnterEditor(); } return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); ItemData val = FindBuildingHammer(inventory); if (val == null) { ((Character)localPlayer).Message((MessageType)1, _language.NoBuildingHammer, 0, (Sprite)null); } else if (!RejectBlockedInteriorEditorEntry(localPlayer)) { _editorEntryPending = true; _pendingEquipIssued = false; _pendingOwnEquipAction = false; _pendingEntryPlayer = localPlayer; _pendingEntryInventory = inventory; _pendingEntryHammer = val; _pendingEntryDeadline = Time.unscaledTime + 8f; UpdatePendingEditorEntry(); } } private void UpdatePendingEditorEntry() { if (!_editorEntryPending) { return; } Player pendingEntryPlayer = _pendingEntryPlayer; Inventory pendingEntryInventory = _pendingEntryInventory; ItemData pendingEntryHammer = _pendingEntryHammer; if ((Object)(object)pendingEntryPlayer == (Object)null || Player.m_localPlayer != pendingEntryPlayer || ((Character)pendingEntryPlayer).IsDead() || ((Character)pendingEntryPlayer).InCutscene() || ((Character)pendingEntryPlayer).IsTeleporting() || IsGameUiBlockingEditorInput()) { CancelPendingEditorEntry(removeOwnedEquipAction: true); } else if (IsConflictingEditorActive()) { CancelPendingEditorEntry(removeOwnedEquipAction: true); ((Character)pendingEntryPlayer).Message((MessageType)1, _language.DisableConflictingEditor, 0, (Sprite)null); } else if (pendingEntryInventory == null || pendingEntryHammer == null || !pendingEntryInventory.ContainsItem(pendingEntryHammer) || !IsBuildingHammer(pendingEntryHammer)) { FailPendingEditorEntry(pendingEntryPlayer); } else if (IsEditorBlockedInCurrentInterior(pendingEntryPlayer)) { CancelPendingEditorEntry(removeOwnedEquipAction: true); ((Character)pendingEntryPlayer).Message((MessageType)2, "$msg_notindungeon", 0, (Sprite)null); } else if (IsHammerEquippedForBuilding(pendingEntryPlayer, pendingEntryHammer)) { CompletePendingEditorEntry(pendingEntryPlayer); } else if (Time.unscaledTime >= _pendingEntryDeadline) { FailPendingEditorEntry(pendingEntryPlayer); } else if (!_pendingEquipIssued) { if (!((Character)pendingEntryPlayer).InAttack() && !((Character)pendingEntryPlayer).InDodge() && (!((Character)pendingEntryPlayer).IsSwimming() || ((Character)pendingEntryPlayer).IsOnGround())) { bool num = pendingEntryPlayer.IsEquipActionQueued(pendingEntryHammer); _pendingEquipIssued = true; if (!num) { ((Humanoid)pendingEntryPlayer).UseItem(pendingEntryInventory, pendingEntryHammer, true); _pendingOwnEquipAction = pendingEntryPlayer.IsEquipActionQueued(pendingEntryHammer); } if (IsHammerEquippedForBuilding(pendingEntryPlayer, pendingEntryHammer)) { CompletePendingEditorEntry(pendingEntryPlayer); } else if (!pendingEntryPlayer.IsEquipActionQueued(pendingEntryHammer)) { FailPendingEditorEntry(pendingEntryPlayer); } } } else if (!pendingEntryPlayer.IsEquipActionQueued(pendingEntryHammer)) { FailPendingEditorEntry(pendingEntryPlayer); } } private void CompletePendingEditorEntry(Player player) { CancelPendingEditorEntry(removeOwnedEquipAction: false); if (Player.m_localPlayer == player && IsBuildingHammer(((Humanoid)player).RightItem) && ((Character)player).InPlaceMode() && !RejectBlockedInteriorEditorEntry(player)) { EnterEditor(); } } private void FailPendingEditorEntry(Player player) { CancelPendingEditorEntry(removeOwnedEquipAction: true); if (player != null) { ((Character)player).Message((MessageType)1, _language.HammerEquipFailed, 0, (Sprite)null); } } private void CancelPendingEditorEntry(bool removeOwnedEquipAction) { if (removeOwnedEquipAction && _pendingOwnEquipAction && (Object)(object)_pendingEntryPlayer != (Object)null && _pendingEntryHammer != null && _pendingEntryPlayer.IsEquipActionQueued(_pendingEntryHammer)) { ((Humanoid)_pendingEntryPlayer).RemoveEquipAction(_pendingEntryHammer); } _editorEntryPending = false; _pendingEquipIssued = false; _pendingOwnEquipAction = false; _pendingEntryPlayer = null; _pendingEntryInventory = null; _pendingEntryHammer = null; _pendingEntryDeadline = 0f; } private static ItemData FindBuildingHammer(Inventory inventory) { if (inventory == null) { return null; } List allItemsInGridOrder = inventory.GetAllItemsInGridOrder(); for (int i = 0; i < allItemsInGridOrder.Count; i++) { if (IsBuildingHammer(allItemsInGridOrder[i])) { return allItemsInGridOrder[i]; } } return null; } private static bool IsBuildingHammer(ItemData item) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 if (item != null && item.m_shared != null && (int)item.m_shared.m_itemType == 19 && (Object)(object)item.m_shared.m_buildPieces != (Object)null && item.m_shared.m_buildPieces.m_canRemovePieces) { if (item.m_shared.m_useDurability) { return item.m_durability > 0f; } return true; } return false; } private static bool IsEditorBlockedInCurrentInterior(Player player) { if ((Object)(object)player == (Object)null || !((Character)player).InInterior()) { return false; } bool num = (Object)(object)EnvMan.instance != (Object)null && EnvMan.instance.CheckInteriorBuildingOverride(); bool flag = (Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey((GlobalKeys)29); if (!num) { return !flag; } return false; } private static bool RejectBlockedInteriorEditorEntry(Player player) { if (!IsEditorBlockedInCurrentInterior(player)) { return false; } ((Character)player).Message((MessageType)2, "$msg_notindungeon", 0, (Sprite)null); return true; } private static bool IsHammerEquippedForBuilding(Player player, ItemData hammer) { if ((Object)(object)player != (Object)null && ((Humanoid)player).RightItem == hammer && hammer.m_equipped) { return ((Character)player).InPlaceMode(); } return false; } private void EnterEditor() { //IL_011d: 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_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: 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) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0138: 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) Player localPlayer = Player.m_localPlayer; Camera val = ResolveGameCamera(); if ((Object)(object)localPlayer == (Object)null || (Object)(object)GameCamera.instance == (Object)null || (Object)(object)val == (Object)null) { return; } RefreshEditorLanguage(); if (IsGameUiBlockingEditorInput()) { return; } if (!((Character)localPlayer).InPlaceMode()) { ((Character)localPlayer).Message((MessageType)1, _language.EnterBuildModeFirst, 0, (Sprite)null); } else if (!RejectBlockedInteriorEditorEntry(localPlayer)) { if (IsConflictingEditorActive()) { ((Character)localPlayer).Message((MessageType)1, _language.DisableConflictingEditor, 0, (Sprite)null); return; } DestroyCameraLight(); _active = true; _placementUpdateFailed = false; _surfaceSnapEnabled = Plugin.StartWithSnap.Value; _cameraRayFollowEnabled = false; _cameraRayFollowUpdatePending = false; _hasCameraRayFollowInput = false; RefreshToolbarLabels(); _rightMouseActive = false; _rightMouseMoved = false; _cameraCapturedLastFrame = false; _cameraSpeedScale = 1f; _nextDemolitionPickupTime = 0f; _uiInputBlockedThroughFrame = -1; _placementInputBlockedThroughFrame = -1; _editorCamera = val; _observedSelectedPiece = null; _observedSelectedPieceCompatible = false; ClearPlacementGhostTarget(); Transform transform = ((Component)GameCamera.instance).transform; _cameraPosition = transform.position; Quaternion rotation = transform.rotation; Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles; _cameraYaw = eulerAngles.y; _cameraPitch = NormalizePitch(eulerAngles.x); _cameraPositionDirty = true; ((Behaviour)_gizmo).enabled = true; _distancePlayer = localPlayer; _originalPlaceDistance = MaximumPlaceDistance.Invoke(localPlayer); _appliedPlaceDistance = Mathf.Max(_originalPlaceDistance, GetEditorRange() + 2f); MaximumPlaceDistance.Invoke(localPlayer) = _appliedPlaceDistance; ((Character)localPlayer).Message((MessageType)1, _language.EditorEnabled, 0, (Sprite)null); } } private void ExitEditor() { DestroyCameraLight(); if (_active) { AAABuildMenuCompatibility.OnEditorExit(); _placementGhostVisual.Restore(); ClearPlacementGhostTarget(); _reserveHotkeysThroughFrame = Time.frameCount; _active = false; _toolbarDragging = false; _rightMouseActive = false; _rightMouseMoved = false; _cameraCapturedLastFrame = false; _cameraRayFollowEnabled = false; _cameraRayFollowUpdatePending = false; _hasCameraRayFollowInput = false; _cameraPositionDirty = false; _insidePlacementUpdate = false; ((Behaviour)_gizmo).enabled = false; _editorCamera = null; if ((Object)(object)_distancePlayer != (Object)null && Mathf.Abs(MaximumPlaceDistance.Invoke(_distancePlayer) - _appliedPlaceDistance) < 0.01f) { MaximumPlaceDistance.Invoke(_distancePlayer) = _originalPlaceDistance; } _distancePlayer = null; if (Hud.IsPieceSelectionVisible() || IsGameUiBlockingEditorInput()) { Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; } else { Cursor.lockState = (CursorLockMode)1; Cursor.visible = false; } Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, _language.EditorDisabled, 0, (Sprite)null); } } } internal void ForceExit() { CancelPendingEditorEntry(removeOwnedEquipAction: true); ExitEditor(); _demolitionPickupTransactions.Clear(); _demolitionPickupDrops.Clear(); } internal void UpdateMouseCapture() { //IL_0024: 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_002d: Unknown result type (might be due to invalid IL or missing references) if (_active) { bool flag = IsCameraCaptured && !Hud.IsPieceSelectionVisible(); CursorLockMode val = (CursorLockMode)(flag ? 1 : 0); if (Cursor.lockState != val) { Cursor.lockState = val; } if (Cursor.visible == flag) { Cursor.visible = !flag; } } } internal void UpdateFreeCamera(float dt) { //IL_002e: 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_033f: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_0349: 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_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: 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_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) if (!_active) { return; } bool flag = IsCameraCaptured && !Hud.IsPieceSelectionVisible(); Quaternion val = Quaternion.Euler(_cameraPitch, _cameraYaw, 0f); if (flag) { if (_cameraCapturedLastFrame) { float num = PlayerController.m_mouseSens * GetSafeConfigValue(Plugin.MouseSensitivity.Value, 2f, 0.01f, 20f); float axis = Input.GetAxis("Mouse X"); float axis2 = Input.GetAxis("Mouse Y"); if (Mathf.Abs(axis) > 0.0001f || Mathf.Abs(axis2) > 0.0001f) { if (_rightMouseActive) { float rightMouseLookMagnitude = _rightMouseLookMagnitude; Vector2 val2 = new Vector2(axis, axis2); _rightMouseLookMagnitude = rightMouseLookMagnitude + ((Vector2)(ref val2)).magnitude; if (_rightMouseLookMagnitude >= 0.35f) { _rightMouseMoved = true; } } float num2 = (PlayerController.m_invertMouse ? (-1f) : 1f); _cameraYaw += axis * num; _cameraPitch = Mathf.Clamp(_cameraPitch - axis2 * num * num2, -89f, 89f); val = Quaternion.Euler(_cameraPitch, _cameraYaw, 0f); } } Vector3 val3 = Vector3.zero; if (ZInput.GetButton("Forward") || Input.GetKey((KeyCode)119)) { val3 += Vector3.forward; } if (ZInput.GetButton("Backward") || Input.GetKey((KeyCode)115)) { val3 += Vector3.back; } if (ZInput.GetButton("Right") || Input.GetKey((KeyCode)100)) { val3 += Vector3.right; } if (ZInput.GetButton("Left") || Input.GetKey((KeyCode)97)) { val3 += Vector3.left; } Vector3 val4 = val * val3; if (Input.GetKey((KeyCode)101) || Input.GetKey((KeyCode)32) || ZInput.GetButton("Jump")) { val4 += Vector3.up; } if (Input.GetKey((KeyCode)113) || Input.GetKey((KeyCode)306) || ZInput.GetButton("Crouch")) { val4 += Vector3.down; } if (((Vector3)(ref val4)).sqrMagnitude > 1f) { ((Vector3)(ref val4)).Normalize(); } float y = Input.mouseScrollDelta.y; if (Mathf.Abs(y) > 0.01f) { _cameraSpeedScale = Mathf.Clamp(_cameraSpeedScale * Mathf.Pow(1.2f, y), 0.2f, 10f); if (_rightMouseActive) { _rightMouseMoved = true; } } float num3 = GetSafeConfigValue(Plugin.CameraSpeed.Value, 12f, 0.1f, 500f) * _cameraSpeedScale; if (ZInput.GetButton("Run") || IsShiftHeld()) { num3 *= GetSafeConfigValue(Plugin.FastCameraMultiplier.Value, 3f, 1f, 20f); } if (((Vector3)(ref val4)).sqrMagnitude > 0f) { _cameraPosition += val4 * num3 * dt; _cameraPositionDirty = true; if (_rightMouseActive) { _rightMouseMoved = true; } } } _cameraCapturedLastFrame = flag; if (_cameraPositionDirty) { _cameraPosition = ConstrainCameraPosition(_cameraPosition); _cameraPositionDirty = false; } } internal void ApplyFinalCameraTransform(GameCamera gameCamera) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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) if (_active && !((Object)(object)gameCamera == (Object)null)) { Quaternion val = Quaternion.Euler(_cameraPitch, _cameraYaw, 0f); ((Component)gameCamera).transform.SetPositionAndRotation(_cameraPosition, val); ApplyCameraRayFollow(val); } } private void ApplyCameraRayFollow(Quaternion cameraRotation) { //IL_0031: 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) //IL_003c: 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_004c: Unknown result type (might be due to invalid IL or missing references) //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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) if (!_cameraRayFollowEnabled || _dragAxis != GizmoAxis.None || IsGameUiBlockingEditorInput() || Hud.IsPieceSelectionVisible() || (!HasGizmoTarget && !TryAcquireCameraRayFollowTarget())) { return; } Vector3 val = cameraRotation * Vector3.forward; int num; if (_hasCameraRayFollowInput) { Vector3 val2 = _cameraPosition - _lastCameraRayFollowOrigin; if (!(((Vector3)(ref val2)).sqrMagnitude > 1E-06f)) { num = ((Vector3.Dot(val, _lastCameraRayFollowDirection) < 0.9999995f) ? 1 : 0); goto IL_007b; } } num = 1; goto IL_007b; IL_007b: bool flag = (byte)num != 0; if (_cameraRayFollowUpdatePending || flag) { _lastCameraRayFollowOrigin = _cameraPosition; _lastCameraRayFollowDirection = val; _hasCameraRayFollowInput = true; _cameraRayFollowUpdatePending = false; Ray ray = default(Ray); ((Ray)(ref ray))..ctor(_cameraPosition, val); if (TryUpdateSurfaceSnap(ray, _desiredRotation) && (Object)(object)Player.m_localPlayer != (Object)null) { ValidateEditedGhost(Player.m_localPlayer, _targetPiece, flashGuardStone: false); } } } private bool TryAcquireCameraRayFollowTarget() { Player localPlayer = Player.m_localPlayer; GameObject placementGhost = GetPlacementGhost(localPlayer); Piece val = (((Object)(object)localPlayer != (Object)null) ? localPlayer.GetSelectedPiece() : null); if ((Object)(object)placementGhost == (Object)null || (Object)(object)val == (Object)null || !IsSelectedPieceGizmoCompatible(val)) { return false; } SetPlacementGhostTarget(placementGhost, val); return HasGizmoTarget; } private void FreezeCameraRayFollowInput() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_0033: 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) if (_cameraRayFollowEnabled) { Quaternion val = Quaternion.Euler(_cameraPitch, _cameraYaw, 0f); _lastCameraRayFollowOrigin = _cameraPosition; _lastCameraRayFollowDirection = val * Vector3.forward; _hasCameraRayFollowInput = true; _cameraRayFollowUpdatePending = false; } } internal DemolitionPickupTransaction CaptureDemolitionPickup(Player player) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: 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_021e: Unknown result type (might be due to invalid IL or missing references) if (!_active || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || (Object)(object)GameCamera.instance == (Object)null) { return null; } Transform transform = ((Component)GameCamera.instance).transform; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(transform.position, transform.forward, ref val, 50f, RemoveRayMask.Invoke(player)) || Vector3.Distance(((RaycastHit)(ref val)).point, ((Character)player).m_eye.position) >= MaximumPlaceDistance.Invoke(player)) { return null; } Piece val2 = (((Object)(object)((RaycastHit)(ref val)).collider != (Object)null) ? ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent() : null); if ((Object)(object)val2 == (Object)null && (Object)(object)((RaycastHit)(ref val)).collider != (Object)null && (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponent() != (Object)null) { val2 = TerrainModifier.FindClosestModifierPieceInRange(((RaycastHit)(ref val)).point, 2.5f); } if ((Object)(object)val2 == (Object)null) { return null; } if ((Object)(object)val2.m_destroyedLootPrefab != (Object)null || ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey(val2.FreeBuildKey()))) { return null; } DemolitionPickupTransaction demolitionPickupTransaction = new DemolitionPickupTransaction { Center = ((Component)val2).transform.position + Vector3.up * val2.m_returnResourceHeightOffset }; Feast component = ((Component)val2).GetComponent(); Requirement[] resources = val2.m_resources; foreach (Requirement val3 in resources) { if ((Object)(object)val3.m_resItem == (Object)null || !val3.m_recover) { continue; } int num = val3.m_amount; if ((Object)(object)component != (Object)null) { num = (int)Math.Floor((float)num * component.GetStackPercentige()); } if (num > 0) { if (!val2.IsPlacedByPlayer()) { num = Mathf.Max(1, num / 3); } string name = val3.m_resItem.m_itemData.m_shared.m_name; demolitionPickupTransaction.RemainingResources.TryGetValue(name, out var value); demolitionPickupTransaction.RemainingResources[name] = value + num; } } if (demolitionPickupTransaction.RemainingResources.Count == 0) { return null; } int num2 = FillDemolitionPickupBuffer(demolitionPickupTransaction.Center); for (int j = 0; j < num2; j++) { ItemDrop val4 = ResolveItemDrop(_demolitionPickupBuffer[j]); if ((Object)(object)val4 != (Object)null) { demolitionPickupTransaction.ExistingDropIds.Add(((Object)val4).GetInstanceID()); } } return demolitionPickupTransaction; } internal void CommitDemolitionPickup(DemolitionPickupTransaction transaction) { if (transaction != null) { transaction.ExpiresAt = Time.unscaledTime + 5f; if (_demolitionPickupTransactions.Count >= 32) { _demolitionPickupTransactions.RemoveAt(0); } _demolitionPickupTransactions.Add(transaction); _nextDemolitionPickupTime = 0f; UpdateDemolitionAutoPickupSafe(); } } private void UpdateDemolitionAutoPickupSafe() { if (_demolitionPickupTransactions.Count == 0 || Time.unscaledTime < _nextDemolitionPickupTime) { return; } try { UpdateDemolitionAutoPickup(); } catch (Exception arg) { _nextDemolitionPickupTime = Time.unscaledTime + 0.5f; if (Time.unscaledTime - _lastDemolitionPickupErrorTime >= 5f) { _lastDemolitionPickupErrorTime = Time.unscaledTime; Plugin.LogError($"Demolition resource pickup failed: {arg}"); } } } private void UpdateDemolitionAutoPickup() { //IL_00b5: Unknown result type (might be due to invalid IL or missing references) _nextDemolitionPickupTime = Time.unscaledTime + 0.1f; Player localPlayer = Player.m_localPlayer; for (int num = _demolitionPickupTransactions.Count - 1; num >= 0; num--) { if (Time.unscaledTime >= _demolitionPickupTransactions[num].ExpiresAt) { _demolitionPickupTransactions.RemoveAt(num); } } if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting() || !EnableAutoPickup.Invoke() || _demolitionPickupTransactions.Count == 0) { return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); _demolitionPickupDrops.Clear(); for (int num2 = _demolitionPickupTransactions.Count - 1; num2 >= 0; num2--) { DemolitionPickupTransaction demolitionPickupTransaction = _demolitionPickupTransactions[num2]; int num3 = FillDemolitionPickupBuffer(demolitionPickupTransaction.Center); for (int i = 0; i < num3; i++) { ItemDrop val = ResolveItemDrop(_demolitionPickupBuffer[i]); if ((Object)(object)val == (Object)null || demolitionPickupTransaction.ExistingDropIds.Contains(((Object)val).GetInstanceID()) || !val.m_autoPickup || val.IsPiece()) { continue; } ZNetView component = ((Component)val).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { continue; } val.Load(); string name = val.m_itemData.m_shared.m_name; int stack = val.m_itemData.m_stack; if (((Humanoid)localPlayer).HaveUniqueKey(name) || !demolitionPickupTransaction.RemainingResources.TryGetValue(name, out var value) || stack <= 0 || stack > value || !_demolitionPickupDrops.Add(val)) { continue; } if (!val.CanPickup(false)) { val.RequestOwn(); } else { if (val.InTar() || !inventory.CanAddItem(val.m_itemData, -1) || val.m_itemData.GetWeight(-1) + inventory.GetTotalWeight() > localPlayer.GetMaxCarryWeight()) { continue; } GameObject gameObject = ((Component)val).gameObject; if (((Humanoid)localPlayer).Pickup(gameObject, false, false)) { if ((Object)(object)gameObject != (Object)null) { gameObject.SetActive(false); } if (stack == value) { demolitionPickupTransaction.RemainingResources.Remove(name); } else { demolitionPickupTransaction.RemainingResources[name] = value - stack; } } } } if (demolitionPickupTransaction.RemainingResources.Count == 0) { _demolitionPickupTransactions.RemoveAt(num2); } } } private int FillDemolitionPickupBuffer(Vector3 center) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) int num; while (true) { num = Physics.OverlapSphereNonAlloc(center, 3f, _demolitionPickupBuffer, _itemLayerMask, (QueryTriggerInteraction)0); if (num < _demolitionPickupBuffer.Length || _demolitionPickupBuffer.Length >= 2048) { break; } Array.Resize(ref _demolitionPickupBuffer, _demolitionPickupBuffer.Length * 2); } return num; } private static ItemDrop ResolveItemDrop(Collider collider) { Rigidbody val = (((Object)(object)collider != (Object)null) ? collider.attachedRigidbody : null); if ((Object)(object)val == (Object)null) { return null; } ItemDrop component = ((Component)val).GetComponent(); if ((Object)(object)component == (Object)null) { FloatingTerrainDummy component2 = ((Component)val).GetComponent(); if ((Object)(object)component2 != (Object)null && (Object)(object)component2.m_parent != (Object)null) { component = ((Component)component2.m_parent).gameObject.GetComponent(); } } return component; } private static Vector3 ConstrainCameraPosition(Vector3 position) { //IL_0017: 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_001d: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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) //IL_0068: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return position; } Vector3 position2 = ((Component)localPlayer).transform.position; Vector3 val = position - position2; float editorRange = GetEditorRange(); if (((Vector3)(ref val)).sqrMagnitude > editorRange * editorRange) { position = position2 + ((Vector3)(ref val)).normalized * editorRange; } float num = default(float); if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(position, ref num) && position.y < num + 0.1f) { position.y = num + 0.1f; } return position; } private void ToggleBuildMenu() { if ((Object)(object)Hud.instance != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InPlaceMode()) { Hud.instance.TogglePieceSelection(); } } private Vector3 GetWorldAxis(GizmoAxis axis) { //IL_0016: 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_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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) Vector3 val = (Vector3)(axis switch { GizmoAxis.Y => Vector3.up, GizmoAxis.X => Vector3.right, _ => Vector3.forward, }); if (_space != CoordinateSpace.Local || !HasGizmoTarget) { return val; } return _targetGhost.transform.rotation * val; } private float GetProjectedTargetSize(Vector3 worldAxis) { //IL_0011: 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_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) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00b9: 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_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0114: 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_0138: 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_0141: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) if (!HasGizmoTarget || _targetGeometryRenderers.Length == 0 || !IsFinite(worldAxis) || ((Vector3)(ref worldAxis)).sqrMagnitude <= 1E-06f) { return 0f; } Vector3 normalized = ((Vector3)(ref worldAxis)).normalized; Transform transform = _targetGhost.transform; Vector3 position = transform.position; float num = float.PositiveInfinity; float num2 = float.NegativeInfinity; bool flag = false; for (int i = 0; i < _targetGeometryRenderers.Length; i++) { Renderer val = _targetGeometryRenderers[i]; if (!IsTargetGeometryRenderer(val, transform)) { continue; } Bounds localBounds = val.localBounds; Vector3 center = ((Bounds)(ref localBounds)).center; Vector3 extents = ((Bounds)(ref localBounds)).extents; if (!IsFinite(center) || !IsFinite(extents)) { continue; } ((Vector3)(ref extents))..ctor(Mathf.Abs(extents.x), Mathf.Abs(extents.y), Mathf.Abs(extents.z)); for (int j = 0; j < 8; j++) { Vector3 val2 = center + new Vector3(((j & 1) == 0) ? (0f - extents.x) : extents.x, ((j & 2) == 0) ? (0f - extents.y) : extents.y, ((j & 4) == 0) ? (0f - extents.z) : extents.z); Vector3 val3 = ((Component)val).transform.TransformPoint(val2); if (IsFinite(val3)) { float num3 = Vector3.Dot(val3 - position, normalized); if (!float.IsNaN(num3) && !float.IsInfinity(num3)) { num = Mathf.Min(num, num3); num2 = Mathf.Max(num2, num3); flag = true; } } } } if (!flag) { return 0f; } float num4 = num2 - num; if (!float.IsNaN(num4) && !float.IsInfinity(num4) && !(num4 <= 0.001f)) { return num4; } return 0f; } private float GetProjectedSnapPointSpan(Vector3 worldAxis) { //IL_0008: 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_002b: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_00c1: Unknown result type (might be due to invalid IL or missing references) if (!HasGizmoTarget || !IsFinite(worldAxis) || ((Vector3)(ref worldAxis)).sqrMagnitude <= 1E-06f) { return 0f; } Vector3 normalized = ((Vector3)(ref worldAxis)).normalized; Transform transform = _targetGhost.transform; _sourceSnapPoints.Clear(); _targetPiece.GetSnapPoints(_sourceSnapPoints); float num = float.PositiveInfinity; float num2 = float.NegativeInfinity; int num3 = 0; for (int i = 0; i < _sourceSnapPoints.Count; i++) { Transform val = _sourceSnapPoints[i]; if ((Object)(object)val == (Object)null) { continue; } Vector3 val2 = (((Object)(object)val.parent == (Object)(object)transform) ? transform.TransformVector(val.localPosition) : (val.position - transform.position)); if (IsFinite(val2)) { float num4 = Vector3.Dot(val2, normalized); if (!float.IsNaN(num4) && !float.IsInfinity(num4)) { num = Mathf.Min(num, num4); num2 = Mathf.Max(num2, num4); num3++; } } } if (num3 < 2) { return 0f; } float num5 = num2 - num; if (!float.IsNaN(num5) && !float.IsInfinity(num5) && !(num5 <= 0.001f)) { return num5; } return 0f; } private static bool IsTargetGeometryRenderer(Renderer renderer, Transform root) { if ((Object)(object)renderer == (Object)null || (!(renderer is MeshRenderer) && !(renderer is SkinnedMeshRenderer))) { return false; } Transform val = ((Component)renderer).transform; while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root) { if (!((Component)val).gameObject.activeSelf || ((Object)val).name == "_GhostOnly") { return false; } val = val.parent; } return (Object)(object)val == (Object)(object)root; } internal Vector3 GetDisplayAxis(GizmoAxis axis) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) return GetWorldAxis(axis); } private bool IsPointerOverToolbar() { //IL_0014: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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) if (!ShouldRenderToolbar) { return false; } if (_toolbarDragging) { return true; } Vector3 mousePosition = Input.mousePosition; return ((Rect)(ref _toolbarRect)).Contains(new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y)); } private bool IsPointerOverGizmo() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (!ShouldRenderEditorOverlay) { return false; } Camera editorCamera = EditorCamera; if ((Object)(object)editorCamera != (Object)null && HasGizmoTarget) { return _gizmo.HitTest(editorCamera, Input.mousePosition) != GizmoAxis.None; } return false; } internal bool IsGameUiBlockingEditorInput() { if (!InventoryGui.IsVisible() && !Menu.IsVisible() && !Console.IsVisible() && !TextInput.IsVisible() && !StoreGui.IsVisible() && !Minimap.IsOpen() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && (!((Object)(object)TextViewer.instance != (Object)null) || !TextViewer.instance.IsVisible()) && !PlayerCustomizaton.IsBarberGuiVisible() && !UnifiedPopup.IsVisible() && !Hud.InRadial()) { return Game.IsPaused(); } return true; } internal bool ShouldConsumeEditorShortcutForExternalHotkeys(Player player) { if (!_active || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer) { return false; } return EditorInputFirewall.IsAnyReservedInputHeld(); } internal void ReserveEscapeInput() { _suppressMenuFrame = Time.frameCount; } internal static void ReserveBuildMenuEscapeInput() { _buildMenuConsumedEscapeFrame = Time.frameCount; } private static float GetEditorRange() { return GetSafeConfigValue(Plugin.EditorRange.Value, 100f, 20f, 200f); } private static float GetSafeConfigValue(float value, float fallback, float minimum, float maximum) { if (!float.IsNaN(value) && !float.IsInfinity(value)) { return Mathf.Clamp(value, minimum, maximum); } return fallback; } private bool IsCurrentGhostOutsideEditorRange(Player player) { //IL_0026: 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_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) GameObject placementGhost = GetPlacementGhost(player); if ((Object)(object)placementGhost == (Object)null || !placementGhost.activeInHierarchy) { return false; } float editorRange = GetEditorRange(); Vector3 val = placementGhost.transform.position - ((Component)player).transform.position; return ((Vector3)(ref val)).sqrMagnitude > editorRange * editorRange; } private static PlacementRotationSnapshot CapturePlacementRotation(Player player) { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) PlacementRotationSnapshot result = new PlacementRotationSnapshot { PlaceRotation = PlaceRotation.Invoke(player), ScrollCurrentAmount = ScrollCurrentAmount.Invoke(player), RotatePieceTimer = RotatePieceTimer.Invoke(player) }; EnsureExternalModeResolvers(); if (_perfectPlacementPlayersData == null || _perfectPlacementPlaceRotation == null) { return result; } try { result.PerfectPlacementAvailable = true; object obj = _perfectPlacementPlayersData[player]; if (obj != null) { result.PerfectPlacementHadEntry = true; result.PerfectPlacementRotation = _perfectPlacementPlaceRotation.Invoke(obj); } } catch { _perfectPlacementPlayersData = null; _perfectPlacementPlaceRotation = null; result.PerfectPlacementAvailable = false; } return result; } private static void RestorePlacementRotation(Player player, PlacementRotationSnapshot snapshot) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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_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) PlaceRotation.Invoke(player) = snapshot.PlaceRotation; ScrollCurrentAmount.Invoke(player) = snapshot.ScrollCurrentAmount; RotatePieceTimer.Invoke(player) = snapshot.RotatePieceTimer; if (!snapshot.PerfectPlacementAvailable || _perfectPlacementPlayersData == null || _perfectPlacementPlaceRotation == null) { return; } try { object obj = _perfectPlacementPlayersData[player]; if (obj != null) { Vector3 val = (snapshot.PerfectPlacementHadEntry ? snapshot.PerfectPlacementRotation : (Vector3.up * ((float)snapshot.PlaceRotation * 22.5f))); _perfectPlacementPlaceRotation.Invoke(obj) = val; } } catch { _perfectPlacementPlayersData = null; _perfectPlacementPlaceRotation = null; } } private static void SynchronizePerfectPlacementRotation(Player player, Quaternion sampledRotation) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) EnsureExternalModeResolvers(); if (_perfectPlacementPlayersData == null || _perfectPlacementPlaceRotation == null || !IsFinite(sampledRotation)) { return; } try { object obj = _perfectPlacementPlayersData[player]; if (obj != null) { _perfectPlacementPlaceRotation.Invoke(obj) = ((Quaternion)(ref sampledRotation)).eulerAngles; } } catch { _perfectPlacementPlayersData = null; _perfectPlacementPlaceRotation = null; } } private static float NormalizePitch(float angle) { if (!(angle > 180f)) { return angle; } return angle - 360f; } private static bool IsFinite(Vector3 value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0041: Unknown result type (might be due to invalid IL or missing references) if (!float.IsNaN(value.x) && !float.IsInfinity(value.x) && !float.IsNaN(value.y) && !float.IsInfinity(value.y) && !float.IsNaN(value.z)) { return !float.IsInfinity(value.z); } return false; } private static bool IsFinite(Quaternion value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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) if (float.IsNaN(value.x) || float.IsInfinity(value.x) || float.IsNaN(value.y) || float.IsInfinity(value.y) || float.IsNaN(value.z) || float.IsInfinity(value.z) || float.IsNaN(value.w) || float.IsInfinity(value.w)) { return false; } float num = value.x * value.x + value.y * value.y + value.z * value.z + value.w * value.w; if (num > 0.5f) { return num < 1.5f; } return false; } private static Action CreateUpdatePlacementInvoker() { try { return (UpdatePlacementMethod == null) ? null : AccessTools.MethodDelegate>(UpdatePlacementMethod, (object)null, true); } catch { return null; } } private static bool IsConflictingEditorActive() { EnsureExternalModeResolvers(); if (!InvokeModeResolver(_perfectPlacementBuildingMode) && !InvokeModeResolver(_perfectPlacementEditingMode) && !InvokeModeResolver(_buildCameraMode)) { return IsMoveBuildPiecesConflictActive(); } return true; } private static void EnsureExternalModeResolvers() { if (!_externalModeResolversInitialized) { _externalModeResolversInitialized = true; _perfectPlacementBuildingMode = CreateStaticBoolResolver("PerfectPlacement.Patches.ABM", "IsInAbmMode"); _perfectPlacementEditingMode = CreateStaticBoolResolver("PerfectPlacement.Patches.AEM", "IsInAemMode"); _buildCameraMode = CreateStaticBoolResolver("Valheim_Build_Camera.Utils", "InBuildMode"); ResolveMoveBuildPiecesState(); ResolvePerfectPlacementRotationState(); } } private static void ResolveMoveBuildPiecesState() { Type type = OptionalModTypeResolver.FindLoadedType("Obelisk.MoveBuildPieces.MoveBuildPiecesPlugin"); if (type == null) { return; } _moveBuildPiecesPresent = true; try { Type type2 = OptionalModTypeResolver.FindLoadedType("Obelisk.MoveBuildPieces.MoveController"); _moveBuildPiecesEnabled = CreateStaticGetter(type, "IsEnabled"); _moveBuildPiecesBuildModeHotkey = CreateStaticGetter(type, "BuildModeMoveHotkey"); _moveBuildPiecesWorldModeHotkey = CreateStaticGetter(type, "WorldModeMoveHotkey"); _moveBuildPiecesMixedModeHotkey = CreateStaticGetter(type, "MixedModeMoveHotkey"); MethodInfo methodInfo = ((type2 == null) ? null : AccessTools.Method(type2, "ShouldBlockBuildAction", new Type[1] { typeof(Player) }, (Type[])null)); _moveBuildPiecesBlocksBuildAction = ((methodInfo == null) ? null : AccessTools.MethodDelegate>(methodInfo, (object)null, true)); _moveBuildPiecesPendingRequest = ((type2 == null) ? null : AccessTools.Field(type2, "_pendingRequest")); _moveBuildPiecesResolved = _moveBuildPiecesEnabled != null && _moveBuildPiecesBlocksBuildAction != null && _moveBuildPiecesBuildModeHotkey != null && _moveBuildPiecesWorldModeHotkey != null && _moveBuildPiecesMixedModeHotkey != null && _moveBuildPiecesPendingRequest != null; } catch { _moveBuildPiecesResolved = false; } } private static Func CreateStaticGetter(Type type, string propertyName) { MethodInfo methodInfo = ((type == null) ? null : AccessTools.PropertyGetter(type, propertyName)); if (!(methodInfo == null)) { return AccessTools.MethodDelegate>(methodInfo, (object)null, true); } return null; } private static bool IsMoveBuildPiecesConflictActive() { if (!_moveBuildPiecesPresent) { return false; } if (!_moveBuildPiecesResolved) { return true; } try { Player localPlayer = Player.m_localPlayer; return (Object)(object)localPlayer == (Object)null || _moveBuildPiecesPendingRequest.GetValue(null) != null || _moveBuildPiecesBlocksBuildAction(localPlayer); } catch { return true; } } internal unsafe static bool IsMoveBuildPiecesActivationShortcut(KeyboardShortcut shortcut) { //IL_0029: 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_0065: Unknown result type (might be due to invalid IL or missing references) EnsureExternalModeResolvers(); if (!_moveBuildPiecesPresent || !_moveBuildPiecesResolved) { return false; } try { int result; if (_moveBuildPiecesEnabled()) { object obj = _moveBuildPiecesBuildModeHotkey(); if (!((object)(*(KeyboardShortcut*)(&shortcut))/*cast due to .constrained prefix*/).Equals(obj)) { object obj2 = _moveBuildPiecesWorldModeHotkey(); if (!((object)(*(KeyboardShortcut*)(&shortcut))/*cast due to .constrained prefix*/).Equals(obj2)) { object obj3 = _moveBuildPiecesMixedModeHotkey(); result = (((object)(*(KeyboardShortcut*)(&shortcut))/*cast due to .constrained prefix*/).Equals(obj3) ? 1 : 0); goto IL_0080; } } result = 1; } else { result = 0; } goto IL_0080; IL_0080: return (byte)result != 0; } catch { return false; } } private static void ResolvePerfectPlacementRotationState() { try { Type type = OptionalModTypeResolver.FindLoadedType("PerfectPlacement.PerfectPlacementPlugin"); Type type2 = ((type == null) ? null : AccessTools.Inner(type, "PlayerData")); _perfectPlacementPlayersData = ((type == null) ? null : AccessTools.Field(type, "PlayersData"))?.GetValue(null) as IDictionary; _perfectPlacementPlaceRotation = ((type2 == null) ? null : AccessTools.FieldRefAccess(type2, "PlaceRotation")); } catch { _perfectPlacementPlayersData = null; _perfectPlacementPlaceRotation = null; } } private static Func CreateStaticBoolResolver(string typeName, string methodName) { try { Type type = OptionalModTypeResolver.FindLoadedType(typeName); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, methodName, Type.EmptyTypes, (Type[])null)); return (methodInfo == null) ? null : AccessTools.MethodDelegate>(methodInfo, (object)null, true); } catch { return null; } } private static bool InvokeModeResolver(Func resolver) { if (resolver == null) { return false; } try { return resolver(); } catch { return false; } } private static Camera ResolveGameCamera() { Camera val = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).GetComponent() : null); if (!((Object)(object)val != (Object)null)) { return Camera.main; } return val; } internal static GameObject GetPlacementGhost(Player player) { if (!((Object)(object)player == (Object)null)) { return PlacementGhost.Invoke(player); } return null; } private void OnGUI() { //IL_0042: 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_0066: Unknown result type (might be due to invalid IL or missing references) if (ShouldRenderToolbar) { GUI.depth = -100; ((Rect)(ref _toolbarRect)).width = Mathf.Min(1290f, Mathf.Max(1000f, (float)Screen.width - 20f)); _toolbarRect = GUILayout.Window(20260714, _toolbarRect, _toolbarWindowFunction, string.Empty, GUI.skin.box, Array.Empty()); ((Rect)(ref _toolbarRect)).x = Mathf.Clamp(((Rect)(ref _toolbarRect)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref _toolbarRect)).width)); ((Rect)(ref _toolbarRect)).y = Mathf.Clamp(((Rect)(ref _toolbarRect)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref _toolbarRect)).height)); } } private void DrawToolbarWindow(int windowId) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 //IL_0025: 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_0039: 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) //IL_0207: Unknown result type (might be due to invalid IL or missing references) Event current = Event.current; bool flag = !IsCameraCaptured && Cursor.visible; if (!flag) { _toolbarDragging = false; } if (flag && (int)current.type == 0 && current.button == 0) { Rect toolbarDragRect = ToolbarDragRect; if (((Rect)(ref toolbarDragRect)).Contains(current.mousePosition)) { _toolbarDragging = true; } } if ((int)current.rawType == 1 && current.button == 0) { _toolbarDragging = false; } GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label(_language.Header, (GUILayoutOption[])(object)new GUILayoutOption[1] { HeaderWidth }); if (GUILayout.Toggle(_mode == EditMode.Translate, _language.Translate, GUI.skin.button, (GUILayoutOption[])(object)new GUILayoutOption[1] { TranslateWidth })) { SetEditMode(EditMode.Translate); } if (GUILayout.Toggle(_mode == EditMode.Rotate, _language.Rotate, GUI.skin.button, (GUILayoutOption[])(object)new GUILayoutOption[1] { RotateWidth })) { SetEditMode(EditMode.Rotate); } if (GUILayout.Button(_spaceButtonLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { SpaceWidth })) { ToggleCoordinateSpace(); } if (GUILayout.Button(_surfaceSnapButtonLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { SnapWidth })) { ToggleSurfaceSnapping(); } if (GUILayout.Button(_cameraLightButtonLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { CameraLightWidth })) { ToggleCameraLight(); } GUI.enabled = HasGizmoTarget; if (GUILayout.Button(_language.ResetToRay, (GUILayoutOption[])(object)new GUILayoutOption[1] { ResetWidth })) { ReleasePlacementGhost(); } GUI.enabled = true; if (GUILayout.Button(_exitButtonLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { ExitWidth })) { ExitEditor(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(Array.Empty()); if (GUILayout.Button(_cameraRayFollowButtonLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { CameraRayFollowWidth })) { ToggleCameraRayFollow(); } GUILayout.Label(_targetStatusText, Array.Empty()); GUILayout.EndHorizontal(); if (flag) { GUI.DragWindow(ToolbarDragRect); } } private void OnToolbarHotkeySettingChanged(object sender, EventArgs eventArgs) { _toolbarLabelsDirty = true; } private void OnCameraLightSettingChanged(object sender, EventArgs eventArgs) { _cameraLightSettingsDirty = true; } private void OnGhostPreviewSettingChanged(object sender, EventArgs eventArgs) { _ghostPreviewSettingsDirty = true; } private void ApplyGhostPreviewSetting() { _blueGhostPreviewEnabled = Plugin.BlueGhostPreview.Value; if (!_active || !_blueGhostPreviewEnabled) { _placementGhostVisual.Restore(); return; } Player localPlayer = Player.m_localPlayer; _placementGhostVisual.Sync(((Object)(object)localPlayer != (Object)null) ? GetPlacementGhost(localPlayer) : null); } private void OnGameLanguageChanged() { RefreshEditorLanguage(); } private void RefreshEditorLanguage() { EditorLanguage editorLanguage = EditorLanguage.FromGameLanguage(); bool num = !_languageInitialized || _language != editorLanguage; _language = editorLanguage; _languageInitialized = true; if (num) { RefreshToolbarLabels(); } RefreshTargetStatusText(); } private void RefreshToolbarLabels() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_00fd: 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) _spaceButtonLabel = ((_space == CoordinateSpace.World) ? _language.World : _language.Local) + " (" + FormatShortcut(Plugin.ToggleCoordinateSpaceKey.Value) + ")"; _surfaceSnapButtonLabel = (_surfaceSnapEnabled ? _language.SurfaceOn : _language.SurfaceOff) + " (" + FormatShortcut(Plugin.ToggleSurfaceSnapKey.Value) + ")"; _cameraLightButtonLabel = (((Object)(object)_cameraLight != (Object)null) ? _language.LightOn : _language.LightOff) + " (" + FormatShortcut(Plugin.ToggleCameraLightKey.Value) + ")"; _cameraRayFollowButtonLabel = (_cameraRayFollowEnabled ? _language.FollowOn : _language.FollowOff) + " (" + FormatShortcut(Plugin.ToggleCameraRayFollowKey.Value) + ")"; _exitButtonLabel = _language.Exit + " (" + FormatShortcut(Plugin.ToggleEditorKey.Value) + ")"; } private unsafe static string FormatShortcut(KeyboardShortcut shortcut) { string text = ((object)(*(KeyboardShortcut*)(&shortcut))/*cast due to .constrained prefix*/).ToString(); if (!string.IsNullOrEmpty(text)) { return text; } return "—"; } static EditorController() { //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) KeyCode[] array = new KeyCode[8]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); HotbarKeys = (KeyCode[])(object)array; CameraLightColor = new Color(1f, 0.92f, 0.78f, 1f); HeaderWidth = GUILayout.Width(220f); TranslateWidth = GUILayout.Width(120f); RotateWidth = GUILayout.Width(105f); SpaceWidth = GUILayout.Width(165f); SnapWidth = GUILayout.Width(185f); CameraLightWidth = GUILayout.Width(165f); CameraRayFollowWidth = GUILayout.Width(205f); ResetWidth = GUILayout.Width(105f); ExitWidth = GUILayout.Width(125f); ToolbarDragRect = new Rect(0f, 0f, 220f, 28f); _suppressMenuFrame = -1; _buildMenuConsumedEscapeFrame = -1; } } internal static class EditorInputFirewall { private sealed class ReservedKeySnapshot { internal readonly HashSet Lookup; internal readonly KeyCode[] PollingOrder; internal ReservedKeySnapshot(HashSet lookup, KeyCode[] pollingOrder) { Lookup = lookup; PollingOrder = pollingOrder; } } [ThreadStatic] private static int _editorShortcutReadDepth; private static readonly KeyCode[] FixedReservedKeys; private static ReservedKeySnapshot _reservedKeys; private static bool _initialized; internal static void Initialize() { if (!_initialized) { Subscribe(Plugin.ToggleEditorKey); Subscribe(Plugin.ToggleSurfaceSnapKey); Subscribe(Plugin.ToggleCoordinateSpaceKey); Subscribe(Plugin.ToggleCameraLightKey); Subscribe(Plugin.ToggleCameraRayFollowKey); Subscribe(Plugin.BoundsStepModifier); _reservedKeys = BuildReservedKeySnapshot(); _initialized = true; } } internal static void Shutdown() { if (_initialized) { Unsubscribe(Plugin.ToggleEditorKey); Unsubscribe(Plugin.ToggleSurfaceSnapKey); Unsubscribe(Plugin.ToggleCoordinateSpaceKey); Unsubscribe(Plugin.ToggleCameraLightKey); Unsubscribe(Plugin.ToggleCameraRayFollowKey); Unsubscribe(Plugin.BoundsStepModifier); _reservedKeys = BuildFixedReservedKeySnapshot(); _initialized = false; } } internal static bool IsEditorShortcutDown(KeyboardShortcut shortcut) { _editorShortcutReadDepth++; try { return ((KeyboardShortcut)(ref shortcut)).IsDown(); } finally { _editorShortcutReadDepth--; } } internal static bool ShouldBlockExternalShortcut(KeyboardShortcut shortcut) { //IL_0011: 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_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_0053: Unknown result type (might be due to invalid IL or missing references) if (_editorShortcutReadDepth > 0 || !IsReservationActive()) { return false; } if (EditorController.IsMoveBuildPiecesActivationShortcut(shortcut)) { return true; } ReservedKeySnapshot reservedKeys = _reservedKeys; if (reservedKeys.Lookup.Contains(((KeyboardShortcut)(ref shortcut)).MainKey)) { return true; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers) { if (reservedKeys.Lookup.Contains(modifier)) { return true; } } return false; } internal static bool IsAnyReservedInputHeld() { if (!IsReservationActive()) { return false; } KeyCode[] pollingOrder = _reservedKeys.PollingOrder; for (int i = 0; i < pollingOrder.Length; i++) { if (Input.GetKey(pollingOrder[i])) { return true; } } return false; } private static bool IsReservationActive() { EditorController controller = Plugin.Controller; if ((Object)(object)controller != (Object)null) { return controller.ShouldReserveEditorHotkeys; } return false; } private static void Subscribe(ConfigEntry configEntry) { if (configEntry != null) { configEntry.SettingChanged += OnShortcutSettingChanged; } } private static void Unsubscribe(ConfigEntry configEntry) { if (configEntry != null) { configEntry.SettingChanged -= OnShortcutSettingChanged; } } private static void Subscribe(ConfigEntry configEntry) { if (configEntry != null) { configEntry.SettingChanged += OnShortcutSettingChanged; } } private static void Unsubscribe(ConfigEntry configEntry) { if (configEntry != null) { configEntry.SettingChanged -= OnShortcutSettingChanged; } } private static void OnShortcutSettingChanged(object sender, EventArgs eventArgs) { _reservedKeys = BuildReservedKeySnapshot(); } private static ReservedKeySnapshot BuildReservedKeySnapshot() { List list = new List(FixedReservedKeys.Length + 12); HashSet lookup = new HashSet(); for (int i = 0; i < FixedReservedKeys.Length; i++) { AddReservedKey(FixedReservedKeys[i], lookup, list); } AddShortcut(Plugin.ToggleEditorKey, lookup, list); AddShortcut(Plugin.ToggleSurfaceSnapKey, lookup, list); AddShortcut(Plugin.ToggleCoordinateSpaceKey, lookup, list); AddShortcut(Plugin.ToggleCameraLightKey, lookup, list); AddShortcut(Plugin.ToggleCameraRayFollowKey, lookup, list); AddConfiguredKey(Plugin.BoundsStepModifier, lookup, list); return new ReservedKeySnapshot(lookup, list.ToArray()); } private static ReservedKeySnapshot BuildFixedReservedKeySnapshot() { List list = new List(FixedReservedKeys.Length); HashSet lookup = new HashSet(); for (int i = 0; i < FixedReservedKeys.Length; i++) { AddReservedKey(FixedReservedKeys[i], lookup, list); } return new ReservedKeySnapshot(lookup, list.ToArray()); } private static void AddShortcut(ConfigEntry configEntry, HashSet lookup, List pollingOrder) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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) if (configEntry == null) { return; } KeyboardShortcut value = configEntry.Value; AddReservedKey(((KeyboardShortcut)(ref value)).MainKey, lookup, pollingOrder); foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers) { AddReservedKey(modifier, lookup, pollingOrder); } } private static void AddConfiguredKey(ConfigEntry configEntry, HashSet lookup, List pollingOrder) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) if (configEntry != null) { AddReservedKey(configEntry.Value, lookup, pollingOrder); } } private static void AddReservedKey(KeyCode key, HashSet lookup, List pollingOrder) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) if ((int)key != 0 && lookup.Add(key)) { pollingOrder.Add(key); } } static EditorInputFirewall() { KeyCode[] array = new KeyCode[24]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); FixedReservedKeys = (KeyCode[])(object)array; _reservedKeys = BuildReservedKeySnapshot(); } } internal sealed class EditorLanguage { internal static readonly EditorLanguage English = new EditorLanguage { Header = "EXTENDED BUILDING", Translate = "W Move", Rotate = "E/R Rotate", ResetToRay = "Reset to ray", World = "World", Local = "Local", SurfaceOn = "Surface: ON", SurfaceOff = "Surface: OFF", LightOn = "Light: ON", LightOff = "Light: OFF", FollowOn = "Camera ray: ON", FollowOff = "Camera ray: OFF", Exit = "Exit", NoGhost = "Piece: select an object in the build menu", SpecialPiece = "Special piece: vanilla Valheim placement", PiecePrefix = "Piece: ", ToolbarHelp = " | LMB: build | MMB: dismantle | Shift+MMB: sample | RMB: click — menu, hold + WASD — camera", DisableConflictingEditor = "Disable the active PerfectPlacement, Build Camera or MoveBuildPieces mode first", PlacementError = "Building editor error; see the log for details", EnterBuildModeFirst = "Equip a building tool and enter building mode first", NoBuildingHammer = "No building hammer found in the inventory", HammerEquipFailed = "Unable to equip the building hammer", EditorEnabled = "Extended building enabled", EditorDisabled = "Extended building disabled" }; internal static readonly EditorLanguage Russian = new EditorLanguage { Header = "РАСШИРЕННОЕ СТРОИТЕЛЬСТВО", Translate = "W Перемещение", Rotate = "E/R Поворот", ResetToRay = "Сброс к лучу", World = "Мировые", Local = "Локальные", SurfaceOn = "Поверхность: ВКЛ", SurfaceOff = "Поверхность: ВЫКЛ", LightOn = "Свет: ВКЛ", LightOff = "Свет: ВЫКЛ", FollowOn = "Луч камеры: ВКЛ", FollowOff = "Луч камеры: ВЫКЛ", Exit = "Выход", NoGhost = "Деталь: выберите объект в меню строительства", SpecialPiece = "Специальная деталь: штатное размещение Valheim", PiecePrefix = "Деталь: ", ToolbarHelp = " | ЛКМ: построить | СКМ: снести | Shift+СКМ: проба | ПКМ: клик — меню, удержание + WASD — камера", DisableConflictingEditor = "Сначала выключите активный режим PerfectPlacement, Build Camera или MoveBuildPieces", PlacementError = "Ошибка режима строительства; подробности в журнале", EnterBuildModeFirst = "Сначала возьмите строительный инструмент и войдите в режим строительства", NoBuildingHammer = "В инвентаре не найден строительный молоток", HammerEquipFailed = "Не удалось взять строительный молоток", EditorEnabled = "Расширенное строительство включено", EditorDisabled = "Расширенное строительство выключено" }; internal string Header { get; private set; } internal string Translate { get; private set; } internal string Rotate { get; private set; } internal string ResetToRay { get; private set; } internal string World { get; private set; } internal string Local { get; private set; } internal string SurfaceOn { get; private set; } internal string SurfaceOff { get; private set; } internal string LightOn { get; private set; } internal string LightOff { get; private set; } internal string FollowOn { get; private set; } internal string FollowOff { get; private set; } internal string Exit { get; private set; } internal string NoGhost { get; private set; } internal string SpecialPiece { get; private set; } internal string PiecePrefix { get; private set; } internal string ToolbarHelp { get; private set; } internal string DisableConflictingEditor { get; private set; } internal string PlacementError { get; private set; } internal string EnterBuildModeFirst { get; private set; } internal string NoBuildingHammer { get; private set; } internal string HammerEquipFailed { get; private set; } internal string EditorEnabled { get; private set; } internal string EditorDisabled { get; private set; } private EditorLanguage() { } internal static EditorLanguage FromGameLanguage() { if (!string.Equals(Localization.instance.GetSelectedLanguage(), "Russian", StringComparison.OrdinalIgnoreCase)) { return English; } return Russian; } } internal enum GizmoAxis { None, Center, X, Y, Z } internal sealed class GizmoRenderer : MonoBehaviour { private static readonly Color XColor = new Color(0.95f, 0.15f, 0.12f, 1f); private static readonly Color YColor = new Color(0.2f, 0.85f, 0.2f, 1f); private static readonly Color ZColor = new Color(0.18f, 0.45f, 1f, 1f); private static readonly Color CenterColor = new Color(0.82f, 0.62f, 0.05f, 1f); private static readonly Color HighlightColor = new Color(1f, 0.78f, 0.08f, 1f); private const float DesiredPixelSize = 105f; private const float HitRadiusPixels = 13f; private const float DefaultCenterHandleSizePixels = 35f; private const float MinCenterHandleSizePixels = 10f; private const float MaxCenterHandleSizePixels = 100f; private const float TranslationAxisLengthMultiplier = 1.15f; private const float RingFrontFallbackRelativeSqr = 1E-06f; private const float AxisEpsilonSqr = 1E-08f; private const int RingSegments = 72; private static readonly GizmoAxis[] Axes = new GizmoAxis[3] { GizmoAxis.X, GizmoAxis.Y, GizmoAxis.Z }; private static readonly Vector2[] RingPoints = CreateRingPoints(); private Material _lineMaterial; private float _halfLineWidth; private Vector3 _renderCameraForward; private Vector3 _renderCameraUp; private Vector3 _renderCameraRight; private Vector3 _renderViewToCamera; private int _hitTestFrame = -1; private Camera _hitTestCamera; private Transform _hitTestTarget; private Vector3 _hitTestMouse; private Vector3 _hitTestPivot; private Quaternion _hitTestTargetRotation; private EditMode _hitTestMode; private CoordinateSpace _hitTestSpace; private GizmoAxis _hitTestResult; internal EditorController Controller { private get; set; } internal GizmoAxis HoveredAxis { get; set; } internal GizmoAxis ActiveAxis { get; set; } private void Awake() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown Shader val = Shader.Find("Hidden/Internal-Colored"); if ((Object)(object)val == (Object)null) { Plugin.LogError("Hidden/Internal-Colored shader was not found; gizmo disabled"); ((Behaviour)this).enabled = false; return; } _lineMaterial = new Material(val) { hideFlags = (HideFlags)61 }; _lineMaterial.SetInt("_SrcBlend", 5); _lineMaterial.SetInt("_DstBlend", 10); _lineMaterial.SetInt("_Cull", 0); _lineMaterial.SetInt("_ZWrite", 0); _lineMaterial.SetInt("_ZTest", 8); ((Behaviour)this).enabled = false; } private void OnDestroy() { if ((Object)(object)_lineMaterial != (Object)null) { Object.Destroy((Object)(object)_lineMaterial); } } private void OnRenderObject() { //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_007d: 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) //IL_008d: 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_00ab: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0106: 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_0116: 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_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0146: 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_018d: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_lineMaterial == (Object)null || (Object)(object)Controller == (Object)null) { return; } Camera current = Camera.current; Camera editorCamera = Controller.EditorCamera; if ((Object)(object)current == (Object)null || (Object)(object)current != (Object)(object)editorCamera || !Controller.ShouldRenderEditorOverlay || !Controller.HasGizmoTarget) { return; } Transform transform = ((Component)current).transform; _renderCameraForward = transform.forward; _renderCameraUp = transform.up; _renderCameraRight = transform.right; Vector3 gizmoPivot = Controller.GizmoPivot; _renderViewToCamera = (current.orthographic ? (-_renderCameraForward) : (transform.position - gizmoPivot)); float num = CalculateWorldSize(current, gizmoPivot); _halfLineWidth = num / 105f * 0.9f; _lineMaterial.SetPass(0); GL.PushMatrix(); GL.Begin(1); if (Controller.Mode == EditMode.Translate) { DrawCenterHandle(gizmoPivot, num); DrawTranslationAxis(gizmoPivot, Controller.GetDisplayAxis(GizmoAxis.X), num, AxisColor(GizmoAxis.X), GizmoAxis.X); DrawTranslationAxis(gizmoPivot, Controller.GetDisplayAxis(GizmoAxis.Y), num, AxisColor(GizmoAxis.Y), GizmoAxis.Y); DrawTranslationAxis(gizmoPivot, Controller.GetDisplayAxis(GizmoAxis.Z), num, AxisColor(GizmoAxis.Z), GizmoAxis.Z); } else { GizmoAxis gizmoAxis = ((ActiveAxis != GizmoAxis.None) ? ActiveAxis : HoveredAxis); GizmoAxis[] axes = Axes; foreach (GizmoAxis gizmoAxis2 in axes) { if (gizmoAxis2 != gizmoAxis) { DrawRotationAxis(gizmoPivot, num, gizmoAxis2); } } if (gizmoAxis == GizmoAxis.X || gizmoAxis == GizmoAxis.Y || gizmoAxis == GizmoAxis.Z) { DrawRotationAxis(gizmoPivot, num, gizmoAxis); } } GL.End(); GL.PopMatrix(); } internal GizmoAxis HitTest(Camera camera, Vector3 mousePosition) { //IL_003d: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0137: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: 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_0148: 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_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: 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_018e: 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) if ((Object)(object)_lineMaterial == (Object)null || (Object)(object)Controller == (Object)null || !Controller.HasGizmoTarget) { return GizmoAxis.None; } Transform targetTransform = Controller.TargetTransform; Vector3 gizmoPivot = Controller.GizmoPivot; if (_hitTestFrame == Time.frameCount && (Object)(object)_hitTestCamera == (Object)(object)camera && (Object)(object)_hitTestTarget == (Object)(object)targetTransform && _hitTestMouse == mousePosition && _hitTestPivot == gizmoPivot && _hitTestTargetRotation == targetTransform.rotation && _hitTestMode == Controller.Mode && _hitTestSpace == Controller.Space) { return _hitTestResult; } float num = CalculateWorldSize(camera, gizmoPivot); GizmoAxis gizmoAxis = GizmoAxis.None; float num2 = 13f; Vector3 val = camera.WorldToScreenPoint(gizmoPivot); float centerHalfSizePixels = GetCenterHalfSizePixels(); Transform transform = ((Component)camera).transform; Vector3 viewToCamera = (camera.orthographic ? (-transform.forward) : (transform.position - gizmoPivot)); if (Controller.Mode == EditMode.Translate && val.z > 0f && Mathf.Abs(mousePosition.x - val.x) <= centerHalfSizePixels && Mathf.Abs(mousePosition.y - val.y) <= centerHalfSizePixels) { gizmoAxis = GizmoAxis.Center; } else { GizmoAxis[] axes = Axes; foreach (GizmoAxis gizmoAxis2 in axes) { float num3 = ((Controller.Mode == EditMode.Translate) ? DistanceToTranslationAxis(camera, mousePosition, gizmoPivot, Controller.GetDisplayAxis(gizmoAxis2), num) : DistanceToRing(camera, mousePosition, gizmoPivot, Controller.GetDisplayAxis(gizmoAxis2), num * 0.82f, viewToCamera)); if (num3 < num2) { num2 = num3; gizmoAxis = gizmoAxis2; } } } _hitTestFrame = Time.frameCount; _hitTestCamera = camera; _hitTestTarget = targetTransform; _hitTestMouse = mousePosition; _hitTestPivot = gizmoPivot; _hitTestTargetRotation = targetTransform.rotation; _hitTestMode = Controller.Mode; _hitTestSpace = Controller.Space; _hitTestResult = gizmoAxis; return gizmoAxis; } private void DrawCenterHandle(Vector3 pivot, float size) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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) //IL_0038: 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) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_0046: 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_004d: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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) //IL_0075: 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) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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) float num = size * GetCenterHalfSizePixels() / 105f; Vector3 val = _renderCameraRight * num; Vector3 val2 = _renderCameraUp * num; Vector3 val3 = pivot - val - val2; Vector3 val4 = pivot + val - val2; Vector3 val5 = pivot + val + val2; Vector3 val6 = pivot - val + val2; Color color = DisplayColor(CenterColor, GizmoAxis.Center); DrawLine(val3, val4, color); DrawLine(val4, val5, color); DrawLine(val5, val6, color); DrawLine(val6, val3, color); } private void DrawTranslationAxis(Vector3 pivot, Vector3 axis, float size, Color color, GizmoAxis gizmoAxis) { //IL_0001: 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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_000e: 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_0024: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_0033: 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_003c: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) Color color2 = DisplayColor(color, gizmoAxis); Vector3 val = pivot + axis * size * 1.15f; DrawLine(pivot, val, color2); Vector3 val2 = Vector3.Cross(axis, _renderCameraForward); Vector3 val3 = ((Vector3)(ref val2)).normalized * size * 0.07f; if (((Vector3)(ref val3)).sqrMagnitude < 0.001f) { val2 = Vector3.Cross(axis, _renderCameraUp); val3 = ((Vector3)(ref val2)).normalized * size * 0.07f; } Vector3 val4 = val - axis * size * 0.16f; DrawLine(val, val4 + val3, color2); DrawLine(val, val4 - val3, color2); } private void DrawRing(Vector3 pivot, Vector3 axis, float radius, Color color, GizmoAxis gizmoAxis) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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) //IL_0042: 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_0058: 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) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_009b: 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_00b2: 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_00c9: 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_00d4: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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_011d: 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) if (!TryGetRingBasis(axis, out var u, out var v)) { return; } float frontU; float frontV; bool frontHalfOnly = TryGetRingFrontCoefficients(_renderViewToCamera, u, v, out frontU, out frontV); Color color2 = DisplayColor(color, gizmoAxis); Vector3 val = pivot + (u * RingPoints[0].x + v * RingPoints[0].y) * radius; float startSide = RingPoints[0].x * frontU + RingPoints[0].y * frontV; for (int i = 1; i <= 72; i++) { Vector3 val2 = pivot + (u * RingPoints[i].x + v * RingPoints[i].y) * radius; float num = RingPoints[i].x * frontU + RingPoints[i].y * frontV; Vector3 start = val; Vector3 end = val2; if (TryClipRingSegment(ref start, ref end, startSide, num, frontHalfOnly)) { DrawLine(start, end, color2); } val = val2; startSide = num; } } private void DrawRotationAxis(Vector3 pivot, float size, GizmoAxis axis) { //IL_0001: 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_0016: Unknown result type (might be due to invalid IL or missing references) DrawRing(pivot, Controller.GetDisplayAxis(axis), size * 0.82f, AxisColor(axis), axis); } private Color DisplayColor(Color baseColor, GizmoAxis axis) { //IL_0014: 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) if (axis != ActiveAxis && axis != HoveredAxis) { return baseColor; } return HighlightColor; } private static float DistanceToTranslationAxis(Camera camera, Vector3 mouse, Vector3 pivot, Vector3 axis, float size) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: 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_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_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) //IL_0024: 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_0033: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) Vector3 val = camera.WorldToScreenPoint(pivot + axis * size * 0.15f); Vector3 val2 = camera.WorldToScreenPoint(pivot + axis * size * 1.23f); if (val.z <= 0f || val2.z <= 0f) { return float.MaxValue; } return DistancePointToSegment(mouse, val, val2); } private static float DistanceToRing(Camera camera, Vector3 mouse, Vector3 pivot, Vector3 axis, float radius, Vector3 viewToCamera) { //IL_0000: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0101: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_015b: 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) //IL_011b: 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_0123: 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_012c: 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_014a: 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_014d: Unknown result type (might be due to invalid IL or missing references) if (!TryGetRingBasis(axis, out var u, out var v)) { return float.MaxValue; } float frontU; float frontV; bool frontHalfOnly = TryGetRingFrontCoefficients(viewToCamera, u, v, out frontU, out frontV); float num = float.MaxValue; Vector3 val = pivot + (u * RingPoints[0].x + v * RingPoints[0].y) * radius; float startSide = RingPoints[0].x * frontU + RingPoints[0].y * frontV; for (int i = 1; i <= 72; i++) { Vector3 val2 = pivot + (u * RingPoints[i].x + v * RingPoints[i].y) * radius; float num2 = RingPoints[i].x * frontU + RingPoints[i].y * frontV; Vector3 start = val; Vector3 end = val2; if (TryClipRingSegment(ref start, ref end, startSide, num2, frontHalfOnly)) { Vector3 val3 = camera.WorldToScreenPoint(start); Vector3 val4 = camera.WorldToScreenPoint(end); if (val3.z > 0f && val4.z > 0f) { num = Mathf.Min(num, DistancePointToSegment(mouse, val3, val4)); } } val = val2; startSide = num2; } return num; } private static bool TryGetRingFrontCoefficients(Vector3 viewToCamera, Vector3 u, Vector3 v, out float frontU, out float frontV) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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) frontU = Vector3.Dot(viewToCamera, u); frontV = Vector3.Dot(viewToCamera, v); float sqrMagnitude = ((Vector3)(ref viewToCamera)).sqrMagnitude; float num = frontU * frontU + frontV * frontV; if (!(sqrMagnitude > 1E-08f) || !(num > sqrMagnitude * 1E-06f)) { frontU = 0f; frontV = 0f; return false; } return true; } private static bool TryClipRingSegment(ref Vector3 start, ref Vector3 end, float startSide, float endSide, bool frontHalfOnly) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_004e: 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) if (!frontHalfOnly) { return true; } bool flag = startSide >= 0f; bool flag2 = endSide >= 0f; if (!flag && !flag2) { return false; } if (flag == flag2) { return true; } float num = Mathf.Clamp01(startSide / (startSide - endSide)); Vector3 val = Vector3.Lerp(start, end, num); if (flag) { end = val; } else { start = val; } return true; } private static Vector2[] CreateRingPoints() { //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) Vector2[] array = (Vector2[])(object)new Vector2[73]; for (int i = 0; i <= 72; i++) { float num = (float)i * (float)Math.PI * 2f / 72f; array[i] = new Vector2(Mathf.Cos(num), Mathf.Sin(num)); } return array; } private static bool TryGetRingBasis(Vector3 axis, out Vector3 u, out Vector3 v) { //IL_0028: 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_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_0021: 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_004c: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_0064: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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) float sqrMagnitude = ((Vector3)(ref axis)).sqrMagnitude; if (!(sqrMagnitude > 1E-08f)) { u = Vector3.zero; v = Vector3.zero; return false; } Vector3 val = axis / Mathf.Sqrt(sqrMagnitude); Vector3 val2 = ((Mathf.Abs(Vector3.Dot(val, Vector3.up)) > 0.9f) ? Vector3.right : Vector3.up); Vector3 val3 = Vector3.Cross(val, val2); u = ((Vector3)(ref val3)).normalized; val3 = Vector3.Cross(val, u); v = ((Vector3)(ref val3)).normalized; if (((Vector3)(ref u)).sqrMagnitude > 1E-08f) { return ((Vector3)(ref v)).sqrMagnitude > 1E-08f; } return false; } private static float GetCenterHalfSizePixels() { float num = Plugin.CenterHandleSize.Value; if (float.IsNaN(num) || float.IsInfinity(num)) { num = 35f; } return Mathf.Clamp(num, 10f, 100f) * 0.5f; } private static float CalculateWorldSize(Camera camera, Vector3 position) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Max(0.5f, camera.WorldToScreenPoint(position).z); return 2f * num * Mathf.Tan(camera.fieldOfView * ((float)Math.PI / 180f) * 0.5f) * 105f / Mathf.Max(1f, (float)Screen.height); } private static float DistancePointToSegment(Vector3 point, Vector3 a, Vector3 b) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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) //IL_0038: 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) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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_0071: 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_004e: 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) Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(point.x, point.y); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(a.x, a.y); Vector2 val3 = new Vector2(b.x, b.y) - val2; float sqrMagnitude = ((Vector2)(ref val3)).sqrMagnitude; if (sqrMagnitude < 0.001f) { return Vector2.Distance(val, val2); } float num = Mathf.Clamp01(Vector2.Dot(val - val2, val3) / sqrMagnitude); return Vector2.Distance(val, val2 + val3 * num); } private static Color AxisColor(GizmoAxis axis) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return (Color)(axis switch { GizmoAxis.Y => YColor, GizmoAxis.X => XColor, _ => ZColor, }); } private void DrawLine(Vector3 start, Vector3 end, Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_000e: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0060: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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) Vector3 val = end - start; Vector3 val2 = Vector3.Cross(_renderCameraForward, val); Vector3 val3 = ((Vector3)(ref val2)).normalized * _halfLineWidth; GL.Color(color); GL.Vertex(start); GL.Vertex(end); if (((Vector3)(ref val3)).sqrMagnitude > 0f) { GL.Vertex(start + val3); GL.Vertex(end + val3); GL.Vertex(start - val3); GL.Vertex(end - val3); } } } internal static class OptionalModTypeResolver { internal static Type FindLoadedType(string fullName) { if (string.IsNullOrEmpty(fullName)) { return null; } Assembly[] assemblies; try { assemblies = AppDomain.CurrentDomain.GetAssemblies(); } catch { return null; } for (int i = 0; i < assemblies.Length; i++) { try { Type type = assemblies[i]?.GetType(fullName, throwOnError: false, ignoreCase: false); if (type != null) { return type; } } catch { } } return null; } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] internal static class GameCameraUpdatePatch { [HarmonyPriority(0)] [HarmonyAfter(new string[] { "Azumatt.BuildCameraCHE", "Azumatt.FirstPersonMode" })] private static bool Prefix(float dt, GameCamera __instance) { EditorController controller = Plugin.Controller; if ((Object)(object)controller == (Object)null || !controller.IsActive) { return true; } controller.UpdateFreeCamera(dt); return false; } [HarmonyPriority(0)] [HarmonyAfter(new string[] { "Azumatt.BuildCameraCHE", "Azumatt.FirstPersonMode" })] private static void Postfix(GameCamera __instance) { EditorController controller = Plugin.Controller; if ((Object)(object)controller != (Object)null && controller.IsActive) { controller.ApplyFinalCameraTransform(__instance); } } } [HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")] internal static class GameCameraMouseCapturePatch { [HarmonyPriority(0)] [HarmonyAfter(new string[] { "Azumatt.BuildCameraCHE" })] private static bool Prefix() { EditorController controller = Plugin.Controller; if ((Object)(object)controller == (Object)null || !controller.IsActive) { return true; } controller.UpdateMouseCapture(); return false; } } [HarmonyPatch(typeof(PlayerController), "TakeInput")] internal static class PlayerControllerInputPatch { [HarmonyPriority(0)] [HarmonyAfter(new string[] { "Azumatt.BuildCameraCHE" })] private static bool Prefix(ref bool __result) { if ((Object)(object)Plugin.Controller == (Object)null || !Plugin.Controller.IsActive) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(KeyboardShortcut), "ModifierKeyTest")] internal static class KeyboardShortcutInputFirewallPatch { [HarmonyPriority(800)] private static bool Prefix(ref KeyboardShortcut __instance, ref bool __result) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (!EditorInputFirewall.ShouldBlockExternalShortcut(__instance)) { return true; } __result = false; return false; } } [HarmonyPatch] internal static class InventorySlotsQuickSlotHotkeysPatch { private static MethodBase FindTargetMethod() { Type type = OptionalModTypeResolver.FindLoadedType("InventorySlots.InventorySlotsPlugin"); if (!(type == null)) { return AccessTools.Method(type, "HandleQuickSlotHotkeys", new Type[1] { typeof(Player) }, (Type[])null); } return null; } private static bool Prepare() { return FindTargetMethod() != null; } private static MethodBase TargetMethod() { return FindTargetMethod(); } [HarmonyPriority(800)] private static bool Prefix(Player __0) { EditorController controller = Plugin.Controller; if (!((Object)(object)controller == (Object)null)) { return !controller.ShouldConsumeEditorShortcutForExternalHotkeys(__0); } return true; } } [HarmonyPatch(typeof(Player), "Update")] internal static class PlayerUpdatePatch { [HarmonyPriority(0)] [HarmonyAfter(new string[] { "Azumatt.BuildCameraCHE" })] private static bool Prefix(Player __instance) { EditorController controller = Plugin.Controller; if ((Object)(object)controller == (Object)null || !controller.IsActive || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return true; } controller.UpdatePlayerPlacement(__instance, Time.deltaTime); return false; } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] internal static class PlacementGhostPatch { [HarmonyPriority(0)] private static bool Prefix(Player __instance) { EditorController controller = Plugin.Controller; if (!((Object)(object)controller == (Object)null)) { return !controller.ShouldSkipVanillaGhostUpdate(__instance); } return true; } [HarmonyPriority(400)] [HarmonyAfter(new string[] { "Azumatt_and_ValheimPlusDevs.PerfectPlacement" })] [HarmonyBefore(new string[] { "aedenthorn.BuildRestrictionTweaks" })] private static void Postfix(Player __instance, bool flashGuardStone) { Plugin.Controller?.ApplyGhostOverride(__instance, flashGuardStone); } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] internal static class PlacementGhostHardRangePatch { [HarmonyPriority(0)] [HarmonyAfter(new string[] { "aedenthorn.BuildRestrictionTweaks" })] private static void Postfix(Player __instance) { Plugin.Controller?.EnforceEditorRange(__instance); } } [HarmonyPatch(typeof(Player), "TryPlacePiece")] internal static class TryPlacePiecePatch { [ThreadStatic] private static int _depth; internal static bool IsVanillaPlacementCall => _depth > 0; private static bool Prefix(Player __instance, ref bool __result, out bool __state) { EditorController controller = Plugin.Controller; __state = (Object)(object)controller != (Object)null && controller.IsActive && (Object)(object)__instance == (Object)(object)Player.m_localPlayer; if (__state) { _depth++; } if ((Object)(object)controller == (Object)null || !controller.ShouldBlockVanillaPlacement(__instance)) { return true; } __result = false; return false; } private static void Postfix(Player __instance, bool __result) { if (__result) { Plugin.Controller?.OnVanillaPlacementSucceeded(__instance); } } private static Exception Finalizer(Exception __exception, bool __state) { if (__state && _depth > 0) { _depth--; } return __exception; } } [HarmonyPatch(typeof(Player), "PlacePiece")] internal static class PlacePieceFinalPosePatch { [HarmonyPriority(0)] private static void Prefix(Player __instance, Piece __0, ref Vector3 __1, ref Quaternion __2) { //IL_0025: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) EditorController controller = Plugin.Controller; if (TryPlacePiecePatch.IsVanillaPlacementCall && (Object)(object)controller != (Object)null && controller.TryGetFinalPlacementPose(__instance, __0, out var position, out var rotation)) { __1 = position; __2 = rotation; } } } [HarmonyPatch(typeof(Player), "CopyPiece")] internal static class CopyPieceExecutionContextPatch { [ThreadStatic] private static int _depth; internal static bool IsCopyPieceCall => _depth > 0; private static void Prefix() { _depth++; } private static void Postfix(Player __instance, bool __result) { Plugin.Controller?.OnVanillaCopyCompleted(__instance, __result); } private static Exception Finalizer(Exception __exception) { if (_depth > 0) { _depth--; } return __exception; } } [HarmonyPatch(typeof(Player), "SetSelectedPiece", new Type[] { typeof(Piece) })] internal static class CopiedPieceSelectionPatch { private struct SampledPoseState { internal bool Valid; internal Vector3 Position; internal Quaternion Rotation; } [HarmonyPriority(800)] private static void Prefix(Player __instance, Piece __0, out SampledPoseState __state) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_003c: Unknown result type (might be due to invalid IL or missing references) __state = default(SampledPoseState); EditorController controller = Plugin.Controller; if (CopyPieceExecutionContextPatch.IsCopyPieceCall && !((Object)(object)controller == (Object)null) && controller.TryCaptureSampledPiecePose(__instance, __0, out var position, out var rotation)) { __state.Valid = true; __state.Position = position; __state.Rotation = rotation; } } private static void Postfix(Player __instance, bool __result, SampledPoseState __state) { //IL_0017: 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) if (__result && __state.Valid) { Plugin.Controller?.OnVanillaPieceSampled(__instance, __state.Position, __state.Rotation); } } } [HarmonyPatch(typeof(CraftingStation), "HaveBuildStationInRange")] internal static class BuildStationRangePatch { [HarmonyPriority(0)] private static void Postfix(string name, Vector3 point, ref CraftingStation __result) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) EditorController controller = Plugin.Controller; if ((Object)(object)__result == (Object)null && (Object)(object)controller != (Object)null && controller.ShouldExtendBuildStationRange) { __result = CraftingStation.FindClosestStationInRange(name, point, controller.ActiveEditorRange); } } } [HarmonyPatch(typeof(Player), "RemovePiece")] internal static class RemovePieceExecutionContextPatch { [ThreadStatic] private static bool _isEditorRemoval; internal static bool IsEditorRemoval => _isEditorRemoval; private static void Prefix(Player __instance, out EditorController.DemolitionPickupTransaction __state) { __state = null; EditorController controller = Plugin.Controller; _isEditorRemoval = (Object)(object)controller != (Object)null && controller.IsActive && (Object)(object)__instance == (Object)(object)Player.m_localPlayer; if (!_isEditorRemoval) { return; } try { __state = controller.CaptureDemolitionPickup(__instance); } catch (Exception arg) { Plugin.LogError($"Could not prepare demolition resource pickup: {arg}"); } } private static void Postfix(bool __result, EditorController.DemolitionPickupTransaction __state) { try { if (__result) { Plugin.Controller?.CommitDemolitionPickup(__state); } } finally { _isEditorRemoval = false; } } private static Exception Finalizer(Exception __exception) { _isEditorRemoval = false; return __exception; } } [HarmonyPatch(typeof(Player), "CheckCanRemovePiece")] internal static class RemovePieceStationRequirementPatch { [HarmonyPriority(800)] private static bool Prefix(Player __instance, ref bool __result) { EditorController controller = Plugin.Controller; if ((Object)(object)controller == (Object)null || !controller.IsActive || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || !RemovePieceExecutionContextPatch.IsEditorRemoval) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(Player), "UpdateBuildGuiInput")] internal static class BuildMenuEscapeOwnershipPatch { private static void Prefix() { if ((Object)(object)Plugin.Controller != (Object)null && Plugin.Controller.IsActive && Hud.IsPieceSelectionVisible() && Input.GetKeyDown((KeyCode)27)) { EditorController.ReserveBuildMenuEscapeInput(); } } } [HarmonyPatch(typeof(Menu), "Update")] internal static class MenuInputOwnershipPatch { private static bool Prefix() { if (!Input.GetKeyDown((KeyCode)27)) { return true; } EditorController controller = Plugin.Controller; if ((Object)(object)controller != (Object)null && controller.IsActive && Hud.IsPieceSelectionVisible()) { return false; } if (EditorController.BuildMenuConsumedEscapeThisFrame || EditorController.SuppressMenuThisFrame) { return false; } if ((Object)(object)controller != (Object)null && controller.ShouldOwnEscapeInput) { controller.ReserveEscapeInput(); return false; } return true; } } [HarmonyPatch(typeof(ZNet), "Shutdown")] internal static class ZNetShutdownPatch { private static void Prefix() { Plugin.Controller?.ForceExit(); } } [HarmonyPatch(typeof(ZNet), "ShutdownWithoutSave")] internal static class ZNetShutdownWithoutSavePatch { private static void Prefix() { Plugin.Controller?.ForceExit(); } } [HarmonyPatch(typeof(ZNet), "OnDestroy")] internal static class ZNetDestroyPatch { private static void Prefix() { Plugin.Controller?.ForceExit(); } } internal sealed class PlacementGhostVisual { private struct MaterialState { internal Material Material; internal bool HadColor; internal Color Color; internal bool HadBaseColor; internal Color BaseColor; internal bool HadTintColor; internal Color TintColor; internal bool HadEmissionColor; internal Color EmissionColor; internal bool EmissionKeywordEnabled; } private const string ColorProperty = "_Color"; private const string BaseColorProperty = "_BaseColor"; private const string TintColorProperty = "_TintColor"; private const string EmissionColorProperty = "_EmissionColor"; private const string EmissionKeyword = "_EMISSION"; private static readonly Color GhostColor = new Color(0.22f, 0.66f, 1f, 0.75f); private static readonly Color GhostEmissionColor = new Color(0.05f, 0.42f, 0.9f, 0.9f); private readonly List _materialStates = new List(32); private readonly HashSet _seenMaterials = new HashSet(); private GameObject _ghost; internal void Sync(GameObject ghost) { if (_ghost != ghost) { Restore(); if (!((Object)(object)ghost == (Object)null)) { _ghost = ghost; Apply(ghost.GetComponentsInChildren()); Apply(ghost.GetComponentsInChildren()); _seenMaterials.Clear(); } } } internal void Restore() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_0076: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < _materialStates.Count; i++) { MaterialState materialState = _materialStates[i]; Material material = materialState.Material; if (!((Object)(object)material == (Object)null)) { RestoreColor(material, "_Color", materialState.HadColor, materialState.Color); RestoreColor(material, "_BaseColor", materialState.HadBaseColor, materialState.BaseColor); RestoreColor(material, "_TintColor", materialState.HadTintColor, materialState.TintColor); RestoreColor(material, "_EmissionColor", materialState.HadEmissionColor, materialState.EmissionColor); if (materialState.EmissionKeywordEnabled) { material.EnableKeyword("_EMISSION"); } else { material.DisableKeyword("_EMISSION"); } } } _materialStates.Clear(); _seenMaterials.Clear(); _ghost = null; } private void Apply(T[] renderers) where T : Renderer { //IL_0088: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) foreach (T val in renderers) { if ((Object)(object)val == (Object)null || (Object)(object)((Renderer)val).sharedMaterial == (Object)null) { continue; } Material[] sharedMaterials = ((Renderer)val).sharedMaterials; foreach (Material val2 in sharedMaterials) { if (!((Object)(object)val2 == (Object)null) && _seenMaterials.Add(val2)) { MaterialState item = Capture(val2); _materialStates.Add(item); SetColor(val2, "_Color", GhostColor); SetColor(val2, "_BaseColor", GhostColor); SetColor(val2, "_TintColor", GhostColor); SetColor(val2, "_EmissionColor", GhostEmissionColor); if (item.HadEmissionColor) { val2.EnableKeyword("_EMISSION"); } } } } } private static MaterialState Capture(Material material) { MaterialState result = new MaterialState { Material = material, EmissionKeywordEnabled = material.IsKeywordEnabled("_EMISSION") }; CaptureColor(material, "_Color", out result.HadColor, out result.Color); CaptureColor(material, "_BaseColor", out result.HadBaseColor, out result.BaseColor); CaptureColor(material, "_TintColor", out result.HadTintColor, out result.TintColor); CaptureColor(material, "_EmissionColor", out result.HadEmissionColor, out result.EmissionColor); return result; } private static void CaptureColor(Material material, string property, out bool exists, out Color color) { //IL_001b: 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_0016: 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) exists = material.HasProperty(property); color = (Color)(exists ? material.GetColor(property) : default(Color)); } private static void SetColor(Material material, string property, Color color) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (material.HasProperty(property)) { material.SetColor(property, color); } } private static void RestoreColor(Material material, string property, bool existed, Color color) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (existed && material.HasProperty(property)) { material.SetColor(property, color); } } } [BepInPlugin("Obelisk.UEPlacementEditor", "Build Ease", "0.3.16")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string ModGuid = "Obelisk.UEPlacementEditor"; public const string ModName = "Build Ease"; public const string ModVersion = "0.3.16"; internal static ConfigEntry ToggleEditorKey; internal static ConfigEntry ToggleSurfaceSnapKey; internal static ConfigEntry ToggleCoordinateSpaceKey; internal static ConfigEntry ToggleCameraLightKey; internal static ConfigEntry ToggleCameraRayFollowKey; internal static ConfigEntry BoundsStepModifier; internal static ConfigEntry CameraSpeed; internal static ConfigEntry FastCameraMultiplier; internal static ConfigEntry MouseSensitivity; internal static ConfigEntry CameraLightRange; internal static ConfigEntry CameraLightIntensity; internal static ConfigEntry EditorRange; internal static ConfigEntry RotationSnap; internal static ConfigEntry StartWithSnap; internal static ConfigEntry BlueGhostPreview; internal static ConfigEntry CenterHandleSize; internal static ConfigEntry ShowToolbar; private Harmony _harmony; private static ManualLogSource _log; internal static EditorController Controller { get; private set; } internal static void LogError(string message) { ManualLogSource log = _log; if (log != null) { log.LogError((object)message); } } private void Awake() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Expected O, but got Unknown //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) _log = ((BaseUnityPlugin)this).Logger; ToggleEditorKey = ((BaseUnityPlugin)this).Config.Bind("General", "Toggle editor", new KeyboardShortcut((KeyCode)98, Array.Empty()), "Enter or leave the extended placement editor. If needed, equips a building hammer from the player's inventory first."); ConfigEntry val = ((BaseUnityPlugin)this).Config.Bind("Internal", "Input defaults schema", 0, "Internal one-time migration marker for default hotkeys."); if (val.Value < 1) { if (((object)ToggleEditorKey.Value/*cast due to .constrained prefix*/).Equals((object)new KeyboardShortcut((KeyCode)271, Array.Empty()))) { ToggleEditorKey.Value = new KeyboardShortcut((KeyCode)98, Array.Empty()); } val.Value = 1; } ToggleSurfaceSnapKey = ((BaseUnityPlugin)this).Config.Bind("Hotkeys", "Toggle surface snapping", new KeyboardShortcut((KeyCode)103, Array.Empty()), "Enable or disable surface and vanilla build-point snapping for the centre translation handle."); ToggleCoordinateSpaceKey = ((BaseUnityPlugin)this).Config.Bind("Hotkeys", "Toggle coordinate space", new KeyboardShortcut((KeyCode)120, Array.Empty()), "Switch the gizmo between world and local axes."); ToggleCameraLightKey = ((BaseUnityPlugin)this).Config.Bind("Hotkeys", "Toggle camera light", new KeyboardShortcut((KeyCode)102, Array.Empty()), "Create or remove a shadowless point light at the free camera while the editor is active. Do not reuse a camera movement or editor action key."); ToggleCameraRayFollowKey = ((BaseUnityPlugin)this).Config.Bind("Hotkeys", "Toggle camera ray follow", new KeyboardShortcut((KeyCode)116, Array.Empty()), "Continuously place the selected preview on the surface under the centre of the free camera. Press again to freeze its exact pose."); ConfigEntry val2 = ((BaseUnityPlugin)this).Config.Bind("Hotkeys", "Snap-point step modifier", (KeyCode)306, "Obsolete setting retained only for one-time config migration."); BoundsStepModifier = ((BaseUnityPlugin)this).Config.Bind("Hotkeys", "Bounds step modifier", (KeyCode)306, "Hold this key while dragging an X/Y/Z translation arrow to force increments equal to the piece's projected visual-bounds size along that axis. Shift is not required; it independently uses the span between the piece's outer vanilla snap points, with a bounds fallback. Set to None to disable this override, and do not reuse an editor action key."); if (val.Value < 2) { BoundsStepModifier.Value = val2.Value; val.Value = 2; } ((BaseUnityPlugin)this).Config.Remove(((ConfigEntryBase)val2).Definition); CameraSpeed = ((BaseUnityPlugin)this).Config.Bind("Camera", "Move speed", 12f, "Free camera movement speed."); FastCameraMultiplier = ((BaseUnityPlugin)this).Config.Bind("Camera", "Fast multiplier", 3f, "Camera speed multiplier while Shift is held."); MouseSensitivity = ((BaseUnityPlugin)this).Config.Bind("Camera", "Mouse sensitivity", 2f, "Free camera look sensitivity."); CameraLightRange = ((BaseUnityPlugin)this).Config.Bind("Lighting", "Camera light range", 100f, "Radius of the temporary camera light in metres (1-100)."); CameraLightIntensity = ((BaseUnityPlugin)this).Config.Bind("Lighting", "Camera light intensity", 1.5f, "Intensity of the temporary camera light (0-10). Shadows are always disabled."); EditorRange = ((BaseUnityPlugin)this).Config.Bind("Safety", "Maximum editor range", 100f, "Maximum free-camera, construction and removal distance from the player in metres (20-200)."); RotationSnap = ((BaseUnityPlugin)this).Config.Bind("Snapping", "Rotation step", 5f, "Rotation step in degrees. Set to 0 for continuous rotation."); StartWithSnap = ((BaseUnityPlugin)this).Config.Bind("Snapping", "Enabled by default", true, "Start each editor session with surface and vanilla build-point snapping enabled."); BlueGhostPreview = ((BaseUnityPlugin)this).Config.Bind("Visuals", "Blue ghost preview", false, "Tint the selected placement preview blue with emission while the extended editor is active."); CenterHandleSize = ((BaseUnityPlugin)this).Config.Bind("Visuals", "Center handle size", 35f, "Full width and height of the centre translation handle in screen pixels (10-100)."); ShowToolbar = ((BaseUnityPlugin)this).Config.Bind("Interface", "Show toolbar", true, "Show the editor toolbar at the top of the screen. The gizmo and controls remain active when it is hidden."); RemoveObsoleteSetting("General", "Toggle cursor capture", new KeyboardShortcut((KeyCode)308, Array.Empty())); RemoveObsoleteSetting("Snapping", "Position step", 0.5f); RemoveObsoleteSetting("Safety", "Existing piece edit range", 50f); ((BaseUnityPlugin)this).Config.Save(); EditorInputFirewall.Initialize(); Controller = ((Component)this).gameObject.AddComponent(); _harmony = new Harmony("Obelisk.UEPlacementEditor"); _harmony.PatchAll(typeof(Plugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Build Ease 0.3.16 loaded"); } private void RemoveObsoleteSetting(string section, string key, T defaultValue) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown ConfigDefinition val = new ConfigDefinition(section, key); ((BaseUnityPlugin)this).Config.Bind(val, defaultValue, new ConfigDescription("Obsolete setting retained only for one-time config cleanup.", (AcceptableValueBase)null, Array.Empty())); ((BaseUnityPlugin)this).Config.Remove(val); } private void OnDestroy() { Controller?.ForceExit(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } EditorInputFirewall.Shutdown(); Controller = null; _log = null; } }