Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of EncounterQoL v0.0.11
plugins/EncounterQoL.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using System.Text; using Advize_PlantEasily; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using EncounterQoL.Configuration; using EncounterQoL.Core; using EncounterQoL.Modules; using HarmonyLib; using Jotunn.Configs; using Jotunn.Extensions; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using MultiUserChest; using MultiUserChest.Patches; using Splatform; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("EncounterQoL")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("EncounterQoL")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.11")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.11.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Advize_PlantEasily { internal enum GridSnappingStyle { Intelligent, Legacy } internal enum HarvestStyle { LikeResources, AllResources } internal enum CostDisplayStyle { TotalCount, FullCost } internal enum CostDisplayLocation { LeftSide, RightSide } internal sealed class EncounterPlantEasilyConfig { private readonly ConfigEntry<KeyboardShortcut> _snapToggleKey; private readonly ConfigEntry<KeyboardShortcut> _autoReplantToggleKey; private readonly ConfigEntry<bool> _snapActive; private readonly ConfigEntry<bool> _replantOnHarvest; private readonly ConfigEntry<KeyboardShortcut> _modifierKey; private readonly ConfigEntry<KeyboardShortcut> _increaseColumnsKey; private readonly ConfigEntry<KeyboardShortcut> _decreaseColumnsKey; private readonly ConfigEntry<KeyboardShortcut> _increaseRowsKey; private readonly ConfigEntry<KeyboardShortcut> _decreaseRowsKey; internal const int MinimumGridSize = 1; internal const int MaximumGridSize = 10; internal KeyboardShortcut SnapToggleKey => _snapToggleKey.Value; internal KeyboardShortcut AutoReplantToggleKey => _autoReplantToggleKey.Value; internal KeyboardShortcut ModifierKey => _modifierKey.Value; internal KeyboardShortcut IncreaseColumnsKey => _increaseColumnsKey.Value; internal KeyboardShortcut DecreaseColumnsKey => _decreaseColumnsKey.Value; internal KeyboardShortcut IncreaseRowsKey => _increaseRowsKey.Value; internal KeyboardShortcut DecreaseRowsKey => _decreaseRowsKey.Value; internal bool ModActive => true; internal bool SnapActive { get { return _snapActive.Value; } set { _snapActive.Value = value; } } internal int Rows { get; set; } = 2; internal int Columns { get; set; } = 2; internal int MaxConcurrentPlacements => 100; internal bool RandomizeRotation => true; internal bool EnableScatter => true; internal float PositionScatterRadius => 0f; internal float RotationScatterAngle => 0f; internal bool GloballyAlignGridDirections => true; internal bool MinimizeGridSpacing => false; internal GridSnappingStyle GridSnappingStyle => GridSnappingStyle.Intelligent; internal bool ForceAltPlacement => false; internal bool PreferCardinalSnapping => false; internal float ExtraCropSpacing => 0f; internal float ExtraSaplingSpacing => 0f; internal bool PreventPartialPlanting => false; internal bool PreventInvalidPlanting => true; internal bool UseStamina => true; internal bool UseDurability => true; internal int GhostUpdateBatchSize => 20; internal int BulkPlantingBatchSize => 2; internal bool PreventOverlappingPlacements => true; internal float DefaultGridSpacing => 1f; internal bool ShowGhostsDuringPlacement => true; internal bool ShowGridDirections => true; internal bool ShowSnapDirection => true; internal bool ShowCost => true; internal CostDisplayStyle CostDisplayStyle => CostDisplayStyle.TotalCount; internal CostDisplayLocation CostDisplayLocation => CostDisplayLocation.RightSide; internal bool ShowHUDKeyHints => true; internal bool ShowHoverKeyHints => true; internal bool HighlightRootPlacementGhost => true; internal Color RootGhostHighlightColor => Color.green; internal Color RowStartColor => Color.blue; internal Color RowEndColor => Color.cyan; internal Color ColumnStartColor => Color.green; internal Color ColumnEndColor => Color.yellow; internal Color SnapStartColor => Color.red; internal Color SnapEndColor => Color.magenta; internal bool EnableBulkHarvest => false; internal HarvestStyle HarvestStyle => HarvestStyle.AllResources; internal float HarvestRadius => 3f; internal bool ReplantOnHarvest { get { return _replantOnHarvest.Value; } set { _replantOnHarvest.Value = value; } } internal bool ShowHoverReplantHint => true; internal EncounterPlantEasilyConfig(ConfigFile config) { //IL_002a: 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_00b6: 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_0134: 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) _snapToggleKey = config.Bind<KeyboardShortcut>("Farming", "Plant Grid Snapping Toggle Key", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Toggle intelligent plant-grid snapping on or off."); _autoReplantToggleKey = config.Bind<KeyboardShortcut>("Farming", "Auto Replant Toggle Key", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Toggle automatic crop replanting on or off."); _snapActive = config.Bind<bool>("Farming", "Plant Grid Snapping", true, "Whether intelligent plant-grid snapping is currently active. F10 toggles this setting."); _replantOnHarvest = config.Bind<bool>("Farming", "Auto Replant", true, "Whether harvested crops are automatically replanted when requirements are available. F6 toggles this setting."); _modifierKey = config.Bind<KeyboardShortcut>("Farming", "Plant Grid Modifier Key", new KeyboardShortcut((KeyCode)305, Array.Empty<KeyCode>()), "Hold this key while using the plant grid resize keys."); _increaseColumnsKey = config.Bind<KeyboardShortcut>("Farming", "Plant Grid Increase Columns Key", new KeyboardShortcut((KeyCode)275, Array.Empty<KeyCode>()), "Increase plant grid columns by one."); _decreaseColumnsKey = config.Bind<KeyboardShortcut>("Farming", "Plant Grid Decrease Columns Key", new KeyboardShortcut((KeyCode)276, Array.Empty<KeyCode>()), "Decrease plant grid columns by one."); _increaseRowsKey = config.Bind<KeyboardShortcut>("Farming", "Plant Grid Increase Rows Key", new KeyboardShortcut((KeyCode)273, Array.Empty<KeyCode>()), "Increase plant grid rows by one."); _decreaseRowsKey = config.Bind<KeyboardShortcut>("Farming", "Plant Grid Decrease Rows Key", new KeyboardShortcut((KeyCode)274, Array.Empty<KeyCode>()), "Decrease plant grid rows by one."); } internal bool TryGetScatterRadius(out float radius) { radius = PositionScatterRadius; if (EnableScatter) { return radius > 0f; } return false; } internal bool TryGetScatterAngle(out float angle) { angle = RotationScatterAngle; if (EnableScatter) { return angle > 0f; } return false; } } [HarmonyPatch] internal static class EncounterPlantEasilyHarvestBridge { private static readonly HashSet<int> PendingReplants = new HashSet<int>(); [HarmonyPatch(typeof(ZNetScene), "Awake")] [HarmonyPostfix] private static void ZNetSceneAwakePostfix(ZNetScene __instance) { RebuildRegistry(__instance); } [HarmonyPatch(typeof(Pickable), "Interact")] [HarmonyPrefix] private static void PickableInteractPrefix(Pickable __instance, Humanoid character) { if (!((Object)(object)__instance == (Object)null) && character is Player && ModContext.config != null && ModContext.config.ReplantOnHarvest) { string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject); if (ReplantDB.Registry.ContainsKey(prefabName)) { PendingReplants.Add(((Object)__instance).GetInstanceID()); } } } [HarmonyPatch(typeof(Pickable), "SetPicked")] [HarmonyPrefix] private static void PickableSetPickedPrefix(Pickable __instance, bool picked) { if (!((Object)(object)__instance == (Object)null) && picked && ModContext.config != null && ModContext.config.ReplantOnHarvest) { int instanceID = ((Object)__instance).GetInstanceID(); if (PendingReplants.Remove(instanceID)) { TryReplant(__instance); } } } private static void RebuildRegistry(ZNetScene scene) { if ((Object)(object)scene == (Object)null) { return; } ModContext.PrefabRefs.Clear(); ReplantDB.Registry.Clear(); List<GameObject> prefabs = scene.m_prefabs; if (prefabs == null) { return; } for (int i = 0; i < prefabs.Count; i++) { GameObject val = prefabs[i]; if (!((Object)(object)val == (Object)null)) { ModContext.PrefabRefs[((Object)val).name] = val; } } for (int j = 0; j < prefabs.Count; j++) { GameObject val2 = prefabs[j]; if ((Object)(object)val2 == (Object)null || (Object)(object)val2.GetComponent<Piece>() == (Object)null) { continue; } Plant component = val2.GetComponent<Plant>(); if ((Object)(object)component == (Object)null || component.m_grownPrefabs == null || component.m_grownPrefabs.Length == 0) { continue; } bool flag = true; for (int k = 0; k < component.m_grownPrefabs.Length; k++) { GameObject val3 = component.m_grownPrefabs[k]; if ((Object)(object)val3 == (Object)null || (Object)(object)val3.GetComponent<Pickable>() == (Object)null || (Object)(object)val3.GetComponent<Vine>() != (Object)null || (Object)(object)val3.GetComponent<TreeBase>() != (Object)null) { flag = false; break; } } if (!flag) { continue; } try { ReplantDB replantDB = new ReplantDB(val2); if ((Object)(object)replantDB.Pickable != (Object)null) { ReplantDB.Registry[((Object)replantDB.Pickable).name] = replantDB; } } catch (Exception) { } } } private static void TryReplant(Pickable pickable) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)pickable == (Object)null) { return; } string key = (string.IsNullOrEmpty(PlacementState.LastSelectedPlantName) ? Utils.GetPrefabName(((Component)pickable).gameObject) : PlacementState.LastSelectedPlantName); if (ReplantDB.Registry.TryGetValue(key, out var value) && !string.IsNullOrEmpty(value.PlantName) && ModContext.PrefabRefs.TryGetValue(value.PlantName, out var value2) && !((Object)(object)value2 == (Object)null)) { Piece component = value2.GetComponent<Piece>(); if (!((Object)(object)component == (Object)null) && (localPlayer.m_noPlacementCost || localPlayer.HaveRequirements(component, (RequirementMode)0))) { PlacementController.PlacePiece(localPlayer, ((Component)pickable).gameObject, ((Component)component).gameObject); } } } } [HarmonyPatch(typeof(Player), "Update")] internal static class EncounterPlantEasilyInput { private static void Postfix(Player __instance) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_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_00ea: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: 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_0148: 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_0150: 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_0189: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || ModContext.config == null || !Object.op_Implicit((Object)(object)PlacementState.PlacementGhost) || !ModUtils.HoldingCultivator) { return; } KeyboardShortcut val = ModContext.config.AutoReplantToggleKey; if (((KeyboardShortcut)(ref val)).IsDown()) { ModContext.config.ReplantOnHarvest = !ModContext.config.ReplantOnHarvest; ((Character)__instance).Message((MessageType)1, "Auto Replant: " + (ModContext.config.ReplantOnHarvest ? "On" : "Off"), 0, (Sprite)null, false); } val = ModContext.config.SnapToggleKey; if (((KeyboardShortcut)(ref val)).IsDown()) { ModContext.config.SnapActive = !ModContext.config.SnapActive; ((Character)__instance).Message((MessageType)1, "Plant Grid Snapping: " + (ModContext.config.SnapActive ? "On" : "Off"), 0, (Sprite)null, false); __instance.SetupPlacementGhost(); } val = ModContext.config.ModifierKey; KeyCode mainKey = ((KeyboardShortcut)(ref val)).MainKey; if ((int)mainKey == 0 || !ZInput.GetKey(mainKey, false)) { return; } bool flag = false; val = ModContext.config.IncreaseColumnsKey; if (ZInput.GetKeyDown(((KeyboardShortcut)(ref val)).MainKey, false)) { ModContext.config.Columns = ClampGrid(ModContext.config.Columns + 1); flag = true; } else { val = ModContext.config.DecreaseColumnsKey; if (ZInput.GetKeyDown(((KeyboardShortcut)(ref val)).MainKey, false)) { ModContext.config.Columns = ClampGrid(ModContext.config.Columns - 1); flag = true; } else { val = ModContext.config.IncreaseRowsKey; if (ZInput.GetKeyDown(((KeyboardShortcut)(ref val)).MainKey, false)) { ModContext.config.Rows = ClampGrid(ModContext.config.Rows + 1); flag = true; } else { val = ModContext.config.DecreaseRowsKey; if (ZInput.GetKeyDown(((KeyboardShortcut)(ref val)).MainKey, false)) { ModContext.config.Rows = ClampGrid(ModContext.config.Rows - 1); flag = true; } } } } if (flag) { GhostGrid.ResizeGrid(); __instance.SetupPlacementGhost(); ((Character)__instance).Message((MessageType)1, "Plant Grid: " + ModContext.config.Columns + " x " + ModContext.config.Rows, 0, (Sprite)null, false); } } private static int ClampGrid(int value) { if (value < 1) { return 1; } if (value > 10) { return 10; } return value; } } [HarmonyPatch] internal static class EncounterPlantEasilyKeyHints { private static GameObject _keyboardHint; [HarmonyPatch(typeof(KeyHints), "Start")] [HarmonyPostfix] private static void StartPostfix() { CreateKeyboardHint(); } [HarmonyPatch(typeof(KeyHints), "ApplySettings")] [HarmonyPostfix] private static void ApplySettingsPostfix() { UpdateKeyboardHint(); } [HarmonyPatch(typeof(KeyHints), "UpdateHints")] [HarmonyPostfix] private static void UpdateHintsPostfix() { if (!((Object)(object)_keyboardHint == (Object)null)) { _keyboardHint.SetActive(ModContext.config != null && ModContext.config.ShowHUDKeyHints && ModUtils.HoldingCultivator); } } private static void CreateKeyboardHint() { if ((Object)(object)_keyboardHint != (Object)null || (Object)(object)KeyHints.m_instance == (Object)null || (Object)(object)KeyHints.m_instance.m_buildHints == (Object)null) { return; } Transform val = KeyHints.m_instance.m_buildHints.transform.Find("Keyboard"); if ((Object)(object)val == (Object)null) { return; } Transform val2 = val.Find("Copy"); if ((Object)(object)val2 == (Object)null) { return; } _keyboardHint = Object.Instantiate<GameObject>(((Component)val2).gameObject, val); ((Object)_keyboardHint).name = "Resize Grid"; Transform transform = _keyboardHint.transform; if (transform.childCount >= 2) { transform.SetSiblingIndex(3); Transform child = transform.GetChild(0); TextMeshProUGUI component = ((Component)child).GetComponent<TextMeshProUGUI>(); if ((Object)(object)component != (Object)null) { ((TMP_Text)component).text = "Grid Size"; } LayoutElement component2 = ((Component)child).GetComponent<LayoutElement>(); if ((Object)(object)component2 != (Object)null) { component2.preferredWidth = 75f; } GameObject gameObject = ((Component)transform.GetChild(1)).gameObject; for (int i = 0; i < 3; i++) { Object.Instantiate<GameObject>(gameObject, transform); } UpdateKeyboardHint(); _keyboardHint.SetActive(false); } } private static void UpdateKeyboardHint() { //IL_0031: 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_005d: 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_0089: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_keyboardHint == (Object)null) && ModContext.config != null) { Transform transform = _keyboardHint.transform; if (transform.childCount >= 7) { SetKeyText(transform, 1, FormatShortcut(ModContext.config.ModifierKey)); SetKeyText(transform, 3, FormatShortcut(ModContext.config.DecreaseColumnsKey)); SetKeyText(transform, 4, FormatShortcut(ModContext.config.IncreaseRowsKey)); SetKeyText(transform, 5, FormatShortcut(ModContext.config.IncreaseColumnsKey)); SetKeyText(transform, 6, FormatShortcut(ModContext.config.DecreaseRowsKey)); } } } private static void SetKeyText(Transform root, int childIndex, string text) { Transform child = root.GetChild(childIndex); if (!((Object)(object)child == (Object)null) && child.childCount != 0) { TextMeshProUGUI component = ((Component)child.GetChild(0)).GetComponent<TextMeshProUGUI>(); if ((Object)(object)component != (Object)null) { ((TMP_Text)component).text = text; } } } private static string FormatShortcut(KeyboardShortcut shortcut) { //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_0008: 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_0024: Expected I4, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) KeyCode mainKey = ((KeyboardShortcut)(ref shortcut)).MainKey; return (mainKey - 273) switch { 0 => "↑", 2 => "→", 1 => "↓", 3 => "←", _ => ZInput.KeyCodeToDisplayName(mainKey), }; } } [HarmonyPatch] internal static class EncounterPlantEasilyUiPatches { [HarmonyPatch(typeof(InventoryGui), "SetupRequirement")] [HarmonyPriority(0)] [HarmonyPostfix] private static void SetupRequirementPostfix(Transform elementRoot, Requirement req) { if (ModContext.config == null || !ModContext.config.ShowCost || GhostGrid.ExtraGhosts.Count < 1 || (Object)(object)elementRoot == (Object)null || req == null) { return; } Transform val = elementRoot.Find("res_amount"); if (!((Object)(object)val == (Object)null)) { TMP_Text component = ((Component)val).GetComponent<TMP_Text>(); if (!((Object)(object)component == (Object)null)) { int num = Mathf.Min(ModContext.config.Rows * ModContext.config.Columns, ModContext.config.MaxConcurrentPlacements); string text = ((ModContext.config.CostDisplayStyle != CostDisplayStyle.TotalCount) ? ("(" + req.m_amount * num + ")") : ((ModContext.config.CostDisplayLocation == CostDisplayLocation.LeftSide) ? (num + "x") : ("x" + num))); component.text = ((ModContext.config.CostDisplayLocation == CostDisplayLocation.LeftSide) ? (text + component.text) : (component.text + text)); } } } } [HarmonyPatch] internal static class EncounterPlantEasilyVisualBridge { private static bool _initialized; [HarmonyPatch(typeof(ZNetScene), "Awake")] [HarmonyPostfix] private static void ZNetSceneAwakePostfix() { Initialize(); } internal static void Initialize() { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //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) if (_initialized && (Object)(object)GhostGrid.DirectionRenderer != (Object)null && GhostGrid.LineRenderers.Count == 3) { return; } Material val = ((IEnumerable<Material>)Resources.FindObjectsOfTypeAll<Material>()).FirstOrDefault((Func<Material, bool>)((Material candidate) => (Object)(object)candidate != (Object)null && ((Object)candidate).name == "Default-Line")); if ((Object)(object)val == (Object)null) { ManualLogSource logger = ModContext.Logger; if (logger != null) { logger.LogWarning((object)"Plant Easily could not find Valheim's Default-Line material. Grid direction lines were not initialized."); } return; } Shutdown(); GhostGrid.DirectionRenderer = new GameObject("EncounterQoL Plant Grid Directions"); Object.DontDestroyOnLoad((Object)(object)GhostGrid.DirectionRenderer); for (int num = 0; num < 3; num++) { GameObject val2 = new GameObject("Direction " + num); val2.transform.SetParent(GhostGrid.DirectionRenderer.transform); LineRenderer val3 = val2.AddComponent<LineRenderer>(); ((Renderer)val3).material = val; val3.widthMultiplier = 0.025f; val3.positionCount = 2; GhostGrid.LineRenderers.Add(val3); } ApplyDefaultColors(); GhostGrid.DirectionRenderer.SetActive(false); _initialized = true; } private static void ApplyDefaultColors() { //IL_001e: 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_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_0066: 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) if (GhostGrid.LineRenderers.Count >= 3) { SetGradient(GhostGrid.LineRenderers[0], ModContext.config.RowStartColor, ModContext.config.RowEndColor); SetGradient(GhostGrid.LineRenderers[1], ModContext.config.ColumnStartColor, ModContext.config.ColumnEndColor); SetGradient(GhostGrid.LineRenderers[2], ModContext.config.SnapStartColor, ModContext.config.SnapEndColor); } } private static void SetGradient(LineRenderer renderer, Color start, Color end) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0019: 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_002b: 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_0043: 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) //IL_005a: 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_006a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)renderer == (Object)null)) { Gradient val = new Gradient(); val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(start, 0f), new GradientColorKey(end, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[2] { new GradientAlphaKey(start.a, 0f), new GradientAlphaKey(end.a, 1f) }); renderer.colorGradient = val; } } internal static void Shutdown() { if ((Object)(object)GhostGrid.DirectionRenderer != (Object)null) { Object.Destroy((Object)(object)GhostGrid.DirectionRenderer); GhostGrid.DirectionRenderer = null; } GhostGrid.LineRenderers.Clear(); _initialized = false; } } internal static class ModContext { internal static EncounterPlantEasilyConfig config; internal static ManualLogSource Logger; internal static readonly Dictionary<string, GameObject> PrefabRefs = new Dictionary<string, GameObject>(); internal static readonly List<PickableDB> PickableRefs = new List<PickableDB>(); internal static void Dbgl(string message, LogLevel level = (LogLevel)32, bool forceLog = false) { //IL_0018: 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_000d: Invalid comparison between Unknown and I4 //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Invalid comparison between Unknown and I4 if (Logger != null && (forceLog || (int)level == 2 || (int)level == 4)) { Logger.Log(level, (object)message); } } } internal enum Status { Healthy, LackResources, NotCultivated, WrongBiome, NoSpace, NoSun, Invalid, NoAttachPiece, TooHot, TooCold } internal static class ModUtils { internal static bool HoldingCultivator { get { Player localPlayer = Player.m_localPlayer; return ((localPlayer == null) ? null : ((Humanoid)localPlayer).GetRightItem()?.m_shared.m_name) == "$item_cultivator"; } } internal static bool IsPlantOrPickable(GameObject go) { if (!Object.op_Implicit((Object)(object)go.GetComponent<Plant>())) { return Object.op_Implicit((Object)(object)go.GetComponent<Pickable>()); } return true; } internal static bool HasGrowSpace(Plant plant, Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Physics.OverlapSphere(position, plant.m_growRadius, Plant.m_spaceMask).Length == 0; } internal static bool PositionHasCollisions(Vector3 position) { //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_000c: 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) return Physics.CheckCapsule(position, position + Vector3.up * 0.1f, Mathf.Epsilon, CollisionScanner.CollisionMask); } internal static float GetPieceSpacing(GameObject go) { float num = 0f; bool flag = false; Plant component = go.GetComponent<Plant>(); if (Object.op_Implicit((Object)(object)component)) { GameObject[] grownPrefabs = component.m_grownPrefabs; List<GameObject> list = new List<GameObject>(1 + grownPrefabs.Length); list.Add(go); list.AddRange(grownPrefabs); List<GameObject> list2 = list; flag = list2.Any((GameObject x) => Object.op_Implicit((Object)(object)x.GetComponent<TreeBase>())); if (ModContext.config.MinimizeGridSpacing && !flag) { for (int num2 = 0; num2 < list2.Count; num2++) { CapsuleCollider[] componentsInChildren = list2[num2].GetComponentsInChildren<CapsuleCollider>(); foreach (CapsuleCollider val in componentsInChildren) { num = Mathf.Max(num, val.radius); } } } num += (flag ? ModContext.config.ExtraSaplingSpacing : ModContext.config.ExtraCropSpacing); } return (flag ? (component.m_growRadius * 2.2f) : ((component?.m_growRadius * (ModContext.config.MinimizeGridSpacing ? 1.1f : 2f)) ?? PickableSnapRadius(go.GetComponent<Piece>()))) + num; } internal static HashSet<Interactable> FindResourcesInRadius(GameObject rootInteractable) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) HashSet<Interactable> hashSet = new HashSet<Interactable>(); Transform root = rootInteractable.transform.root; Collider[] array = Physics.OverlapSphere(root.position, ModContext.config.HarvestRadius, CollisionScanner.CollisionMask); foreach (Collider val in array) { Pickable componentInParent = ((Component)val).GetComponentInParent<Pickable>(); Beehive val2 = (Object.op_Implicit((Object)(object)componentInParent) ? null : ((Component)val).GetComponentInParent<Beehive>()); if (Object.op_Implicit((Object)(object)componentInParent) || Object.op_Implicit((Object)(object)val2)) { Transform root2 = (Object.op_Implicit((Object)(object)componentInParent) ? ((Component)componentInParent).gameObject : ((Component)val2).gameObject).transform.root; if (!((Object)(object)root2 == (Object)(object)root) && (ModContext.config.HarvestStyle != HarvestStyle.LikeResources || !(((Object)root2).name != ((Object)root).name)) && (!Object.op_Implicit((Object)(object)val2) || val2.GetHoneyLevel() >= 1)) { Interactable val3 = (Interactable)(object)componentInParent; Interactable item = (Interactable)(((object)val3) ?? ((object)val2)); hashSet.Add(item); } } } return hashSet; } private static float PickableSnapRadius(Piece p) { if (p == null || !(p.m_harvestRadius > 0f)) { return ModContext.config.DefaultGridSpacing; } return p.m_harvestRadius; } } internal sealed class PickableDB { internal string key; internal PickableDB(string prefabName) { key = prefabName; } } internal sealed class PlacementController : MonoBehaviour { private static PlacementController _instance; private readonly List<Renderer> _disabledRenderers = new List<Renderer>(); private bool _isPlanting; internal static PlacementController Instance => _instance ?? (_instance = Initialize()); internal static bool IsPlanting => Instance._isPlanting; private static PlacementController Initialize() { //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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown GameObject val = new GameObject($"PlantEasily_PlacementController_{Guid.NewGuid()}") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)val); return val.AddComponent<PlacementController>(); } internal void OnDestroy() { if ((Object)(object)_instance == (Object)(object)this) { _instance = null; } } internal void StartBulkPlanting(GameObject piecePrefab) { ((MonoBehaviour)this).StartCoroutine(BulkPlanting(piecePrefab)); } private IEnumerator BulkPlanting(GameObject piecePrefab) { Player player = Player.m_localPlayer; _isPlanting = true; int count = 0; bool showGhostsDuringPlacement = ModContext.config.ShowGhostsDuringPlacement; foreach (GameObject extraGhost in GhostGrid.ExtraGhosts) { if (!showGhostsDuringPlacement || !GhostGrid.ValidExtraGhosts.Contains(extraGhost)) { DisableRenderers(extraGhost); } } if (showGhostsDuringPlacement) { foreach (GameObject validExtraGhost in GhostGrid.ValidExtraGhosts) { MaterialMan.instance.SetValue<Color>(validExtraGhost, ShaderProps._Color, Color.gray, false); } } foreach (GameObject validExtraGhost2 in GhostGrid.ValidExtraGhosts) { count++; PlacePiece(player, validExtraGhost2, piecePrefab); if (count % ModContext.config.BulkPlantingBatchSize == 0) { yield return null; } } GhostGrid.ValidExtraGhosts.Clear(); _isPlanting = false; player.SetupPlacementGhost(); ReEnableRenderers(); } internal static void PlacePiece(Player player, GameObject go, GameObject piecePrefab) { //IL_0008: 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_006f: 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_0074: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_0083: 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_00a7: Unknown result type (might be due to invalid IL or missing references) Transform transform = go.transform; Vector3 position = transform.position; if (ModContext.config.TryGetScatterRadius(out var radius)) { position.x += Random.Range(0f - radius, radius); position.z += Random.Range(0f - radius, radius); } Quaternion val = (ModContext.config.RandomizeRotation ? Quaternion.Euler(0f, 22.5f * (float)Random.Range(0, 16), 0f) : transform.rotation); if (ModContext.config.TryGetScatterAngle(out var angle)) { val *= Quaternion.Euler(Random.Range(0f - angle, angle), 0f, Random.Range(0f - angle, angle)); } go.SetActive(false); TerrainModifier.SetTriggerOnPlaced(true); GameObject obj = Object.Instantiate<GameObject>(piecePrefab, position, val); TerrainModifier.SetTriggerOnPlaced(false); obj.GetComponent<Piece>().SetCreator(player.GetPlayerID(), ((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID); Game.instance.IncrementPlayerStat((PlayerStatType)2, 1f, false); ((Character)player).RaiseSkill((SkillType)106, 1f); } private void DisableRenderers(GameObject go) { Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { val.enabled = false; _disabledRenderers.Add(val); } } private void ReEnableRenderers() { foreach (Renderer disabledRenderer in _disabledRenderers) { disabledRenderer.enabled = true; } _disabledRenderers.Clear(); } } internal static class PlacementPatches { [HarmonyPatch(typeof(Player), "SetupPlacementGhost")] private static class PlayerSetupPlacementGhost { private static int placementRotation; private static void Prefix(Player __instance) { if (ModContext.config.ModActive && ModUtils.HoldingCultivator) { placementRotation = __instance.m_placeRotation; } } private static void Postfix(Player __instance) { if (!PlacementController.IsPlanting) { GhostGrid.PrepareGhostPool(__instance.m_placementGhost); if (ModContext.config.ModActive && Object.op_Implicit((Object)(object)__instance.m_placementGhost) && ModUtils.HoldingCultivator && ModUtils.IsPlantOrPickable(__instance.m_placementGhost)) { __instance.m_placeRotation = placementRotation; GhostGrid.BuildGrid(__instance.m_placementGhost); } } } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] private static class PlayerUpdatePlacementGhost { private static void Prefix(Player __instance) { if (ModContext.config.ModActive && Object.op_Implicit((Object)(object)PlacementState.PlacementGhost) && (GhostGrid.GhostPlacementStatus.Count == 0 || (GhostGrid.ExtraGhosts.Count == 0 && (ModContext.config.Rows != 1 || ModContext.config.Columns != 1)))) { __instance.SetupPlacementGhost(); } } private static void Postfix(Player __instance) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (ModContext.config.ModActive && Object.op_Implicit((Object)(object)PlacementState.PlacementGhost) && !PlacementController.IsPlanting) { PlacementState.Update(((Component)__instance).transform.position); GhostGrid.Update(__instance); } } } [HarmonyPatch(typeof(Player), "TryPlacePiece")] private static class PlayerTryPlacePiece { private static readonly Dictionary<Status, string> StatusMessages = new Dictionary<Status, string> { { Status.LackResources, "$msg_missingrequirement" }, { Status.NotCultivated, "$piece_plant_notcultivated" }, { Status.WrongBiome, "$piece_plant_wrongbiome" }, { Status.NoSpace, "$piece_plant_nospace" }, { Status.NoSun, "$piece_plant_nosun" }, { Status.Invalid, "$msg_invalidplacement" }, { Status.NoAttachPiece, "$piece_plant_nowall" }, { Status.TooHot, "$piece_plant_toohot" }, { Status.TooCold, "$piece_plant_toocold" } }; private static bool Prefix(Player __instance, Piece piece, ref bool __result) { if (!ModContext.config.ModActive || !Object.op_Implicit((Object)(object)piece) || !ModUtils.HoldingCultivator || !ModUtils.IsPlantOrPickable(((Component)piece).gameObject)) { return true; } if (PlacementController.IsPlanting) { __result = false; return false; } if (ModContext.config.PreventInvalidPlanting) { Status status = GhostStatus.EvaluateStatus(__instance.m_placementGhost); if (status != Status.Healthy) { return PreventPlacement(__instance, status, ref __result); } } if (ModContext.config.PreventPartialPlanting) { foreach (Status item in GhostGrid.GhostPlacementStatus) { if (item != Status.Healthy && (item != Status.LackResources || !__instance.m_noPlacementCost)) { return PreventPlacement(__instance, item, ref __result); } } } return true; } private static bool PreventPlacement(Player player, Status status, ref bool result) { if (StatusMessages.TryGetValue(status, out var value)) { ((Character)player).Message((MessageType)2, value, 0, (Sprite)null, false); } result = false; return false; } } [HarmonyPatch(typeof(Player), "PlacePiece")] private static class PlayerPlacePiece { private static int placementRotation; private static void Prefix(Player __instance) { placementRotation = __instance.m_placeRotation; } private static void Postfix(Player __instance, PieceTable ___m_buildPieces, Piece piece) { //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_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) if (!ModContext.config.ModActive || !Object.op_Implicit((Object)(object)piece) || !ModUtils.HoldingCultivator || !ModUtils.IsPlantOrPickable(((Component)piece).gameObject)) { return; } __instance.m_placeRotation = placementRotation; if (GhostGrid.MaxActiveGhosts < 1) { return; } for (int i = 0; i < GhostGrid.MaxActiveGhosts; i++) { Status status = GhostGrid.GhostPlacementStatus[i + 1]; bool num = status == Status.Healthy; bool flag = status == Status.LackResources && __instance.m_noPlacementCost; bool flag2 = !ModContext.config.PreventInvalidPlanting && status > Status.LackResources; if (num || flag || flag2) { GhostGrid.ValidExtraGhosts.Add(GhostGrid.ExtraGhosts[i]); } } int num2 = ((!__instance.m_noPlacementCost) ? GhostGrid.ValidExtraGhosts.Count : 0); if (GhostGrid.ValidExtraGhosts.Count > 0) { PieceCategory selectedCategory = ___m_buildPieces.GetSelectedCategory(); Vector2Int selectedIndex = ___m_buildPieces.GetSelectedIndex(); GameObject gameObject = ((Component)___m_buildPieces.GetPiece(selectedCategory, selectedIndex)).gameObject; PlacementController.Instance.StartBulkPlanting(gameObject); } ItemData rightItem = ((Humanoid)__instance).GetRightItem(); for (int j = 0; j < num2; j++) { __instance.ConsumeResources(piece.m_resources, 0, -1, 1); if (ModContext.config.UseStamina) { ((Character)__instance).UseStamina(__instance.GetBuildStamina()); } if (ModContext.config.UseDurability && rightItem.m_shared.m_useDurability) { rightItem.m_durability -= __instance.GetPlaceDurability(rightItem); } } } } } internal class ReplantDB { internal static readonly Dictionary<string, ReplantDB> Registry = new Dictionary<string, ReplantDB>(); internal string PlantName { get; } internal Pickable Pickable { get; } internal ReplantDB(GameObject plantPrefab) { PlantName = ((Object)plantPrefab).name; Pickable = plantPrefab.GetComponent<Plant>().m_grownPrefabs[0].GetComponent<Pickable>(); Registry[PlantName] = this; } } internal static class CollisionScanner { internal static readonly int CollisionMask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "item" }); private static readonly Collider[] _primary = (Collider[])(object)new Collider[50]; private static readonly Collider[] _secondary = (Collider[])(object)new Collider[50]; private const int MaxRawColliders = 50; internal static IEnumerable<Transform> Scan(Vector3 origin, float spacingRadius) { //IL_0008: 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) int count = Physics.OverlapSphereNonAlloc(origin, spacingRadius, _primary, CollisionMask); for (int i = 0; i < count; i++) { yield return ((Component)_primary[i]).transform.root; } } internal static IEnumerable<Transform> ScanNeighbours(Transform primary, float expectedSpacing) { float num = Mathf.Max(expectedSpacing * 0.01f, 0.005f); float num2 = expectedSpacing - num; float num3 = expectedSpacing + num; float minSquared = num2 * num2; float maxSquared = num3 * num3; int neighbours = Physics.OverlapSphereNonAlloc(primary.position, num3, _secondary, CollisionMask); Vector3 origin = primary.position; for (int i = 0; i < neighbours; i++) { Transform root = ((Component)_secondary[i]).transform.root; if (!((Object)(object)root == (Object)(object)primary)) { Vector3 val = root.position - origin; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude >= minSquared && sqrMagnitude <= maxSquared) { yield return root; } } } } } internal sealed class GhostCache : MonoBehaviour { internal Piece piece; internal Plant plant; internal int lastUpdatedVersion = -1; public void Init() { piece = ((Component)this).GetComponent<Piece>(); plant = ((Component)this).GetComponent<Plant>(); } } internal static class GhostGrid { internal static readonly List<GameObject> ExtraGhosts = new List<GameObject>(); internal static readonly List<GameObject> ValidExtraGhosts = new List<GameObject>(); internal static readonly List<Status> GhostPlacementStatus = new List<Status>(); internal static GameObject DirectionRenderer = null; internal static List<LineRenderer> LineRenderers = new List<LineRenderer>(); private static readonly int ghostLayer = LayerMask.NameToLayer("ghost"); private static int _gridVersion; private static int _ghostUpdateIndex; private static Vector3 _lastBasePosition; private static Quaternion _lastBaseRotation; private static Quaternion _lastEffectiveRotation; private static int _lastRows; private static int _lastColumns; private static string _lastPieceName; private static bool _preservePool; internal static int MaxActiveGhosts => Mathf.Min(ModContext.config.Rows * ModContext.config.Columns - 1, ModContext.config.MaxConcurrentPlacements - 1); private static int TotalCells => 1 + MaxActiveGhosts; private static int ActualRows => (TotalCells + ModContext.config.Columns - 1) / ModContext.config.Columns; private static int ActualColumns => Mathf.Min(ModContext.config.Columns, TotalCells); internal static void ResizeGrid() { _preservePool = true; GhostPlacementStatus.Clear(); } internal static void BuildGrid(GameObject rootGhost) { GrowPoolIfNeeded(rootGhost); GhostPlacementStatus.Clear(); InitializeGhosts(rootGhost); DeactivateExcessGhosts(); } internal static void PrepareGhostPool(GameObject currentPlacementGhost) { GameObject directionRenderer = DirectionRenderer; if (directionRenderer != null) { directionRenderer.SetActive(false); } DetectPieceChange(currentPlacementGhost); if (!ShouldPreservePool()) { DestroyExtraGhosts(); } } private static void GrowPoolIfNeeded(GameObject rootGhost) { int i = ExtraGhosts.Count; string name = ((Object)rootGhost).name; for (; i < MaxActiveGhosts && i < ModContext.config.MaxConcurrentPlacements - 1; i++) { ZNetView.m_forceDisableInit = true; GameObject val = Object.Instantiate<GameObject>(rootGhost); val.AddComponent<GhostCache>().Init(); ZNetView.m_forceDisableInit = false; ((Object)val).name = name; Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(); for (int j = 0; j < componentsInChildren.Length; j++) { ((Component)componentsInChildren[j]).gameObject.layer = ghostLayer; } ExtraGhosts.Add(val); } } private static void InitializeGhosts(GameObject rootGhost) { //IL_0050: 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) Transform transform = rootGhost.transform; int num = 0; for (int i = 0; i < ModContext.config.Rows; i++) { for (int j = 0; j < ModContext.config.Columns; j++) { if (i == 0 && j == 0) { PlacementState.SetReferences(rootGhost); GhostPlacementStatus.Add(Status.Healthy); continue; } if (num >= MaxActiveGhosts) { return; } GameObject obj = ExtraGhosts[num++]; obj.SetActive(true); Transform transform2 = obj.transform; transform2.position = transform.position; transform2.localScale = transform.localScale; GhostPlacementStatus.Add(Status.Healthy); } } } private static void DeactivateExcessGhosts() { for (int i = MaxActiveGhosts; i < ExtraGhosts.Count; i++) { ExtraGhosts[i].SetActive(false); } } private static void DetectPieceChange(GameObject currentPlacementGhost) { if (Object.op_Implicit((Object)(object)currentPlacementGhost)) { string name = ((Object)currentPlacementGhost).name; if (string.IsNullOrEmpty(_lastPieceName)) { _lastPieceName = name; } else if (name == _lastPieceName) { _preservePool = true; } else { _lastPieceName = name; } } } private static bool ShouldPreservePool() { if (!_preservePool || !ModContext.config.ModActive) { return false; } _preservePool = false; return true; } private static void DestroyExtraGhosts() { foreach (GameObject extraGhost in ExtraGhosts) { Object.Destroy((Object)(object)extraGhost); } ExtraGhosts.Clear(); } internal static void Update(Player player) { UpdateVisibility(); if (ModContext.config.ShowGridDirections) { ShowGridDirections(); } if (!Object.op_Implicit((Object)(object)PlacementState.PlacementGhost)) { return; } Piece piece = PlacementState.Piece; int amount = piece.m_resources[0].m_amount; UpdateGridVersion(); UpdateGhost(player, piece, 0, 0, 0); int num = 1 + MaxActiveGhosts; int num2 = Mathf.Min(ModContext.config.GhostUpdateBatchSize, num); for (int i = 0; i < num2; i++) { int num3 = _ghostUpdateIndex % num; _ghostUpdateIndex++; int num4 = num3 / ModContext.config.Columns; int column = num3 % ModContext.config.Columns; if (num4 < ModContext.config.Rows) { UpdatePieceCost(piece, num3, amount); UpdateGhost(player, piece, num4, column, num3); } } UpdatePieceCost(piece, 0, amount); } private static void UpdatePieceCost(Piece piece, int ghostIndex, int baseCost) { piece.m_resources[0].m_amount = baseCost * (ghostIndex + 1); } private static void UpdateVisibility() { bool flag = Object.op_Implicit((Object)(object)PlacementState.PlacementGhost) && PlacementState.PlacementGhost.activeSelf; for (int i = 0; i < ExtraGhosts.Count; i++) { bool flag2 = flag && i < MaxActiveGhosts; if (ExtraGhosts[i].activeSelf != flag2) { ExtraGhosts[i].SetActive(flag2); } } } private static void ShowGridDirections() { //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_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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_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_0057: 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_007e: 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_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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_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_00e2: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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) DirectionRenderer.SetActive(PlacementState.PlacementGhost.activeSelf); Vector3 val = PlacementState.BasePosition + Vector3.up * 0.5f; LineRenderers[0].SetPositions((Vector3[])(object)new Vector3[2] { val, val + PlacementState.RowDirection * (float)(ActualRows - 1) }); LineRenderers[1].SetPositions((Vector3[])(object)new Vector3[2] { val, val + PlacementState.ColumnDirection * (float)(ActualColumns - 1) }); ((Component)LineRenderers[2]).gameObject.SetActive(ModContext.config.ShowSnapDirection); LineRenderers[2].SetPositions((Vector3[])(object)new Vector3[2] { val, val + PlacementState.SnapDirection * ((Vector3)(ref PlacementState.RowDirection)).magnitude }); } private static void UpdateGridVersion() { //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_000c: 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_002c: 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_0020: 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_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_0066: 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_006b: 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_007b: 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_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) bool flag = false; Vector3 val = PlacementState.BasePosition - _lastBasePosition; if (((Vector3)(ref val)).sqrMagnitude > 0.0001f) { _lastBasePosition = PlacementState.BasePosition; flag = true; } if (Quaternion.Angle(PlacementState.BaseRotation, _lastBaseRotation) > 1f) { _lastBaseRotation = PlacementState.BaseRotation; flag = true; } Quaternion lastEffectiveRotation = (Quaternion)(((??)PlacementState.SavedBaseRotation) ?? PlacementState.BaseRotation); if (Quaternion.Angle((Quaternion)(((??)PlacementState.SavedBaseRotation) ?? PlacementState.BaseRotation), _lastEffectiveRotation) > 0.1f) { _lastEffectiveRotation = lastEffectiveRotation; flag = true; } if (ModContext.config.Rows != _lastRows || ModContext.config.Columns != _lastColumns) { _lastRows = ModContext.config.Rows; _lastColumns = ModContext.config.Columns; flag = true; } if (flag) { _gridVersion++; } } private static void UpdateGhost(Player player, Piece piece, int row, int column, int index) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) GameObject ghostObject = GetGhostObject(index); GhostCache ghostCache = GetGhostCache(ghostObject); bool flag = ghostCache != null; if (!flag || ghostCache.lastUpdatedVersion != _gridVersion) { UpdateGhostTransform(ghostObject, GetGhostPosition(row, column, index)); UpdateGhostStatus(player, piece, ghostObject, index); if (flag) { ghostCache.lastUpdatedVersion = _gridVersion; } } } private static GameObject GetGhostObject(int index) { if (index != 0) { return ExtraGhosts[index - 1]; } return PlacementState.PlacementGhost; } private static GhostCache GetGhostCache(GameObject ghost) { if (!((Object)(object)ghost == (Object)(object)PlacementState.PlacementGhost)) { return ghost.GetComponent<GhostCache>(); } return null; } private static Vector3 GetGhostPosition(int row, int column, int index) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0003: 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_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_0020: 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_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_0043: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((index == 0) ? PlacementState.BasePosition : (PlacementState.BasePosition + PlacementState.RowDirection * (float)row + PlacementState.ColumnDirection * (float)column)); float y = default(float); Heightmap.GetHeight(val, ref y); val.y = y; return val; } private static void UpdateGhostTransform(GameObject ghost, Vector3 position) { //IL_0006: 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) ghost.transform.position = position; ghost.transform.rotation = PlacementState.BaseRotation; } private static void UpdateGhostStatus(Player player, Piece piece, GameObject ghost, int index) { //IL_009b: 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_0084: 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) Status baseStatus = ((!player.m_noPlacementCost && !player.HaveRequirements(piece, (RequirementMode)0)) ? Status.LackResources : Status.Healthy); Status status = GhostStatus.EvaluateStatus(ghost, baseStatus); ghost.GetComponent<Piece>().SetInvalidPlacementHeightlight(status != Status.Healthy); GhostPlacementStatus[index] = status; if (index == 0 && status == Status.Healthy) { if (ModContext.config.HighlightRootPlacementGhost && GhostPlacementStatus.Count > 1) { MaterialMan.instance.SetValue<Color>(ghost, ShaderProps._Color, ModContext.config.RootGhostHighlightColor, false); MaterialMan.instance.SetValue<Color>(ghost, ShaderProps._EmissionColor, ModContext.config.RootGhostHighlightColor * 0.7f, false); } player.m_placementStatus = (PlacementStatus)0; } } } internal static class GhostStatus { private static readonly Dictionary<Biome, Status> TemperatureBiomeStatus = new Dictionary<Biome, Status> { { (Biome)32, Status.TooHot }, { (Biome)64, Status.TooCold }, { (Biome)4, Status.TooCold } }; internal static Status EvaluateStatus(GameObject ghost, Status baseStatus = Status.Healthy) { //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_003a: 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_0076: 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_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_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_008c: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) Piece piece; Plant plant; if ((Object)(object)ghost == (Object)(object)PlacementState.PlacementGhost) { piece = PlacementState.Piece; plant = PlacementState.Plant; } else { GhostCache component = ghost.GetComponent<GhostCache>(); piece = component.piece; plant = component.plant; } Vector3 position = ghost.transform.position; Heightmap val = Heightmap.FindHeightmap(position); if ((Object)(object)val == (Object)null) { return Status.Invalid; } if ((plant?.m_needCultivatedGround ?? piece.m_cultivatedGroundOnly) && !val.IsCultivated(position)) { return Status.NotCultivated; } Biome val2 = plant?.m_biome ?? piece.m_onlyInBiome; Biome biome = val.GetBiome(position, 0.02f, false); if ((int)val2 != 0 && (biome & val2) == 0) { return Status.WrongBiome; } if (Object.op_Implicit((Object)(object)plant)) { if (!ModUtils.HasGrowSpace(plant, position)) { return Status.NoSpace; } if (plant.HaveRoof()) { return Status.NoSun; } if (plant.m_attachDistance > 0f && !plant.GetClosestAttachPosRot(ref plant.m_attachPos, ref plant.m_attachRot, ref plant.m_attachNormal)) { return Status.NoAttachPiece; } if (TemperatureBiomeStatus.TryGetValue(biome, out var value) && value switch { Status.TooHot => plant.m_tolerateHeat ? 1 : 0, Status.TooCold => plant.m_tolerateCold ? 1 : 0, _ => 1, } == 0 && !ShieldGenerator.IsInsideShield(position)) { return value; } } else if (ModContext.config.PreventOverlappingPlacements && ModUtils.PositionHasCollisions(position)) { return Status.NoSpace; } return baseStatus; } } internal static class PlacementState { internal static Vector3 BasePosition; internal static Vector3 RowDirection; internal static Vector3 ColumnDirection; internal static Quaternion BaseRotation; internal static Quaternion FixedRotation; internal static bool AltPlacement; internal static GameObject PlacementGhost; internal static Piece Piece; internal static Plant Plant; internal static string LastSelectedPlantName = ""; internal static Vector3 SnapDirection; internal static Vector3 SavedRowDirection; internal static Vector3 SavedColumnDirection; internal static Quaternion? SavedBaseRotation; internal static void SetReferences(GameObject rootGhost) { PlacementGhost = rootGhost; Plant = rootGhost.GetComponent<Plant>(); Piece = rootGhost.GetComponent<Piece>(); LastSelectedPlantName = null; if (!Object.op_Implicit((Object)(object)Plant)) { return; } foreach (KeyValuePair<string, ReplantDB> item in ReplantDB.Registry) { if (item.Value.PlantName == ((Object)rootGhost).name) { LastSelectedPlantName = item.Key; break; } } } internal static void Update(Vector3 playerPosition) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) UpdateAltPlacementMode(); UpdateBaseTransform(); UpdateFixedRotation(); UpdateGridDirectionsAndSnapping(playerPosition); } private static void UpdateAltPlacementMode() { if (ModContext.config.ForceAltPlacement) { AltPlacement = true; return; } if (ZInput.IsNonClassicFunctionality() && ZInput.IsGamepadActive()) { AltPlacement = Player.m_localPlayer.m_altPlace; return; } bool button = ZInput.GetButton("AltPlace"); bool flag = ZInput.GetButton("JoyAltPlace") && !ZInput.GetButton("JoyRotate"); AltPlacement = button || flag; } private static void UpdateBaseTransform() { //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_001e: 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) BasePosition = PlacementGhost.transform.position; BaseRotation = PlacementGhost.transform.rotation; } private static void UpdateFixedRotation() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_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_0038: Unknown result type (might be due to invalid IL or missing references) FixedRotation = BaseRotation; Vector3 eulerAngles = ((Quaternion)(ref FixedRotation)).eulerAngles; eulerAngles.y = Mathf.Round(eulerAngles.y / 90f) * 90f; ((Quaternion)(ref FixedRotation)).eulerAngles = eulerAngles; } private static void UpdateGridDirectionsAndSnapping(Vector3 playerPosition) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: 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) //IL_0040: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_005a: 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) float pieceSpacing = ModUtils.GetPieceSpacing(PlacementGhost); ResetGridDirections(); if (ModContext.config.SnapActive) { if (SnapSystem.FindSnapPoints(pieceSpacing)) { return; } ResetGridDirections(); } RowDirection = BaseRotation * RowDirection * pieceSpacing; ColumnDirection = BaseRotation * ColumnDirection * pieceSpacing; void ResetGridDirections() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_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) RowDirection = (ModContext.config.GloballyAlignGridDirections ? Vector3.forward : Utils.DirectionXZ(BasePosition - playerPosition)); ColumnDirection = Vector3.Cross(Vector3.up, RowDirection); } } } internal class SnapPoint { public Vector3 pos; public Vector3 rowDir; public Vector3 colDir; public Vector3 origin; public bool isCardinal; internal SnapPoint() { } internal SnapPoint(Vector3 pos, Vector3 row, Vector3 col, Vector3 origin) { //IL_0007: 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_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_0015: 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_001e: Unknown result type (might be due to invalid IL or missing references) this.pos = pos; rowDir = row; colDir = col; this.origin = origin; } } internal static class SnapPointGenerator { private const int MaxRotations = 16; private static readonly Vector3[] _positionBuffer; private static readonly SnapPoint[] _snapBuffer; static SnapPointGenerator() { _positionBuffer = (Vector3[])(object)new Vector3[16]; _snapBuffer = new SnapPoint[16]; for (int i = 0; i < 16; i++) { _snapBuffer[i] = new SnapPoint(); } } internal static bool Generate(List<SnapPoint> snapPoints, Vector3 snapFromPos, bool gridDetected) { //IL_0000: 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) int candidateCount = BuildCandidatePositions(snapFromPos, gridDetected); return ValidateCandidates(snapPoints, candidateCount, snapFromPos); } private static int BuildCandidatePositions(Vector3 snapFromPos, bool gridDetected) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_0020: 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_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_003b: 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_004b: 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_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_0067: 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_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_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) //IL_0092: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009a: 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_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_00b5: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_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_011e: 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_0120: 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_0134: 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_0136: 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_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0172: 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_0182: 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_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_01a7: 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) Vector3 rowDirection = PlacementState.RowDirection; Vector3 columnDirection = PlacementState.ColumnDirection; int result = 0; if (gridDetected) { _positionBuffer[result++] = snapFromPos + rowDirection; _positionBuffer[result++] = snapFromPos - rowDirection; _positionBuffer[result++] = snapFromPos + columnDirection; _positionBuffer[result++] = snapFromPos - columnDirection; _positionBuffer[result++] = snapFromPos + rowDirection - columnDirection; _positionBuffer[result++] = snapFromPos + rowDirection + columnDirection; _positionBuffer[result++] = snapFromPos - rowDirection - columnDirection; _positionBuffer[result++] = snapFromPos - rowDirection + columnDirection; } else if (PlacementState.AltPlacement) { _positionBuffer[result++] = snapFromPos + rowDirection; _positionBuffer[result++] = snapFromPos - rowDirection; _positionBuffer[result++] = snapFromPos + columnDirection; _positionBuffer[result++] = snapFromPos - columnDirection; } else { float num = 22.5f * ((float)Math.PI / 180f); Vector3 val = default(Vector3); for (int i = 0; i < 16; i++) { float num2 = num * (float)i; float num3 = Mathf.Sin(num2); float num4 = Mathf.Cos(num2); ((Vector3)(ref val))..ctor(rowDirection.x * num4 + rowDirection.z * num3, rowDirection.y, rowDirection.z * num4 - rowDirection.x * num3); _positionBuffer[result++] = snapFromPos + val; } } return result; } private static bool ValidateCandidates(List<SnapPoint> snapPoints, int candidateCount, Vector3 snapFromPos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_0026: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_00b7: 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_00ba: 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) Vector3 rowDirection = PlacementState.RowDirection; Vector3 columnDirection = PlacementState.ColumnDirection; int num = 0; bool flag = false; for (int i = 0; i < candidateCount; i++) { Vector3 val = _positionBuffer[i]; if (!ModUtils.PositionHasCollisions(val) && (!((Object)(object)PlacementState.Plant != (Object)null) || ModUtils.HasGrowSpace(PlacementState.Plant, val))) { Vector3 val2 = val - snapFromPos; float magnitude = ((Vector3)(ref rowDirection)).magnitude; float num2 = Mathf.Abs(Vector3.Dot(val2, ((Vector3)(ref rowDirection)).normalized)); float num3 = Mathf.Abs(Vector3.Dot(val2, ((Vector3)(ref columnDirection)).normalized)); float num4 = magnitude * 0.25f; bool flag2 = (num2 < num4 && num3 >= num4) || (num3 < num4 && num2 >= num4); InitSnapPoint(num++, val, rowDirection, columnDirection, snapFromPos, flag2); if (flag2) { flag = true; } } } if (num == 0) { return false; } for (int j = 0; j < num; j++) { SnapPoint snapPoint = _snapBuffer[j]; if (!ModContext.config.PreferCardinalSnapping || !flag || snapPoint.isCardinal) { snapPoints.Add(snapPoint); } } return snapPoints.Count > 0; } private static SnapPoint InitSnapPoint(int index, Vector3 pos, Vector3 row, Vector3 col, Vector3 origin, bool isCardinal) { //IL_0008: 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_000f: 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_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) //IL_001f: Unknown result type (might be due to invalid IL or missing references) SnapPoint obj = _snapBuffer[index]; obj.pos = pos; obj.rowDir = row; obj.colDir = col; obj.origin = origin; obj.isCardinal = isCardinal; return obj; } } internal static class SnapSystem { private const int MaxValidCollisions = 8; private static SnapPoint _lastSnap; private static bool _hasLastSnap; private static Quaternion _lastGhostRotation; internal static bool FindSnapPoints(float pieceSpacing) { //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) if (TryGridSnaps(pieceSpacing, out var snapPoints)) { ApplyGridSnap(snapPoints); return true; } if (TryFreeSnaps(pieceSpacing, out var snapPoints2)) { ApplyFreeSnap(snapPoints2); return true; } PlacementState.SnapDirection = Vector3.zero; return false; } private static void ApplyGridSnap(List<SnapPoint> availableSnapPoints) { ApplyRotationHysteresis(); (SnapPoint snap, float distance) tuple = FindNearestManhattan(availableSnapPoints); SnapPoint item = tuple.snap; float item2 = tuple.distance; item = ApplyPositionHysteresis(item, item2); CommitSnap(item); ApplyGridOrientation(item); } private static void ApplyFreeSnap(List<SnapPoint> availableSnapPoints) { SnapPoint snap = FindNearestEuclidean(availableSnapPoints); CommitSnap(snap); ApplyFreeOrientation(snap); } private static bool TryGridSnaps(float pieceSpacing, out List<SnapPoint> snapPoints) { //IL_0023: 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_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_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) snapPoints = new List<SnapPoint>(); float num = Mathf.Max(pieceSpacing * 0.01f, 0.005f); float spacingRadius = pieceSpacing + num; List<(Transform, float, List<Transform>)> list = new List<(Transform, float, List<Transform>)>(); foreach (Transform item3 in ValidPrimaryCollisions(PlacementState.BasePosition, spacingRadius)) { Vector3 val = item3.position - PlacementState.BasePosition; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; float pieceSpacing2 = ModUtils.GetPieceSpacing(((Component)item3).gameObject); List<Transform> list2 = new List<Transform>(8); foreach (Transform item4 in CollisionScanner.ScanNeighbours(item3, pieceSpacing2)) { if (ModUtils.IsPlantOrPickable(((Component)item4).gameObject)) { list2.Add(item4); } } list.Add((item3, sqrMagnitude, list2)); } list.Sort(delegate((Transform transform, float distance, List<Transform> neighbours) a, (Transform transform, float distance, List<Transform> neighbours) b) { int num3 = a.distance.CompareTo(b.distance); return (num3 != 0) ? num3 : a.neighbours.Count.CompareTo(b.neighbours.Count); }); foreach (var item5 in list) { Transform item = item5.Item1; List<Transform> item2 = item5.Item3; Transform val2 = item; int num2 = 0; foreach (Transform item6 in item2) { if (++num2 > 8) { break; } if (TryDetectGrid(val2.position, item6.position, pieceSpacing) && SnapPointGenerator.Generate(snapPoints, val2.position, gridDetected: true)) { return true; } } } return false; } private static bool TryDetectGrid(Vector3 primary, Vector3 neighbour, float pieceSpacing) { //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_000c: 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_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_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_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_003a: 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) //IL_0043: 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_004e: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Utils.DirectionXZ(neighbour - primary); if (((Vector3)(ref val)).sqrMagnitude < 1E-06f) { return false; } val = PlacementState.FixedRotation * val; PlacementState.RowDirection = val * pieceSpacing; Vector3 val2 = Vector3.Cross(Vector3.up, val); PlacementState.ColumnDirection = ((Vector3)(ref val2)).normalized * pieceSpacing; return true; } private static bool TryFreeSnaps(float pieceSpacing, out List<SnapPoint> snapPoints) { //IL_001d: 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_0046: Unknown result type (might be due to invalid IL or missing references) snapPoints = new List<SnapPoint>(); float num = Mathf.Max(pieceSpacing * 0.01f, 0.005f); float spacingRadius = pieceSpacing + num; foreach (Transform item in ValidPrimaryCollisions(PlacementState.BasePosition, spacingRadius)) { ComputeFreeDirections(item.position, pieceSpacing); if (SnapPointGenerator.Generate(snapPoints, item.position, gridDetected: false)) { return true; } } return false; } private static void ComputeFreeDirections(Vector3 target, float pieceSpacing) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_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_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) //IL_0022: 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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_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_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) Vector3 val = Utils.DirectionXZ(PlacementState.BasePosition - target); PlacementState.RowDirection = PlacementState.FixedRotation * val * pieceSpacing; if (!PlacementState.AltPlacement) { float num = Mathf.Round(Vector3.SignedAngle(Vector3.forward, val, Vector3.up) / 22.5f) * 22.5f; PlacementState.RowDirection = PlacementState.FixedRotation * Quaternion.Euler(0f, num, 0f) * Vector3.forward * pieceSpacing; } PlacementState.ColumnDirection = Vector3.Cross(Vector3.up, PlacementState.RowDirection); } private static IEnumerable<Transform> ValidPrimaryCollisions(Vector3 origin, float spacingRadius) { //IL_0008: 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) int count = 0; foreach (Transform item in CollisionScanner.Scan(origin, spacingRadius)) { if (ModUtils.IsPlantOrPickable(((Component)item).gameObject)) { int num = count + 1; count = num; if (num > 8) { yield break; } yield return item; } } } private static (SnapPoint snap, float distance) FindNearestManhattan(List<SnapPoint> snapPoints) { //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_0014: 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_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_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) SnapPoint snapPoint = snapPoints[0]; float num = ManhattanDistance(snapPoint.pos, PlacementState.BasePosition, snapPoint.rowDir, snapPoint.colDir); for (int i = 1; i < snapPoints.Count; i++) { SnapPoint snapPoint2 = snapPoints[i]; float num2 = ManhattanDistance(snapPoint2.pos, PlacementState.BasePosition, snapPoint2.rowDir, snapPoint2.colDir); if (num2 < num) { snapPoint = snapPoint2; num = num2; } } return (snap: snapPoint, distance: num); } private static SnapPoint FindNearestEuclidean(List<SnapPoint> snapPoints) { //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_0013: 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_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_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) SnapPoint snapPoint = snapPoints[0]; Vector3 val = snapPoint.pos - PlacementState.BasePosition; float num = ((Vector3)(ref val)).sqrMagnitude; for (int i = 1; i < snapPoints.Count; i++) { SnapPoint snapPoint2 = snapPoints[i]; val = snapPoint2.pos - PlacementState.BasePosition; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude < num) { snapPoint = snapPoint2; num = sqrMagnitude; } } return snapPoint; } private static float ManhattanDistance(Vector3 snapPos, Vector3 basePos, Vector3 rowDir, Vector3 colDir) { //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_0008: 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) Vector3 val = snapPos - basePos; float num = Mathf.Abs(Vector3.Dot(val, rowDir)); float num2 = Mathf.Abs(Vector3.Dot(val, colDir)); return num + num2; } private static void CommitSnap(SnapPoint snap) { //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_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_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_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) //IL_0066: 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_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_0079: 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_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_003d: Unknown result type (might be due to invalid IL or missing references) _lastSnap = snap; _hasLastSnap = true; _lastGhostRotation = PlacementState.PlacementGhost.transform.rotation; Quaternion valueOrDefault = PlacementState.SavedBaseRotation.GetValueOrDefault(); if (!PlacementState.SavedBaseRotation.HasValue) { valueOrDefault = _lastGhostRotation; PlacementState.SavedBaseRotation = valueOrDefault; } Vector3 val = (PlacementState.BasePosition = (PlacementState.PlacementGhost.transform.position = snap.pos)); val = snap.origin - snap.pos; PlacementState.SnapDirection = ((Vector3)(ref val)).normalized; } private static void ApplyRotationHysteresis() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if (_hasLastSnap && Quaternion.Angle(PlacementState.FixedRotation, _lastGhostRotation) > 1f) { _hasLastSnap = false; } Quaternion? savedBaseRotation = PlacementState.SavedBaseRotation; if (savedBaseRotation.HasValue) { Quaternion valueOrDefault = savedBaseRotation.GetValueOrDefault(); if (Quaternion.Angle(valueOrDefault, _lastGhostRotation) > 1f) { ResetSavedOrientation(); } } } private static SnapPoint ApplyPositionHysteresis(SnapPoint nearestSnap, float nearestGridDistance) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_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_0032: 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 (_hasLastSnap && _lastSnap.origin == nearestSnap.origin) { float num = ManhattanDistance(_lastSnap.pos, PlacementState.BasePosition, _lastSnap.rowDir, _lastSnap.colDir); if (nearestGridDistance > num - 0.0025000002f) { return _lastSnap; } } return nearestSnap; } private static void ApplyGridOrientation(SnapPoint snap) { //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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to inv