Decompiled source of ImpactfulSkills v0.10.0

plugins/ImpactfulSkills.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using ImpactfulSkills.common;
using ImpactfulSkills.compatibility;
using ImpactfulSkills.modules.Multiplant;
using ImpactfulSkills.patches;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using SimpleJson;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ImpactfulSkills")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ImpactfulSkills")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.10.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.10.0.0")]
namespace ImpactfulSkills
{
	internal class ValConfig
	{
		public static ConfigFile cfg;

		public static ConfigEntry<bool> EnableDebugMode;

		public const string cfgFolder = "ImpactfulSkills";

		public static bool AOEFeaturesEnabled = true;

		public static ConfigEntry<KeyboardShortcut> AOEToggleHotkey;

		public static ConfigEntry<bool> EnableWoodcutting;

		public static ConfigEntry<float> WoodCuttingDmgMod;

		public static ConfigEntry<float> WoodCuttingLootFactor;

		public static ConfigEntry<bool> EnableMining;

		public static ConfigEntry<float> MiningDmgMod;

		public static ConfigEntry<float> MiningLootFactor;

		public static ConfigEntry<float> MiningAOERange;

		public static ConfigEntry<float> MiningAOELevel;

		public static ConfigEntry<bool> EnableMiningAOE;

		public static ConfigEntry<bool> EnableMiningRockBreaker;

		public static ConfigEntry<float> RockBreakerMaxChance;

		public static ConfigEntry<int> RockBreakerRequiredLevel;

		public static ConfigEntry<float> RockBreakerDamage;

		public static ConfigEntry<int> MinehitsPerInterval;

		public static ConfigEntry<float> ChanceForAOEOnHit;

		public static ConfigEntry<bool> SkillLevelBonusEnabledForMiningDropChance;

		public static ConfigEntry<bool> ChanceForAOEOnHitScalesWithSkill;

		public static ConfigEntry<bool> EnableMiningCritHit;

		public static ConfigEntry<int> RequiredLevelForMiningCrit;

		public static ConfigEntry<float> ChanceForMiningCritHit;

		public static ConfigEntry<float> CriticalHitDmgMult;

		public static ConfigEntry<bool> SkipNonRockDropIncreases;

		public static ConfigEntry<bool> ReducedChanceDropsForLowAmountDrops;

		public static ConfigEntry<float> DistanceMiningDropMultiplierChecks;

		public static ConfigEntry<float> RockbreakerSafetyResetTimeout;

		public static ConfigEntry<string> SkipNonRockDropPrefabs;

		public static ConfigEntry<bool> FractionalDropsAsChance;

		public static ConfigEntry<bool> EnableStealth;

		public static ConfigEntry<float> SneakSpeedFactor;

		public static ConfigEntry<float> SneakNoiseReductionLevel;

		public static ConfigEntry<float> SneakNoiseReductionFactor;

		public static ConfigEntry<bool> EnableSneakBonusDamage;

		public static ConfigEntry<int> SneakBackstabBonusLevel;

		public static ConfigEntry<float> SneakBackstabBonusFactor;

		public static ConfigEntry<bool> EnableRun;

		public static ConfigEntry<float> RunSpeedFactor;

		public static ConfigEntry<bool> EnableJump;

		public static ConfigEntry<float> JumpHeightFactor;

		public static ConfigEntry<float> JumpHeightRequiredLevel;

		public static ConfigEntry<bool> EnableFallDamageReduction;

		public static ConfigEntry<float> FallDamageReductionFactor;

		public static ConfigEntry<float> FallDamageReductionRequiredLevel;

		public static ConfigEntry<float> FallDamageHeightBonus;

		public static ConfigEntry<float> FallDamageHeightRequiredLevel;

		public static ConfigEntry<bool> EnableFallDamageHeightBonus;

		public static ConfigEntry<bool> EnableAnimalWhisper;

		public static ConfigEntry<float> AnimalTamingSpeedFactor;

		public static ConfigEntry<float> TamedAnimalLootIncreaseFactor;

		public static ConfigEntry<int> BetterBeesLevel;

		public static ConfigEntry<bool> EnableBeeBonuses;

		public static ConfigEntry<int> BeeBiomeUnrestrictedLevel;

		public static ConfigEntry<bool> EnableBeeBiomeUnrestricted;

		public static ConfigEntry<float> BeeHoneyOutputIncreaseBySkill;

		public static ConfigEntry<float> BeeHarvestXP;

		public static ConfigEntry<float> AnimalBreedingXP;

		public static ConfigEntry<float> AnimalBreedingXPRange;

		public static ConfigEntry<bool> EnableGathering;

		public static ConfigEntry<bool> EnableGatheringAOE;

		public static ConfigEntry<float> GatheringLuckFactor;

		public static ConfigEntry<float> GatheringRangeFactor;

		public static ConfigEntry<int> FarmingRangeRequiredLevel;

		public static ConfigEntry<string> GatheringLuckLevels;

		public static ConfigEntry<string> GatheringDisallowedItems;

		public static ConfigEntry<bool> EnableFarmingMultiPlant;

		public static ConfigEntry<int> FarmingMultiplantRequiredLevel;

		public static ConfigEntry<int> FarmingMultiplantMaxPlantedAtOnce;

		public static ConfigEntry<int> FarmingMultiplantColumnCount;

		public static ConfigEntry<bool> FarmingMultiPlantSnapToExisting;

		public static ConfigEntry<float> FarmingMultiPlantBufferSpace;

		public static ConfigEntry<float> PlantingCostStaminaReduction;

		public static ConfigEntry<float> PlantingSnapDistance;

		public static ConfigEntry<float> PlantingAOEHarvestResetSafety;

		public static ConfigEntry<bool> PreferOtherPlantGrid;

		public static ConfigEntry<string> FarmingSnapStyle;

		public static ConfigEntry<bool> FarmingSnapPreferCardinal;

		public static ConfigEntry<bool> EnableSnappingToOtherPlants;

		public static ConfigEntry<float> FarmingMultiPlantDistanceBufferModifier;

		public static ConfigEntry<bool> FarmingMultiPlantPersistOrientation;

		public static ConfigEntry<bool> EnableVoyager;

		public static ConfigEntry<int> VoyagerSkillXPCheckFrequency;

		public static ConfigEntry<float> VoyagerReduceCuttingStart;

		public static ConfigEntry<float> VoyagerSailingSpeedFactor;

		public static ConfigEntry<float> VoyagerIncreaseExplorationRadius;

		public static ConfigEntry<float> VoyagerPaddleSpeedBonus;

		public static ConfigEntry<float> VoyagerPaddleSpeedBonusLevel;

		public static ConfigEntry<bool> EnableBoatDamageReduction;

		public static ConfigEntry<int> BoatDamageReductionLevel;

		public static ConfigEntry<float> VoyagerDamageReductionAmount;

		public static ConfigEntry<bool> VoyagerImpactResistance;

		public static ConfigEntry<int> VoyagerImpactResistanceLevel;

		public static ConfigEntry<bool> EnableFriendsRowSpeedBonus;

		public static ConfigEntry<float> MaxFriendsRowSpeedBonus;

		public static ConfigEntry<bool> EnableWeaponSkill;

		public static ConfigEntry<float> WeaponSkillStaminaReduction;

		public static ConfigEntry<float> WeaponSkillBowDrawStaminaCostReduction;

		public static ConfigEntry<float> WeaponSkillParryBonus;

		public static ConfigEntry<float> WeaponSkillEquipSpeedFactor;

		public static ConfigEntry<int> WeaponSkillEquipRequiredLevel;

		public static ConfigEntry<bool> EnableCooking;

		public static ConfigEntry<bool> EnableCookingBonusItems;

		public static ConfigEntry<float> ChanceForCookingBonusItems;

		public static ConfigEntry<int> RequiredLevelForBonusCookingItems;

		public static ConfigEntry<int> CookingBonusItemMaxAmount;

		public static ConfigEntry<float> CookingBurnReduction;

		public static ConfigEntry<bool> EnableHauling;

		public static ConfigEntry<bool> EnableCarryWeightBonus;

		public static ConfigEntry<float> HaulingMaxWeightBonus;

		public static ConfigEntry<bool> EnableHaulingCartMassReduction;

		public static ConfigEntry<float> HaulingCartMassReduction;

		public static ConfigEntry<float> HaulingXPRate;

		public static ConfigEntry<int> HaulingXPCheckInterval;

		public static ConfigEntry<float> HaulingXPMinDistance;

		public static ConfigEntry<bool> EnableHaulingCarryWeightXP;

		public static ConfigEntry<float> HaulingCarryWeightXPMinWeight;

		public static ConfigEntry<float> HaulingCarryWeightXPRate;

		public static ConfigEntry<float> HaulingMaxLoadRatio;

		public static ConfigEntry<bool> EnableBloodMagic;

		public static ConfigEntry<float> BloodMagicXPForShieldDamageRatio;

		public static ConfigEntry<float> BloodMagicXP;

		public static ConfigEntry<bool> EnableKnowledgeSharing;

		public static ConfigEntry<float> AnimalTamingSkillGainRate;

		public static ConfigEntry<float> VoyagerSkillGainRate;

		public static ConfigEntry<float> SharedKnowledgeSkillBonusRate;

		public static ConfigEntry<float> SharedKnowledgeCap;

		public static ConfigEntry<string> SharedKnowledgeIgnoreList;

		public static ConfigEntry<bool> EnableCrafting;

		public static ConfigEntry<bool> EnableDurabilitySaves;

		public static ConfigEntry<bool> ScaleDurabilitySaveBySkillLevel;

		public static ConfigEntry<bool> EnableDurabilityLossPrevention;

		public static ConfigEntry<int> DurabilitySaveLevel;

		public static ConfigEntry<float> ChanceForDurabilityLossPrevention;

		public static ConfigEntry<int> CraftingMaxBonus;

		public static ConfigEntry<float> CraftingBonusChance;

		public static ConfigEntry<bool> EnableBonusItemCrafting;

		public static ConfigEntry<bool> EnableCraftBonusAsFraction;

		public static ConfigEntry<float> CraftBonusFractionOfCraftNumber;

		public static ConfigEntry<int> CraftingBonusCraftsLevel;

		public static ConfigEntry<bool> EnableMaterialReturns;

		public static ConfigEntry<int> CraftingMaterialReturnsLevel;

		public static ConfigEntry<float> MaxCraftingMaterialReturnPercent;

		public static ConfigEntry<float> ChanceForMaterialReturn;

		public static ConfigEntry<bool> EnableSwimming;

		public static ConfigEntry<int> SwimSpeedRequiredLevel;

		public static ConfigEntry<float> SwimmingSpeedFactor;

		public static ConfigEntry<bool> EnableSwimStaminaCostReduction;

		public static ConfigEntry<int> SwimStaminaReductionLevel;

		public static ConfigEntry<float> SwimStaminaCostReductionFactor;

		public static ConfigEntry<bool> EnableBlocking;

		public static ConfigEntry<int> BlockPowerRequiredLevel;

		public static ConfigEntry<float> BlockPowerFactor;

		public static ConfigEntry<int> BlockStaminaGainRequiredLevel;

		public static ConfigEntry<float> BlockStaminaGainFactor;

		public static ConfigEntry<bool> EnableParryStaminaGain;

		internal static CustomRPC SkillIncreaseXP;

		public ValConfig(ConfigFile cf)
		{
			//IL_0043: 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_0059: Expected O, but got Unknown
			//IL_0059: Expected O, but got Unknown
			cfg = cf;
			cfg.SaveOnConfigSet = true;
			CreateConfigValues(cf);
			Logger.setDebugLogging(EnableDebugMode.Value);
			SetupMainFileWatcher();
			SkillIncreaseXP = NetworkManager.Instance.AddRPC("ISKILL_XP_GRANT", new CoroutineHandler(OnServerReceiveXPRequest), new CoroutineHandler(OnClientReceiveXPGrant));
		}

		private void CreateConfigValues(ConfigFile Config)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			EnableDebugMode = Config.Bind<bool>("Client config", "EnableDebugMode", false, new ConfigDescription("Enables Debug logging.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			} }));
			EnableDebugMode.SettingChanged += Logger.enableDebugLogging;
			AOEToggleHotkey = BindClientConfig("Client config", "AOEToggleHotkey", new KeyboardShortcut((KeyCode)110, Array.Empty<KeyCode>()), "Hotkey to toggle AOE harvesting and AOE planting on/off.");
			EnableWoodcutting = BindServerConfig("Woodcutting", "EnableWoodcutting", value: true, "Enable woodcutting skill changes.");
			WoodCuttingDmgMod = BindServerConfig("Woodcutting", "WoodCuttingDmgMod", 1.2f, "How much skill levels impact your chop damage.");
			WoodCuttingLootFactor = BindServerConfig("Woodcutting", "WoodCuttingLootFactor", 3f, "How much the woodcutting skill provides additional loot. 1 is vanilla (no bonus), 2 is 2x the loot at level 100.", advanced: false, 1f, 10f);
			EnableMining = BindServerConfig("Mining", "EnableMining", value: true, "Enable mining skill changes.");
			MiningDmgMod = BindServerConfig("Mining", "MiningDmgMod", 1.2f, "How much your skill levels impact mining damage.");
			EnableMiningCritHit = BindServerConfig("Mining", "EnableMiningCritHit", value: true, "Enables mining critial hit strikes, must hit the required level for it to be active.");
			RequiredLevelForMiningCrit = BindServerConfig("Mining", "RequiredLevelForMiningCrit", 25, "Level the player must be for critical mining hits to activate", advanced: false, 0, 100);
			ChanceForMiningCritHit = BindServerConfig("Mining", "ChanceForMiningCritHit", 0.1f, "Chance for a critical hit when mining", advanced: false, 0f, 1f);
			CriticalHitDmgMult = BindServerConfig("Mining", "CriticalHitDmgMult", 3f, "Multipler for damage from a critical hit", advanced: false, 1f, 20f);
			MiningLootFactor = BindServerConfig("Mining", "MiningLootFactor", 2f, "How much the mining skill provides additional loot. 1 is vanilla (no bonus), 2 is 2x the loot at level 100.", advanced: false, 1f, 10f);
			EnableMiningAOE = BindServerConfig("Mining", "EnableMiningAOE", value: true, "Enable AOE mining skill changes.");
			ChanceForAOEOnHit = BindServerConfig("Mining", "ChanceForAOEOnHit", 0.3f, "Once AOE Mining is enabled, this is the chance for it to activate on any hit", advanced: false, 0f, 1f);
			ChanceForAOEOnHitScalesWithSkill = BindServerConfig("Mining", "ChanceForAOEOnHitScalesWithSkill", value: true, "Increases your chance for an AOE strike based on player skill");
			MiningAOERange = BindServerConfig("Mining", "MiningAOERange", 2f, "How far away the mining AOE is applied. How far away an AOE hit is applied.", advanced: false, 0.5f, 10f);
			MiningAOELevel = BindServerConfig("Mining", "MiningAOELevel", 50f, "The level that AOE mining requires to activate. What skill level Mining AOE is enabled at.", advanced: false, 0f, 100f);
			EnableMiningRockBreaker = BindServerConfig("Mining", "EnableMiningRockBreaker", value: true, "Enable mining whole veins, by a (small) chance.");
			RockBreakerMaxChance = BindServerConfig("Mining", "RockBreakerMaxChance", 0.05f, "The maximum chance to break a whole vein. 0.05 is 5% chance to break a whole vein at level 100. This is checked on each hit.", advanced: false, 0f, 1f);
			RockBreakerRequiredLevel = BindServerConfig("Mining", "RockBreakerRequiredLevel", 75, "The level that vein breaking requires to activate. What skill level whole rocks breaking is enabled at.", advanced: false, 0, 100);
			RockBreakerDamage = BindServerConfig("Mining", "RockBreakerDamage", 300f, "Veinbreakers damage, small damage numbers will mean triggering this will not destroy a whole vein, but massively weaken it. Large numbers will ensure the whole vein is destroyed.", advanced: false, 0f, 10000f);
			MinehitsPerInterval = BindServerConfig("Mining", "MinehitsPerInterval", 2, "The number of pieces per interval to break when mining large rocks.", advanced: true, 1, 100);
			SkillLevelBonusEnabledForMiningDropChance = BindServerConfig("Mining", "SkillLevelBonusEnabledForMiningDropChance", value: false, "Pickaxes skill level provides a bonus to drop chance for drops that are not gaurenteed (This can significantly increase muddy scrap-pile drops).");
			SkipNonRockDropIncreases = BindServerConfig("Mining", "SkipNonRockDropIncreases", value: true, "When enabled, only ores/rocks will get the increased drops, this primarily impacts muddy scrap piles in vanilla.");
			SkipNonRockDropPrefabs = BindServerConfig("Mining", "SkipNonRockDropPrefabs", "LeatherScraps,WitheredBone", "List of prefabs which will not recieve increased mining drops. Should be comma seperated without spaces.");
			ReducedChanceDropsForLowAmountDrops = BindServerConfig("Mining", "ReducedChanceDropsForLowAmountDrops", value: false, "When Enabled, drops that have an amount increase below 1 will only have a chance to happen instead of being rounded up to 1, and always happening.");
			FractionalDropsAsChance = BindServerConfig("Mining", "FractionalDropsAsChance", value: true, "When enabled, drops that are less than 1 become a chance to drop one. When disabled drops below 1 will never result in drops.");
			DistanceMiningDropMultiplierChecks = BindServerConfig("Mining", "DistanceMiningDropMultiplierChecks", 20f, "How far away the loot multiplier will check when rocks are destroyed. Increasing this significantly can cause a performance impact.", advanced: true, 10f, 100f);
			RockbreakerSafetyResetTimeout = BindServerConfig("Mining", "RockbreakerSafetyResetTimeout", 30f, "How long to wait before re-enabling rock breaker after its last activation.", advanced: true, 10f, 120f);
			EnableRun = BindServerConfig("Run", "EnableRun", value: true, "Enable run skill changes.");
			RunSpeedFactor = BindServerConfig("Run", "RunSpeedFactor", 0.005f, "How much the run speed is increased based on your run level. Amount applied per level, 0.005 will make level 100 run give 50% faster running.", advanced: false, 0.001f, 0.06f);
			EnableJump = BindServerConfig("Jump", "EnableJump", value: true, "Enable jump skill changes.");
			JumpHeightFactor = BindServerConfig("Jump", "JumpHeightFactor", 125f, "Percentage of original jump height at skill level 100. 100 = no change, 50 = half height, 200 = double height.", advanced: false, 50f, 300f);
			JumpHeightRequiredLevel = BindServerConfig("Jump", "JumpHeightRequiredLevel", 10f, "Minimum jump skill level required to gain jump height bonuses.", advanced: false, 0f, 100f);
			EnableFallDamageReduction = BindServerConfig("Jump", "EnableFallDamageReduction", value: true, "Enable fall damage reduction based on jump skill.");
			FallDamageReductionFactor = BindServerConfig("Jump", "FallDamageReductionFactor", 0.5f, "How much fall damage is reduced at skill level 100. 0.5 means 50% reduction at max level.", advanced: false, 0f, 1f);
			FallDamageReductionRequiredLevel = BindServerConfig("Jump", "FallDamageReductionRequiredLevel", 15f, "Minimum jump skill level required to gain fall damage reduction.", advanced: false, 0f, 100f);
			EnableFallDamageHeightBonus = BindServerConfig("Jump", "EnableFallDamageHeightBonus", value: true, "Enables Jump skill impacting the distance you can fall without recieving any fall damage.");
			FallDamageHeightRequiredLevel = BindServerConfig("Jump", "FallDamageHeightRequiredLevel", 25f, "The required level to start getting an increase to the height at which you will not recieve any fall damage.", advanced: false, 0f, 100f);
			FallDamageHeightBonus = BindServerConfig("Jump", "FallDamageHeightBonus", 3f, "Bonus to max fall height before taking damage at skill level 100 (meters). Scales with skill level (default is 4, and this is added to that).", advanced: false, 0f, 50f);
			EnableCooking = BindServerConfig("Cooking", "EnableCooking", value: true, "Enable cooking skill changes.");
			CookingBurnReduction = BindServerConfig("Cooking", "CookingBurnReduction", 0.5f, "How much offset is applied to diminishing returns for food, scaled by the players cooking skill. At 1 and cooking 100 food never degrades.", advanced: false, 0.1f, 1f);
			EnableHauling = BindServerConfig("Hauling", "EnableHauling", value: true, "Enables the hauling skill.");
			EnableCarryWeightBonus = BindServerConfig("Hauling", "EnableCarryWeightBonus", value: true, "Enables the carry weight bonus from the hauling skill.");
			HaulingMaxWeightBonus = BindServerConfig("Hauling", "HaulingMaxWeightBonus", 50f, "The maximum carry weight bonus from the hauling skill (the value you get at skill level 100).", advanced: false, 0f, 300f);
			EnableHaulingCartMassReduction = BindServerConfig("Hauling", "EnableHaulingCartMassReduction", value: true, "Enables mass reduction for the cart (this makes the cart easier to move when heavily loaded).");
			HaulingCartMassReduction = BindServerConfig("Hauling", "HaulingCartMassReduction", 0.8f, "The maximum reduction that a carts weight will recieve based on your hauling skill.", advanced: false, 0.01f, 1f);
			HaulingXPRate = BindServerConfig("Hauling", "HaulingXPRate", 0.2f, "The amount of XP that is gained each time with Hauling", advanced: false, 0.01f, 10f);
			HaulingXPCheckInterval = BindServerConfig("Hauling", "HaulingXPCheckInterval", 3, "How many seconds between checks for hauling XP while moving goods, both by cart and by carrying them.", advanced: false, 1, 60);
			HaulingXPCheckInterval.SettingChanged += HaulingXPTracker.OnIntervalChanged;
			HaulingXPMinDistance = BindServerConfig("Hauling", "HaulingXPMinDistance", 1f, "How far you must travel within the check interval to gain hauling XP. Set to 0 to gain hauling XP without moving.", advanced: false, 0f, 50f);
			EnableHaulingCarryWeightXP = BindServerConfig("Hauling", "EnableHaulingCarryWeightXP", value: true, "Enables gaining hauling XP while moving around with a heavily loaded inventory.");
			HaulingCarryWeightXPMinWeight = BindServerConfig("Hauling", "HaulingCarryWeightXPMinWeight", 275f, "The minimum total inventory weight you must be carrying to gain hauling XP from your load.", advanced: false, 0f, 2000f);
			HaulingCarryWeightXPRate = BindServerConfig("Hauling", "HaulingCarryWeightXPRate", 3f, "The amount of XP that is gained each interval while heavily loaded. This is scaled by how loaded you are.", advanced: false, 0.01f, 10f);
			HaulingMaxLoadRatio = BindServerConfig("Hauling", "HaulingMaxLoadRatio", 1.5f, "The maximum load ratio that hauling XP will scale with. Being over your carry weight grants bonus XP, this caps how much.", advanced: true, 1f, 5f);
			EnableBloodMagic = BindServerConfig("BloodMagic", "EnableBloodMagic", value: true, "Enable blood magic skill changes.");
			BloodMagicXPForShieldDamageRatio = BindServerConfig("BloodMagic", "BloodMagicXPForShieldDamageRatio", 50f, "How much XP is gained for shield damage. 50 is once every 50 damage.", advanced: false, 1f, 200f);
			BloodMagicXP = BindServerConfig("BloodMagic", "BloodMagicXP", 1f, "How much XP is gained, used by other blood magic skill settings.", advanced: false, 0.1f, 10f);
			EnableStealth = BindServerConfig("Sneak", "EnableStealth", value: true, "Enable sneak skill changes.");
			SneakSpeedFactor = BindServerConfig("Sneak", "SneakSpeedFactor", 0.03f, "How much sneak speed is increased based on your sneak level. Amount applied per level, 0.03 will make level 100 sneak give normal walkspeed while sneaking.", advanced: false, 0.001f, 0.06f);
			SneakNoiseReductionLevel = BindServerConfig("Sneak", "SneakNoiseReductionLevel", 50f, "The level at which noise reduction starts being applied based on your skill", advanced: false, 0f, 100f);
			SneakNoiseReductionFactor = BindServerConfig("Sneak", "SneakNoiseReductionFactor", 0.5f, "How much noise is reduced based on your sneak level. Amount applied per level, 0.5 will make level 100 sneak give 50% less noise.", advanced: false, 0.1f, 1f);
			EnableSneakBonusDamage = BindServerConfig("Sneak", "EnableSneakBonusDamage", value: true, "Enable sneak bonus damage changes.");
			SneakBackstabBonusLevel = BindServerConfig("Sneak", "SneakBackstabBonusLevel", 25, "The level at which backstab damage starts being applied based on your skill", advanced: false, 0, 100);
			SneakBackstabBonusFactor = BindServerConfig("Sneak", "SneakBackstabBonusFactor", 2f, "How much backstab damage is increased based on your sneak level. 1 is a 100% bonus backstab damage at skill level 100.", advanced: false, 0.1f, 10f);
			EnableAnimalWhisper = BindServerConfig("AnimalHandling", "EnableAnimalWhisper", value: true, "Enable animal handling skill changes.");
			AnimalTamingSpeedFactor = BindServerConfig("AnimalHandling", "AnimalTamingSpeedFactor", 6f, "How much your animal handling skill impacts taming speed. 6 is 6x taming speed at level 100 (5 minutes vs 30 minutes default)", advanced: false, 1f, 10f);
			TamedAnimalLootIncreaseFactor = BindServerConfig("AnimalHandling", "TamedAnimalLootIncreaseFactor", 3f, "How much the animal handling skill improves your loot from tamed creatures. 1 is vanilla (no bonus), 3 is 3x the loot at level 100", advanced: false, 1f, 10f);
			EnableBeeBonuses = BindServerConfig("AnimalHandling", "EnableBeeBonuses", value: true, "Enables Animal Handling bonuses related to Bees.");
			BetterBeesLevel = BindServerConfig("AnimalHandling", "BetterBeesLevel", 15, "The level at which Bee productivity traits kick in", advanced: false, 0, 100);
			BeeHoneyOutputIncreaseBySkill = BindServerConfig("AnimalHandling", "BeeHoneyOutputIncreaseBySkill", 1f, "At level 100 skill, and 1.0 this results in a 100% increase in honey gathered.");
			EnableBeeBiomeUnrestricted = BindServerConfig("AnimalHandling", "EnableBeeBiomeUnrestricted", value: true, "At the specified level, beeshives built by you can produce honey in any biome.");
			BeeBiomeUnrestrictedLevel = BindServerConfig("AnimalHandling", "BeeBiomeUnrestrictedLevel", 25, "At this level, if enabled, beehives built by you can produce honey in any biome.", advanced: false, 0, 100);
			BeeHarvestXP = BindServerConfig("AnimalHandling", "BeeHarvestXP", 2f, "The amount of xp for Animal handling provided by harvesting a single honey from a beehive", advanced: false, 0f, 20f);
			AnimalBreedingXP = BindServerConfig("AnimalHandling", "AnimalBreedingXP", 5f, "AnimalHandling XP granted to each nearby player when a tamed animal becomes pregnant or gives birth.", advanced: false, 0f, 50f);
			AnimalBreedingXPRange = BindServerConfig("AnimalHandling", "AnimalBreedingXPRange", 30f, "How close a player must be to a breeding animal to gain the breeding XP.", advanced: false, 1f, 100f);
			EnableGathering = BindServerConfig("Farming", "EnableGathering", value: true, "Enable gathering skill changes.");
			GatheringLuckFactor = BindServerConfig("Farming", "GatheringLuckFactor", 0.5f, "How much luck impacts gathering. Each level gives you a small chance to get better loot.", advanced: false, 0.1f, 5f);
			EnableGatheringAOE = BindServerConfig("Farming", "EnableGatheringAOE", value: true, "Enable AOE gathering skill changes.");
			GatheringRangeFactor = BindServerConfig("Farming", "GatheringRangeFactor", 5f, "AOE gathering range you have at level 100.", advanced: false, 3f, 25f);
			FarmingRangeRequiredLevel = BindServerConfig("Farming", "GatheringRangeRequiredLevel", 50, "The level that AOE gathering requires to activate.", advanced: false, 0, 100);
			GatheringLuckLevels = BindServerConfig("Farming", "GatheringLuckLevels", "30,50,70,90,100", "Higher values have a lower chance of dropping. Each comma seperated number entry (0-100) is a chance at an additional drop.");
			GatheringDisallowedItems = BindServerConfig("Farming", "GatheringDisallowedItems", "SurtlingCore,Flint,Wood,Branch,Stone,Amber,AmberPearl,Coins,Ruby,CryptRemains,Obsidian,Crystal,Pot_Shard,DragonEgg,DvergrLantern,DvergrMineTreasure,SulfurRock,VoltureEgg,Swordpiece,MoltenCore,Hairstrands,Tar,BlackCore", "Items which can be picked, but do not get a luck roll for multiple loot and will not be auto-picked.");
			EnableFarmingMultiPlant = BindServerConfig("Farming", "EnableFarmingMultiPlant", value: true, "Enables farming multi-planting");
			FarmingMultiplantRequiredLevel = BindServerConfig("Farming", "FarmingMultiplantRequiredLevel", 25, "The level that Multiplant is enabled.", advanced: false, 0, 100);
			FarmingMultiplantMaxPlantedAtOnce = BindServerConfig("Farming", "FarmingMultiplantMaxPlantedAtOnce", 12, "The total number of plants that can be planted at once at maximum gathering.");
			FarmingMultiplantColumnCount = BindServerConfig("Farming", "FarmingMultiplantColumnCount", 4, "Maximum number of columns in the planting grid. The grid will form the closest square shape possible without exceeding this limit.", advanced: true, 1, 12);
			FarmingMultiPlantSnapToExisting = BindServerConfig("Farming", "FarmingMultiPlantSnapToExisting", value: true, "Automatically align new grid to nearby existing plants");
			FarmingMultiPlantDistanceBufferModifier = BindServerConfig("Farming", "FarmingMultiPlantDistanceBufferModifier", 1.1f, "The increased distance that is applied to all plants requirements to ensure that they do not become unhealthy.");
			FarmingMultiPlantBufferSpace = BindServerConfig("Farming", "FarmingMultiPlantBufferSpace", 0.2f, "Additional space for all multiplanted plants to ensure they are healthy.", advanced: true, 0f, 5f);
			PlantingCostStaminaReduction = BindServerConfig("Farming", "PlantingCostStaminaReduction", 0.5f, "At max level, the percentage reduction in stamina cost when placing.", advanced: true, 0f, 1f);
			PlantingSnapDistance = BindServerConfig("Farming", "PlantingSnapDistance", 1f, "The distance that is checked for other plants to attempt to snap to.", advanced: true, 0f, 10f);
			PlantingAOEHarvestResetSafety = BindServerConfig("Farming", "PlantingAOEHarvestResetSafety", 10f, "The number of seconds after an AOE harvest that harvesting will be re-enabled, even if it failed to reset.");
			FarmingSnapStyle = BindServerConfig("Farming", "FarmingSnapStyle", "Grid", "'Grid' detects the existing grid pattern and aligns to it; 'Legacy' snaps to the nearest plant position only.", new AcceptableValueList<string>(new string[2] { "Grid", "Legacy" }), advanced: true);
			FarmingSnapPreferCardinal = BindServerConfig("Farming", "FarmingSnapPreferCardinal", value: true, "Legacy snap style only: prefer axis-aligned (N/S/E/W) snap candidates over diagonal ones. Grid style is always lattice-aligned and ignores this.", null, advanced: true);
			EnableSnappingToOtherPlants = BindServerConfig("Farming", "EnableSnappingToOtherPlants", value: true, "When enabled, allows plant grid snapping to plants which are not the same kind as the currently planting one");
			FarmingMultiPlantPersistOrientation = BindServerConfig("Farming", "FarmingMultiPlantPersistOrientation", value: true, "After planting, keep the same grid orientation for the next planting instead of resetting to the direction you're facing. Rotate (scroll) to change it.");
			EnableVoyager = BindServerConfig("Voyager", "EnableVoyager", value: true, "Enable voyager skill changes.");
			VoyagerSkillXPCheckFrequency = BindServerConfig("Voyager", "VoyagerSkillXPCheckFrequency", 5, "How often Voyager skill can be increased while sailing. Rate varies based on your game physics engine speed.", advanced: false, 5, 200);
			VoyagerReduceCuttingStart = BindServerConfig("Voyager", "VoyagerReduceCuttingStart", 50f, "The level that the player starts to reduce the penalty of not having the wind at your back.", advanced: false, 0f, 100f);
			VoyagerSailingSpeedFactor = BindServerConfig("Voyager", "VoyagerSailingSpeedFactor", 1.5f, "How much the sailing speed is increased based on your voyager level. Amount applied per level, 2 will make level 100 voyager give 100% faster sailing.", advanced: false, 1f, 20f);
			VoyagerIncreaseExplorationRadius = BindServerConfig("Voyager", "VoyagerIncreaseExplorationRadius", 3f, "How much the exploration radius is increased based on your voyager level. Amount applied per level, 1 will make level 100 voyager give 100% more exploration radius.", advanced: false, 0f, 20f);
			VoyagerPaddleSpeedBonus = BindServerConfig("Voyager", "VoyagerPaddleSpeedBonus", 2f, "How much the paddle speed is increased based on your voyager level. 1 is a 100% bonus at level 100", advanced: false, 0.01f, 5f);
			VoyagerPaddleSpeedBonusLevel = BindServerConfig("Voyager", "VoyagerPaddleSpeedBonusLevel", 25f, "The level that the player starts to get a bonus to paddle speed.", advanced: false, 0f, 100f);
			EnableFriendsRowSpeedBonus = BindServerConfig("Voyager", "EnableFriendsRowSpeedBonus", value: true, "Whether or not friends attached to the ship will provide a 'rowing' speed bonus.");
			MaxFriendsRowSpeedBonus = BindServerConfig("Voyager", "MaxFriendsRowSpeedBonus", 0.25f, "The maximum speed bonus percent that each player can contribute. Players contribution is based on their own Voyager skill level.", advanced: false, 0f, 2f);
			EnableBoatDamageReduction = BindServerConfig("Voyager", "EnableBoatDamageReduction", value: true, "Enable to reduce damage to your boat as Voyager skill level increases.");
			VoyagerDamageReductionAmount = BindServerConfig("Voyager", "VoyagerDamageReductionAmount", 0.9f, "The maximum percentage of damage reduction, at level 100 skill. Scaled to skill. 1 is 100% damage reduction at player skill level 100.", advanced: false, 0f, 1f);
			BoatDamageReductionLevel = BindServerConfig("Voyager", "BoatDamageReductionLevel", 35, "The level at which you start to recieve a damage reduction from damage taken while on the boat");
			VoyagerImpactResistance = BindServerConfig("Voyager", "VoyagerImpactResistance", value: true, "Whether or not impact resistance is enabled.");
			VoyagerImpactResistanceLevel = BindServerConfig("Voyager", "VoyagerImpactResistanceLevel", 75, "The level at which impact resistance is enabled. This prevents the ship from taking damage when it bumps into something.");
			EnableWeaponSkill = BindServerConfig("WeaponSkills", "EnableWeaponSkill", value: true, "Enable weapon skill changes.");
			WeaponSkillStaminaReduction = BindServerConfig("WeaponSkills", "WeaponSkillStaminaReduction", 0.5f, "How much stamina is reduced based on your weapon skill level at level 100. 0.5 will make level 100 weapon skill give 50% less stamina cost.", advanced: false, 0f, 1f);
			WeaponSkillParryBonus = BindServerConfig("WeaponSkills", "WeaponSkillParryBonus", 1f, "How much extra XP you get for parrying an attack", advanced: false, 0f, 10f);
			WeaponSkillBowDrawStaminaCostReduction = BindServerConfig("WeaponSkills", "WeaponSkillBowDrawStaminaCostReduction", 0.5f, "How much stamina is reduced based on your weapon skill level at level 100. 0.5 will make level 100 weapon skill give 50% less stamina cost. Vanilla is .33", advanced: false, 0f, 1f);
			WeaponSkillEquipRequiredLevel = BindServerConfig("WeaponSkills", "WeaponSkillEquipRequiredLevel", 45, "The level that equip speed bonuses start being applied based on your skill", advanced: true, 0, 100);
			WeaponSkillEquipSpeedFactor = BindServerConfig("WeaponSkills", "WeaponSkillEquipSpeedFactor", 2f, "How much faster your equipment is equipped based on your weapon skill.", advanced: true, 0f, 20f);
			EnableBlocking = BindServerConfig("Blocking", "EnableBlocking", value: true, "Enable blocking skill changes.");
			BlockPowerRequiredLevel = BindServerConfig("Blocking", "BlockPowerRequiredLevel", 25, "The level that BlockPowerFactor start being applied based on your skill", advanced: true, 0, 100);
			BlockPowerFactor = BindServerConfig("Blocking", "BlockPowerFactor", 0.75f, "The factor that blocking power increases after reaching the BlockRequiredLevel. Vanilla is .5f", advanced: true, 0.5f, 2f);
			BlockStaminaGainRequiredLevel = BindServerConfig("Blocking", "BlockStaminaGainRequiredLevel", 40, "The level that BlockStaminaGainFactor starts being applied base on your skill", advanced: true, 0, 100);
			BlockStaminaGainFactor = BindServerConfig("Blocking", "BlockStaminaGainFactor", 0.5f, "How much block stamina is returned based on your blocking level. This is modified by your characters blocking level. At level 100 you gain twice your block stamina use's stamina", advanced: true, 0.5f, 2f);
			EnableParryStaminaGain = BindServerConfig("Blocking", "EnableParryStaminaGain", value: false, "Enable stamina gain on parry. Value based off BlockStaminaGainFactor");
			EnableCrafting = BindServerConfig("Crafting", "EnableCrafting", value: true, "Enable crafting skill changes.");
			EnableDurabilityLossPrevention = BindServerConfig("Crafting", "EnableDurabilityLossPrevention", value: true, "Enables durability reduction prevention that can scale with player skill.");
			EnableDurabilitySaves = BindServerConfig("Crafting", "EnableDurabilitySaves", value: true, "Enables reducing how often you use durability for your items.");
			DurabilitySaveLevel = BindServerConfig("Crafting", "DurabilitySaveLevel", 25, "Level requirement to enable durability saves.");
			ChanceForDurabilityLossPrevention = BindServerConfig("Crafting", "ChanceForDurabilityLossPrevention", 0.25f, "Chance that you will not use durability on use.", advanced: false, 0f, 1f);
			ScaleDurabilitySaveBySkillLevel = BindServerConfig("Crafting", "ScaleDurabilitySaveBySkillLevel", value: true, "Reduces MaxChanceForDurabilityPreserveOnUse based on level, at lvl 50 crafting MaxChanceForDurabilityPreserveOnUse is 50% of its value.");
			EnableBonusItemCrafting = BindServerConfig("Crafting", "EnableBonusItemCrafting", value: true, "Enables crafting bonus items.");
			CraftingBonusCraftsLevel = BindServerConfig("Crafting", "CraftingBonusCraftsLevel", 50, "The level at which you can start getting bonus crafts.", advanced: false, 0, 100);
			CraftingMaxBonus = BindServerConfig("Crafting", "CraftingMaxBonus", 3, "The maximum number of additional bonus crafts you can get from crafting an item");
			CraftingBonusChance = BindServerConfig("Crafting", "CraftingBonusChance", 0.3f, "The chance to get a bonus craft when crafting an item. 0.5 is a 50% chance to get a bonus craft at level 100. Bonus crafting success can stack up to the CraftingMaxBonus times.", advanced: false, 0f, 1f);
			EnableCraftBonusAsFraction = BindServerConfig("Crafting", "EnableCraftBonusAsFraction", value: true, "Enable crafting bonus as a fraction of the number crafted (for recipes where the result is more than 1). If disabled, the bonus is always 1 item.");
			CraftBonusFractionOfCraftNumber = BindServerConfig("Crafting", "CraftBonusFractionOfCraftNumber", 0.25f, "If the number of items crafted by the recipe is greater than 1, a percentage of the number crafted is used for the bonus. This determines that percentage. Eg: craft 20 arrows (1 craft) a .25 value would give you 5 arrows for 1 bonus craft.");
			EnableMaterialReturns = BindServerConfig("Crafting", "EnableMaterialReturns", value: true, "Enable material returns from crafting.");
			CraftingMaterialReturnsLevel = BindServerConfig("Crafting", "CraftingMaterialReturnsLevel", 75, "The level at which material returns start being applied based on your skill", advanced: false, 0, 100);
			MaxCraftingMaterialReturnPercent = BindServerConfig("Crafting", "MaxCraftingMaterialReturnPercent", 0.3f, "The maximum percentage of materials that can be returned from crafting. 0.5 is 50% at level 100.", advanced: false, 0f, 1f);
			ChanceForMaterialReturn = BindServerConfig("Crafting", "ChanceForMaterialReturn", 0.15f, "The chance to return materials when crafting an item. 0.25 is a 25% chance to return materials at level 100.", advanced: false, 0f, 1f);
			EnableCooking = BindServerConfig("Cooking", "EnableCooking", value: true, "Enable cooking skill changes.");
			EnableCookingBonusItems = BindServerConfig("Cooking", "EnableCookingBonusItems", value: true, "Enables or disables getting bonuse food items.");
			RequiredLevelForBonusCookingItems = BindServerConfig("Cooking", "RequiredLevelForBonusCookingItems", 10, "Minimum level to start crafting bonus food items.", advanced: false, 0, 100);
			ChanceForCookingBonusItems = BindServerConfig("Cooking", "ChanceForCookingBonusItems", 0.4f, "The chance to craft bonus food items at level 100. 0.4 is a 40% chance.", advanced: false, 0f, 1f);
			CookingBonusItemMaxAmount = BindServerConfig("Cooking", "CookingBonusItemMaxAmount", 3, "The maximum number of cooked items you can recieve as a bonus, each item is an additional chance roll", advanced: true, 0, 10);
			CookingBurnReduction = BindServerConfig("Cooking", "CookingBurnReduction", 0.5f, "How much offset is applied to diminishing returns for food, scaled by the players cooking skill. At 1 and cooking 100 food never degrades.", advanced: false, 0.1f, 1f);
			EnableKnowledgeSharing = BindServerConfig("SkillRates", "EnableKnowledgeSharing", value: true, "Enable shared knowledge, this allows you to gain faster experiance in low skills if you already have other high skills (eg switching primary weapon skill).");
			AnimalTamingSkillGainRate = BindServerConfig("SkillRates", "AnimalTamingSkillGainRate", 1f, "How fast the skill is gained.", advanced: false, 1f, 50f);
			VoyagerSkillGainRate = BindServerConfig("SkillRates", "VoyagerSkillGainRate", 4f, "How fast the skill is gained.", advanced: false, 1f, 50f);
			SharedKnowledgeSkillBonusRate = BindServerConfig("SkillRates", "SharedKnowledgeSkillBonusRate", 1.5f, "How strong at maximum the xp bonus from shared knowledge will be when catching up skills lower than your highest.", advanced: false, 0f, 10f);
			SharedKnowledgeCap = BindServerConfig("SkillRates", "SharedKnowledgeCap", 5f, "The number of levels below your maximum skill that shared knowledge stops providing a bonus at. Eg: max skill 90, at 5 any skills 85+ will not recieve an xp bonus.", advanced: true, 0f, 50f);
			SharedKnowledgeIgnoreList = BindServerConfig("SkillRates", "SharedKnowledgeIgnoreList", "", "Comma separated list of skills to ignore when calculating shared knowledge. This is useful for skills that have vastly different XP curves or that you simply do not want an accelerated growth rate in. Invalid skill names will be ignored.");
			SharedKnowledgeIgnoreList.SettingChanged += SharedKnowledge.UnallowedSharedXPSkillTypesChanged;
			EnableSwimming = BindServerConfig("Swimming", "EnableSwimming", value: true, "Enable swimming skill changes.");
			EnableSwimStaminaCostReduction = BindServerConfig("Swimming", "EnableSwimStaminaCostReduction", value: true, "Enables swim stamina cost reduction, at the level specified by SwimStaminaReductionLevel.");
			SwimSpeedRequiredLevel = BindServerConfig("Swimming", "SwimSpeedRequiredLevel", 25, "The level that swimming speed increases start being applied based on your skill", advanced: false, 0, 100);
			SwimmingSpeedFactor = BindServerConfig("Swimming", "SwimmingSpeedFactor", 3f, "How much swimming speed is increased based on your swimming level. This is modified by your characters swimming level. At skill level 100 the full value is in effect.", advanced: false, 0.1f, 10f);
			SwimStaminaReductionLevel = BindServerConfig("Swimming", "SwimStaminaReductionLevel", 50, "The level that swim stamina cost reductions start being applied based on your skill", advanced: false, 0, 100);
			SwimStaminaCostReductionFactor = BindServerConfig("Swimming", "SwimStaminaCostReductionFactor", 0.5f, "How much swim stamina cost is reduced based on your swimming level. This is modified by your characters swimming level. At skill level 100 the full value is in effect.", advanced: false, 0.1f, 1f);
			PreferOtherPlantGrid = BindServerConfig("Mod Compatibility", "PreferOtherPlantGrid", value: true, "When enabled, and an other planting grid mod is enabled (), Impactful skills planting grid will be disabled.");
		}

		internal static void SetupMainFileWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();
			fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
			fileSystemWatcher.Path = Path.GetDirectoryName(cfg.ConfigFilePath);
			fileSystemWatcher.Filter = "MidnightsFX.ImpactfulSkills.cfg";
			fileSystemWatcher.Changed += OnConfigFileChanged;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private static void OnConfigFileChanged(object sender, FileSystemEventArgs e)
		{
			if (ZNet.instance.IsServer())
			{
				Logger.LogInfo("Configuration file has been changed, reloading settings.");
				cfg.Reload();
			}
		}

		internal static void SendXPForSkillInArea(DataObjects.XPIncreaseRequest xp_increase)
		{
			//IL_0006: 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_002b: Expected O, but got Unknown
			//IL_009a: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogDebug($"Requesting {xp_increase.Skill} xp increase {xp_increase.Amount}");
			ZPackage val = new ZPackage();
			MemoryStream memoryStream = new MemoryStream();
			DataObjects.binFormatter.Serialize(memoryStream, xp_increase);
			val.Write(memoryStream.ToString());
			if (ZNet.instance.IsServer() && ZNet.instance.IsCurrentServerDedicated())
			{
				SkillIncreaseXP.SendPackage(ZNet.instance.GetServerPeer().m_uid, val);
				return;
			}
			SendXPRequestToInRangePlayers(xp_increase, val);
			if ((Object)(object)Player.m_localPlayer != (Object)null && Vector3.Distance(((Component)Player.m_localPlayer).transform.position, (Vector3)xp_increase.Location) <= xp_increase.Range)
			{
				((Character)Player.m_localPlayer).RaiseSkill(xp_increase.Skill, xp_increase.Amount);
			}
		}

		internal static IEnumerator OnServerReceiveXPRequest(long sender, ZPackage pkg)
		{
			MemoryStream serializationStream = new MemoryStream(pkg.ReadByteArray());
			SendXPRequestToInRangePlayers((DataObjects.XPIncreaseRequest)DataObjects.binFormatter.Deserialize(serializationStream), pkg);
			yield break;
		}

		private static void SendXPRequestToInRangePlayers(DataObjects.XPIncreaseRequest xpdetails, ZPackage pkg)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			foreach (ZNetPeer item in Util.ServerGetPeersInArea(xpdetails.Location, xpdetails.Range))
			{
				SkillIncreaseXP.SendPackage(item.m_uid, pkg);
			}
		}

		internal static IEnumerator OnClientReceiveXPGrant(long sender, ZPackage pkg)
		{
			if (pkg != null && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				MemoryStream serializationStream = new MemoryStream(pkg.ReadByteArray());
				DataObjects.XPIncreaseRequest xPIncreaseRequest = (DataObjects.XPIncreaseRequest)DataObjects.binFormatter.Deserialize(serializationStream);
				((Character)Player.m_localPlayer).RaiseSkill(xPIncreaseRequest.Skill, xPIncreaseRequest.Amount);
			}
			yield break;
		}

		public static ConfigEntry<KeyboardShortcut> BindClientConfig(string category, string key, KeyboardShortcut value, string description, bool advanced = false)
		{
			//IL_0007: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			return cfg.Bind<KeyboardShortcut>(category, key, value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = false,
				IsAdvanced = advanced
			} }));
		}

		public static ConfigEntry<float[]> BindServerConfig(string catagory, string key, float[] value, string description, bool advanced = false, float valmin = 0f, float valmax = 150f)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			return cfg.Bind<float[]>(catagory, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(valmin, valmax), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true,
				IsAdvanced = advanced
			} }));
		}

		public static ConfigEntry<bool> BindServerConfig(string catagory, string key, bool value, string description, AcceptableValueBase acceptableValues = null, bool advanced = false)
		{
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			return cfg.Bind<bool>(catagory, key, value, new ConfigDescription(description, acceptableValues, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true,
				IsAdvanced = advanced
			} }));
		}

		public static ConfigEntry<int> BindServerConfig(string catagory, string key, int value, string description, bool advanced = false, int valmin = 0, int valmax = 150)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			return cfg.Bind<int>(catagory, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(valmin, valmax), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true,
				IsAdvanced = advanced
			} }));
		}

		public static ConfigEntry<float> BindServerConfig(string catagory, string key, float value, string description, bool advanced = false, float valmin = 0f, float valmax = 150f)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			return cfg.Bind<float>(catagory, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(valmin, valmax), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true,
				IsAdvanced = advanced
			} }));
		}

		public static ConfigEntry<string> BindServerConfig(string catagory, string key, string value, string description, AcceptableValueList<string> acceptableValues = null, bool advanced = false)
		{
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			return cfg.Bind<string>(catagory, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)acceptableValues, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true,
				IsAdvanced = advanced
			} }));
		}
	}
	internal static class LocalizationLoader
	{
		internal const string LocalizationFolder = "Localizations";

		private static readonly Regex CommentLine = new Regex("^\\s*//.*$", RegexOptions.Multiline);

		internal static void AddLocalizations()
		{
			CustomLocalization localization = ImpactfulSkills.Localization;
			string text = Path.Combine(Paths.ConfigPath, "ImpactfulSkills", "Localizations");
			Directory.CreateDirectory(text);
			Logger.LogInfo("Loading Localizations.");
			string[] manifestResourceNames = typeof(ImpactfulSkills).Assembly.GetManifestResourceNames();
			foreach (string text2 in manifestResourceNames)
			{
				if (!text2.Contains("Localizations"))
				{
					continue;
				}
				string text3 = LanguageNameFromResource(text2);
				if (text3 == null)
				{
					Logger.LogWarning("Could not determine a language name for '" + text2 + "', skipping it.");
					continue;
				}
				try
				{
					AddLocalization(localization, text2, text3, Path.Combine(text, text3 + ".json"));
				}
				catch (Exception ex)
				{
					Logger.LogError("Failed to load localization '" + text3 + "': " + ex.Message);
				}
			}
		}

		private static void AddLocalization(CustomLocalization Localization, string embeddedResource, string language, string translationFile)
		{
			Dictionary<string, string> dictionary = SimpleJson.DeserializeObject<Dictionary<string, string>>(CommentLine.Replace(ReadEmbeddedResourceFile(embeddedResource), ""));
			List<string> token_order = dictionary.Keys.ToList();
			Dictionary<string, string> dictionary2 = dictionary;
			bool flag = true;
			if (File.Exists(translationFile))
			{
				try
				{
					dictionary2 = SimpleJson.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(translationFile));
					flag = UpdateLocalizationWithMissingKeys(dictionary, dictionary2);
				}
				catch
				{
					Logger.LogWarning("'" + translationFile + "' could not be parsed, resetting it to the built in " + language + " localization.");
					dictionary2 = dictionary;
					flag = true;
				}
			}
			string text = SerializePretty(dictionary2, token_order);
			if (flag)
			{
				File.WriteAllText(translationFile, text, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
				Logger.LogDebug("Wrote " + translationFile);
			}
			Localization.AddJsonFile(language, text);
			Logger.LogDebug("Added localization: '" + language + "'");
		}

		private static bool UpdateLocalizationWithMissingKeys(Dictionary<string, string> internal_localization, Dictionary<string, string> cached_localization)
		{
			bool result = false;
			List<string> list = cached_localization.Keys.Where((string key) => !internal_localization.ContainsKey(key)).ToList();
			if (list.Count > 0)
			{
				Logger.LogDebug("Removing extra keys " + string.Join(",", list) + ".");
				foreach (string item in list)
				{
					cached_localization.Remove(item);
				}
				result = true;
			}
			foreach (KeyValuePair<string, string> item2 in internal_localization)
			{
				if (!cached_localization.ContainsKey(item2.Key))
				{
					Logger.LogDebug("Adding missing localization key " + item2.Key);
					cached_localization.Add(item2.Key, item2.Value);
					result = true;
				}
			}
			return result;
		}

		private static string SerializePretty(Dictionary<string, string> localization, List<string> token_order)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("{\n");
			for (int i = 0; i < token_order.Count; i++)
			{
				string text = token_order[i];
				stringBuilder.Append("  \"").Append(EscapeJsonString(text)).Append("\": \"")
					.Append(EscapeJsonString(localization[text]))
					.Append('"');
				if (i < token_order.Count - 1)
				{
					stringBuilder.Append(',');
				}
				stringBuilder.Append('\n');
			}
			stringBuilder.Append("}\n");
			return stringBuilder.ToString();
		}

		private static string EscapeJsonString(string value)
		{
			StringBuilder stringBuilder = new StringBuilder(value.Length);
			foreach (char c in value)
			{
				switch (c)
				{
				case '"':
					stringBuilder.Append("\\\"");
					continue;
				case '\\':
					stringBuilder.Append("\\\\");
					continue;
				case '\b':
					stringBuilder.Append("\\b");
					continue;
				case '\f':
					stringBuilder.Append("\\f");
					continue;
				case '\n':
					stringBuilder.Append("\\n");
					continue;
				case '\r':
					stringBuilder.Append("\\r");
					continue;
				case '\t':
					stringBuilder.Append("\\t");
					continue;
				}
				if (c < ' ')
				{
					StringBuilder stringBuilder2 = stringBuilder.Append("\\u");
					int num = c;
					stringBuilder2.Append(num.ToString("x4"));
				}
				else
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString();
		}

		private static string LanguageNameFromResource(string embeddedResource)
		{
			string[] array = embeddedResource.Split(new char[1] { '.' });
			int num = Array.IndexOf(array, "Localizations");
			if (num < 0 || num + 2 > array.Length - 1)
			{
				return null;
			}
			return array[num + 1];
		}

		private static string ReadEmbeddedResourceFile(string filename)
		{
			using Stream stream = typeof(ImpactfulSkills).Assembly.GetManifestResourceStream(filename);
			using StreamReader streamReader = new StreamReader(stream);
			return streamReader.ReadToEnd();
		}
	}
	internal class Logger
	{
		public static LogLevel Level = (LogLevel)16;

		public static void enableDebugLogging(object sender, EventArgs e)
		{
			//IL_0016: 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)
			if (ValConfig.EnableDebugMode.Value)
			{
				Level = (LogLevel)32;
			}
			else
			{
				Level = (LogLevel)16;
			}
		}

		public static void setDebugLogging(bool state)
		{
			//IL_000d: 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)
			if (state)
			{
				Level = (LogLevel)32;
			}
			else
			{
				Level = (LogLevel)16;
			}
		}

		public static void LogDebug(string message)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)Level >= 32)
			{
				ImpactfulSkills.Log.LogInfo((object)message);
			}
		}

		public static void LogInfo(string message)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)Level >= 16)
			{
				ImpactfulSkills.Log.LogInfo((object)message);
			}
		}

		public static void LogWarning(string message)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)Level >= 4)
			{
				ImpactfulSkills.Log.LogWarning((object)message);
			}
		}

		public static void LogError(string message)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)Level >= 2)
			{
				ImpactfulSkills.Log.LogError((object)message);
			}
		}
	}
	[BepInPlugin("MidnightsFX.ImpactfulSkills", "ImpactfulSkills", "0.10.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class ImpactfulSkills : BaseUnityPlugin
	{
		public const string PluginGUID = "MidnightsFX.ImpactfulSkills";

		public const string PluginName = "ImpactfulSkills";

		public const string PluginVersion = "0.10.0";

		public ValConfig cfg;

		public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

		internal static AssetBundle EmbeddedResourceBundle;

		public static ManualLogSource Log;

		public void Awake()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			cfg = new ValConfig(((BaseUnityPlugin)this).Config);
			EmbeddedResourceBundle = AssetUtils.LoadAssetBundleFromResources("ImpactfulSkills.AssetsEmbedded.impactfulskills", typeof(ImpactfulSkills).Assembly);
			LocalizationLoader.AddLocalizations();
			Gathering.SetupGatherables();
			Mining.SetupMining();
			AnimalWhisper.SetupAnimalSkill();
			Voyaging.SetupSailingSkill();
			Hauling.SetupHaulingSkill();
			HaulingXPTracker.Create();
			Modcheck.CheckModCompat();
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			new Harmony("MidnightsFX.ImpactfulSkills").PatchAll(executingAssembly);
		}
	}
}
namespace ImpactfulSkills.modules.Multiplant
{
	internal class Plantable
	{
		public float GrowRadius { get; set; }

		public GameObject Refgo { get; set; }

		public List<Requirement> Seeds { get; set; }
	}
	internal static class PlantDefinitions
	{
		[HarmonyPriority(100)]
		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		public static class Patch_ZNetScene_Awake
		{
			private static void Postfix()
			{
				BuildPlantRequirements();
			}
		}

		internal static Dictionary<string, Plantable> PlantableDefinitions = new Dictionary<string, Plantable>();

		internal static int plantSpaceMask = 0;

		internal static int GhostLayer = 0;

		internal static void BuildPlantRequirements()
		{
			PlantableDefinitions.Clear();
			if ((Object)(object)ZNetScene.instance == (Object)null || ZNetScene.instance.m_prefabs == null)
			{
				Logger.LogWarning("ZNetScene not ready for plant definitions");
				return;
			}
			foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
			{
				Plant component = prefab.GetComponent<Plant>();
				if ((Object)(object)component == (Object)null || PlantableDefinitions.ContainsKey(((Object)prefab).name))
				{
					continue;
				}
				List<Requirement> list = new List<Requirement>();
				Piece component2 = prefab.GetComponent<Piece>();
				if ((Object)(object)component2 != (Object)null)
				{
					Requirement[] resources = component2.m_resources;
					foreach (Requirement item in resources)
					{
						list.Add(item);
					}
				}
				PlantableDefinitions.Add(((Object)prefab).name, new Plantable
				{
					GrowRadius = component.m_growRadius,
					Refgo = prefab,
					Seeds = list
				});
				GameObject[] grownPrefabs = component.m_grownPrefabs;
				foreach (GameObject val in grownPrefabs)
				{
					if (!PlantableDefinitions.ContainsKey(((Object)val).name))
					{
						PlantableDefinitions.Add(((Object)val).name, new Plantable
						{
							Refgo = val,
							GrowRadius = component.m_growRadius
						});
					}
				}
				Logger.LogDebug("Added plant cache entry: " + ((Object)prefab).name);
			}
			plantSpaceMask = LayerMask.GetMask(new string[4] { "static_solid", "Default_small", "piece", "piece_nonsolid" });
			GhostLayer = LayerMask.NameToLayer("ghost");
			Logger.LogInfo($"Loaded {PlantableDefinitions.Count} plantable definitions");
		}
	}
	internal static class PlantGhostController
	{
		internal static readonly List<GameObject> ExtraGhosts = new List<GameObject>();

		internal static readonly List<bool> GhostValid = new List<bool>();

		private static readonly int _ghostLayer = LayerMask.NameToLayer("ghost");

		private static string _lastPlantName = "";

		private static bool _preservePool;

		private static int MaxActiveGhosts => PlantGrid.MaxToPlantAtOnce() - 1;

		private static int TotalCells => 1 + MaxActiveGhosts;

		private static int Columns => Mathf.Clamp(Mathf.CeilToInt(Mathf.Sqrt((float)TotalCells)), 1, ValConfig.FarmingMultiplantColumnCount.Value);

		internal static void Prepare(GameObject rootGhost)
		{
			if ((Object)(object)rootGhost == (Object)null)
			{
				DestroyPool();
				return;
			}
			DetectPlantChange(rootGhost);
			if (!ShouldPreservePool())
			{
				DestroyPool();
			}
		}

		internal static void BuildGrid(GameObject rootGhost)
		{
			GrowPoolIfNeeded(rootGhost);
			InitializeGhosts(rootGhost);
			DeactivateExcess();
			PlantGrid.GridPlantingActive = true;
		}

		internal static void DestroyPool()
		{
			foreach (GameObject extraGhost in ExtraGhosts)
			{
				if ((Object)(object)extraGhost != (Object)null)
				{
					Object.Destroy((Object)(object)extraGhost);
				}
			}
			ExtraGhosts.Clear();
			GhostValid.Clear();
			PlantGrid.GridPlantingActive = false;
			PlantGridState.ResetSavedOrientation();
		}

		internal static void Update()
		{
			UpdateVisibility();
			if (!((Object)(object)PlantGridState.PlacementGhost == (Object)null))
			{
				int columns = Columns;
				UpdateGhost(0, 0, 0);
				for (int i = 1; i < TotalCells && i - 1 < ExtraGhosts.Count; i++)
				{
					UpdateGhost(i / columns, i % columns, i);
				}
			}
		}

		private static void GrowPoolIfNeeded(GameObject rootGhost)
		{
			string name = ((Object)rootGhost).name;
			while (ExtraGhosts.Count < MaxActiveGhosts)
			{
				ZNetView.m_forceDisableInit = true;
				GameObject val = Object.Instantiate<GameObject>(rootGhost);
				ZNetView.m_forceDisableInit = false;
				((Object)val).name = name;
				Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Component)componentsInChildren[i]).gameObject.layer = _ghostLayer;
				}
				ExtraGhosts.Add(val);
			}
		}

		private static void InitializeGhosts(GameObject rootGhost)
		{
			//IL_0039: 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)
			GhostValid.Clear();
			GhostValid.Add(item: true);
			Transform transform = rootGhost.transform;
			for (int i = 0; i < MaxActiveGhosts && i < ExtraGhosts.Count; i++)
			{
				GameObject obj = ExtraGhosts[i];
				obj.SetActive(true);
				obj.transform.position = transform.position;
				obj.transform.localScale = transform.localScale;
				GhostValid.Add(item: true);
			}
		}

		private static void DeactivateExcess()
		{
			for (int i = MaxActiveGhosts; i < ExtraGhosts.Count; i++)
			{
				ExtraGhosts[i].SetActive(false);
			}
		}

		private static void UpdateVisibility()
		{
			bool flag = (Object)(object)PlantGridState.PlacementGhost != (Object)null && PlantGridState.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 UpdateGhost(int row, int col, int index)
		{
			//IL_003d: 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_002a: 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_0042: 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_005a: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			GameObject ghost = GetGhost(index);
			if (!((Object)(object)ghost == (Object)null))
			{
				Vector3 val = ((index == 0) ? PlantGridState.BasePosition : (PlantGridState.BasePosition + PlantGridState.RowDirection * (float)row + PlantGridState.ColumnDirection * (float)col));
				float y = default(float);
				Heightmap.GetHeight(val, ref y);
				val.y = y;
				ghost.transform.position = val;
				if (index > 0)
				{
					ghost.transform.rotation = Quaternion.identity;
				}
				bool flag = IsValidPosition(val);
				Piece component = ghost.GetComponent<Piece>();
				if (component != null)
				{
					component.SetInvalidPlacementHeightlight(!flag);
				}
				if (index < GhostValid.Count)
				{
					GhostValid[index] = flag;
				}
			}
		}

		private static GameObject GetGhost(int index)
		{
			if (index == 0)
			{
				return PlantGridState.PlacementGhost;
			}
			int num = index - 1;
			if (num >= ExtraGhosts.Count)
			{
				return null;
			}
			return ExtraGhosts[num];
		}

		internal static bool IsValidPosition(Vector3 pos)
		{
			//IL_0000: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			Heightmap val = Heightmap.FindHeightmap(pos);
			if ((Object)(object)val == (Object)null || (Object)(object)PlantGridState.Plant == (Object)null)
			{
				return false;
			}
			if (PlantGridState.Plant.m_needCultivatedGround && !val.IsCultivated(pos))
			{
				return false;
			}
			return Physics.OverlapSphere(pos, PlantGridState.Plant.m_growRadius, Plant.m_spaceMask).Length == 0;
		}

		private static void DetectPlantChange(GameObject rootGhost)
		{
			string name = ((Object)rootGhost).name;
			if (name == _lastPlantName)
			{
				_preservePool = true;
				return;
			}
			_lastPlantName = name;
			_preservePool = false;
		}

		private static bool ShouldPreservePool()
		{
			if (!_preservePool || !PlantGrid.GridPlantingActive)
			{
				return false;
			}
			_preservePool = false;
			return true;
		}
	}
	internal static class PlantGrid
	{
		[HarmonyPatch(typeof(Player), "SetupPlacementGhost")]
		private static class PlayerSetupPlacementGhost
		{
			private static void Prefix(Player __instance, out int __state)
			{
				__state = __instance.m_placeRotation;
			}

			private static void Postfix(Player __instance, int __state)
			{
				if (!ValConfig.EnableFarmingMultiPlant.Value || UseOtherPlantGridSystem || (Object)(object)__instance.m_placementGhost == (Object)null || !HoldingCultivator())
				{
					PlantGhostController.DestroyPool();
					PlantGridState.Clear();
					return;
				}
				if (((Character)__instance).GetSkillLevel((SkillType)106) < (float)ValConfig.FarmingMultiplantRequiredLevel.Value)
				{
					PlantGhostController.DestroyPool();
					PlantGridState.Clear();
					return;
				}
				if (!IsPlantable(__instance.m_placementGhost))
				{
					PlantGhostController.DestroyPool();
					PlantGridState.Clear();
					return;
				}
				Plant component = __instance.m_placementGhost.GetComponent<Plant>();
				if ((Object)(object)component != (Object)null)
				{
					Spacing = component.m_growRadius * ValConfig.FarmingMultiPlantDistanceBufferModifier.Value + ValConfig.FarmingMultiPlantBufferSpace.Value;
				}
				PlantGridState.SetReferences(__instance.m_placementGhost);
				PlantGhostController.Prepare(__instance.m_placementGhost);
				PlantGhostController.BuildGrid(__instance.m_placementGhost);
				if (ValConfig.FarmingMultiPlantPersistOrientation.Value && __instance.m_placeRotation != __state)
				{
					if (ValConfig.EnableDebugMode.Value)
					{
						Logger.LogDebug($"[Multiplant/setup] restoring placeRot {__instance.m_placeRotation} -> {__state}");
					}
					__instance.m_placeRotation = __state;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
		private static class AdjustPlacementGhosts
		{
			private static void Postfix()
			{
				if (!GridPlantingActive || UseOtherPlantGridSystem || !HoldingCultivator())
				{
					return;
				}
				PlantGridState.Update();
				if (MultiplantDisabled)
				{
					foreach (GameObject extraGhost in PlantGhostController.ExtraGhosts)
					{
						if ((Object)(object)extraGhost != (Object)null)
						{
							extraGhost.SetActive(false);
						}
					}
					return;
				}
				PlantGhostController.Update();
			}
		}

		[HarmonyPatch(typeof(Player), "PlacePiece")]
		public static class PlaceMultiPlantPieces
		{
			private static void Prefix(Player __instance, out int __state)
			{
				__state = __instance.m_placeRotation;
			}

			private static void Postfix(Player __instance, Piece piece, int __state)
			{
				//IL_0065: 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)
				if (!GridPlantingActive || UseOtherPlantGridSystem || !IsPlantable(((Component)piece).gameObject))
				{
					return;
				}
				if (ValConfig.FarmingMultiPlantPersistOrientation.Value)
				{
					PlantGridState.SaveOrientation();
					__instance.m_placeRotation = __state;
					if (ValConfig.EnableDebugMode.Value)
					{
						Logger.LogDebug($"[Multiplant/place] persist=True randomInit={piece.m_randomInitBuildRotation} " + $"placeRot restored to {__state} baseYaw={((Quaternion)(ref PlantGridState.BaseRotation)).eulerAngles.y:F0} " + $"savedRow={PlantGridState.HeadingOf(PlantGridState.SavedRowDirection):F0}");
					}
				}
				PlantGhostsWithCosts(__instance, ((Component)piece).gameObject);
			}
		}

		internal static bool GridPlantingActive = false;

		internal static bool MultiplantDisabled = false;

		internal static float Spacing = 0f;

		internal static int UserDefinedMax = ValConfig.FarmingMultiplantMaxPlantedAtOnce.Value;

		internal static bool UseOtherPlantGridSystem = IsOtherPlantGridSystemAvailable();

		public static bool IsOtherPlantGridSystemAvailable()
		{
			if (ValConfig.PreferOtherPlantGrid.Value && Modcheck.OtherFarmingGridModPresent())
			{
				return true;
			}
			return false;
		}

		internal static int MaxToPlantAtOnce()
		{
			int num = Mathf.RoundToInt((float)ValConfig.FarmingMultiplantMaxPlantedAtOnce.Value * ((Character)Player.m_localPlayer).GetSkillFactor((SkillType)106));
			if (num <= 1)
			{
				return 1;
			}
			return num;
		}

		internal static bool HoldingCultivator()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null || ((Humanoid)Player.m_localPlayer).GetRightItem() == null)
			{
				return false;
			}
			return ((Humanoid)Player.m_localPlayer).GetRightItem().m_shared.m_name == "$item_cultivator";
		}

		internal static bool IsPlantable(GameObject go)
		{
			return (Object)(object)go.GetComponent<Plant>() != (Object)null;
		}

		internal static void PlantGhostsWithCosts(Player player, GameObject primaryPlantablePrefab)
		{
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			if (!GridPlantingActive || PlantGhostController.ExtraGhosts.Count == 0)
			{
				return;
			}
			Logger.LogDebug("Placing plants in grid");
			int num = 0;
			string prefabName = Utils.GetPrefabName(primaryPlantablePrefab);
			Plantable plantable = PlantDefinitions.PlantableDefinitions[prefabName];
			int num2 = 100;
			if (plantable.Seeds.Count > 0)
			{
				foreach (Requirement seed in plantable.Seeds)
				{
					int num3 = ((Humanoid)player).m_inventory.CountItems(seed.m_resItem.m_itemData.m_shared.m_name, -1, true) / seed.m_amount;
					if (num3 < num2)
					{
						num2 = num3;
					}
				}
			}
			Logger.LogDebug($"Resources support planting up to {num2}");
			float num4 = 10f * (ValConfig.PlantingCostStaminaReduction.Value * ((Character)player).GetSkillFactor((SkillType)106) - 1f);
			float num5 = 0f;
			for (int i = 0; i < PlantGhostController.ExtraGhosts.Count; i++)
			{
				GameObject val = PlantGhostController.ExtraGhosts[i];
				if (!val.activeSelf)
				{
					continue;
				}
				int num6 = i + 1;
				if (num6 < PlantGhostController.GhostValid.Count && PlantGhostController.GhostValid[num6])
				{
					if (!((Character)player).HaveStamina(num5 + num4))
					{
						Logger.LogDebug($"Not enough stamina to plant more (cost so far: {num5})");
						break;
					}
					if (!player.NoCostCheat() && num2 == num + 1)
					{
						Logger.LogDebug($"Not enough resources for plant {num + 1}");
						break;
					}
					num5 += num4;
					Object.Instantiate<GameObject>(primaryPlantablePrefab, val.transform.position, primaryPlantablePrefab.transform.rotation);
					num++;
				}
			}
			if (plantable.Seeds.Count > 0)
			{
				Logger.LogDebug("Removing seed costs");
				foreach (Requirement seed2 in plantable.Seeds)
				{
					((Humanoid)player).m_inventory.RemoveItem(seed2.m_resItem.m_itemData.m_shared.m_name, seed2.m_amount * num, -1, true);
				}
			}
			Logger.LogDebug("Applying stamina cost and XP.");
			((Character)player).UseStamina(num5);
			((Character)player).RaiseSkill((SkillType)106, (float)num);
		}
	}
	internal static class PlantGridState
	{
		internal static GameObject PlacementGhost;

		internal static Plant Plant;

		internal static Vector3 BasePosition;

		internal static Quaternion BaseRotation;

		internal static Quaternion FixedRotation;

		internal static Vector3 RowDirection;

		internal static Vector3 ColumnDirection;

		internal static bool AltPlacement;

		internal static Quaternion? SavedBaseRotation;

		internal static Vector3 SavedRowDirection;

		internal static Vector3 SavedColumnDirection;

		private static bool _snapEngaged;

		private static string _dbgSig;

		internal static void SetReferences(GameObject rootGhost)
		{
			PlacementGhost = rootGhost;
			Plant = rootGhost.GetComponent<Plant>();
		}

		internal static void Clear()
		{
			PlacementGhost = null;
			Plant = null;
		}

		internal static void Update()
		{
			//IL_0027: 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_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_004a: 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_0052: 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_006f: 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)
			if (!((Object)(object)PlacementGhost == (Object)null))
			{
				AltPlacement = ZInput.GetButton("AltPlace");
				BasePosition = PlacementGhost.transform.position;
				BaseRotation = PlacementGhost.transform.rotation;
				Vector3 eulerAngles = ((Quaternion)(ref BaseRotation)).eulerAngles;
				eulerAngles.y = Mathf.Round(eulerAngles.y / 90f) * 90f;
				FixedRotation = Quaternion.Euler(eulerAngles);
				UpdateDirectionsAndSnap();
				DebugTrace();
			}
		}

		private static void UpdateDirectionsAndSnap()
		{
			//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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0081: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			float spacing = PlantGrid.Spacing;
			string prefabName = Utils.GetPrefabName(PlacementGhost);
			_snapEngaged = false;
			RowDirection = BaseRotation * Vector3.forward;
			ColumnDirection = BaseRotation * Vector3.right;
			if (ValConfig.FarmingMultiPlantSnapToExisting.Value && !AltPlacement && SnapSystem.FindSnapPoints(prefabName, spacing))
			{
				_snapEngaged = true;
				return;
			}
			if (OrientationRotatedAway())
			{
				ResetSavedOrientation();
			}
			if (ValConfig.FarmingMultiPlantPersistOrientation.Value && !AltPlacement && SavedRowDirection != Vector3.zero)
			{
				RowDirection = SavedRowDirection * spacing;
				ColumnDirection = SavedColumnDirection * spacing;
			}
			else
			{
				RowDirection *= spacing;
				ColumnDirection *= spacing;
			}
		}

		internal static void SaveOrientation()
		{
			//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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Vector3)(ref RowDirection)).sqrMagnitude < 0.0001f) && !(((Vector3)(ref ColumnDirection)).sqrMagnitude < 0.0001f))
			{
				SavedRowDirection = ((Vector3)(ref RowDirection)).normalized;
				SavedColumnDirection = ((Vector3)(ref ColumnDirection)).normalized;
				SavedBaseRotation = BaseRotation;
			}
		}

		internal static bool OrientationRotatedAway()
		{
			//IL_000c: 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)
			if (SavedBaseRotation.HasValue)
			{
				return Quaternion.Angle(BaseRotation, SavedBaseRotation.Value) > 11f;
			}
			return false;
		}

		internal static void ResetSavedOrientation()
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			SavedBaseRotation = null;
			SavedRowDirection = Vector3.zero;
			SavedColumnDirection = Vector3.zero;
		}

		internal static float HeadingOf(Vector3 v)
		{
			//IL_001a: 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)
			v.y = 0f;
			if (!(((Vector3)(ref v)).sqrMagnitude < 1E-06f))
			{
				return Mathf.Atan2(v.x, v.z) * 57.29578f;
			}
			return 0f;
		}

		private static void DebugTrace()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (ValConfig.EnableDebugMode.Value)
			{
				string arg = ((SavedRowDirection == Vector3.zero) ? "none" : $"{HeadingOf(SavedRowDirection):F0}");
				string text = $"snap={_snapEngaged} alt={AltPlacement} ghostYaw={((Quaternion)(ref BaseRotation)).eulerAngles.y:F0} " + $"row={HeadingOf(RowDirection):F0} saved={arg} rotAway={OrientationRotatedAway()}";
				if (!(text == _dbgSig))
				{
					_dbgSig = text;
					Logger.LogDebug("[Multiplant/orient] " + text);
				}
			}
		}
	}
	internal class SnapPoint
	{
		internal Vector3 pos;

		internal Vector3 rowDir;

		internal Vector3 colDir;

		internal Vector3 origin;

		internal SnapPoint()
		{
		}

		internal SnapPoint(Vector3 pos, Vector3 rowDir, Vector3 colDir, 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;
			this.rowDir = rowDir;
			this.colDir = colDir;
			this.origin = origin;
		}
	}
	internal static class SnapSystem
	{
		private class GridAnchor
		{
			internal Vector3 pos;

			internal Vector3 axisRow;

			internal Vector3 axisCol;

			internal float spacing;

			internal int cRow;

			internal int cCol;

			internal Vector3 idealPos;
		}

		private static readonly int _scanMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" });

		private const int MaxPrimaries = 8;

		private const int CellSearchRadius = 3;

		internal static bool FindSnapPoints(string plantName, float pieceSpacing)
		{
			if (ValConfig.FarmingSnapStyle?.Value == "Legacy")
			{
				return TryFreeSnap(plantName, pieceSpacing);
			}
			return TryGridSnap(plantName, pieceSpacing);
		}

		private static bool TryFreeSnap(string plantName, float pieceSpacing)
		{
			//IL_0000: 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_002d: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0074: 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)
			List<Transform> list = ScanForPlants(PlantGridState.BasePosition, ValConfig.PlantingSnapDistance.Value, plantName);
			if (list.Count == 0)
			{
				return false;
			}
			Transform val = SortByDistance(list, PlantGridState.BasePosition);
			ComputeFreeDirections(val.position, pieceSpacing);
			List<SnapPoint> list2 = new List<SnapPoint>();
			if (!GenerateCandidates(list2, val.position))
			{
				return false;
			}
			SnapPoint snapPoint = FindNearestEuclidean(list2);
			CommitSnap(snapPoint);
			PlantGridState.RowDirection = ChooseDirection(snapPoint.pos, PlantGridState.RowDirection);
			PlantGridState.ColumnDirection = ChooseDirection(snapPoint.pos, PlantGridState.ColumnDirection);
			return true;
		}

		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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007f: 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_008f: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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)
			Vector3 val = PlantGridState.BasePosition - target;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.001f)
			{
				val = Vector3.forward;
			}
			else
			{
				((Vector3)(ref val)).Normalize();
				if (!PlantGridState.AltPlacement)
				{
					float num = Vector3.SignedAngle(Vector3.forward, val, Vector3.up);
					val = Quaternion.Euler(0f, Mathf.Round(num / 90f) * 90f, 0f) * Vector3.forward;
				}
			}
			PlantGridState.RowDirection = PlantGridState.FixedRotation * val * pieceSpacing;
			PlantGridState.ColumnDirection = Vector3.Cross(Vector3.up, PlantGridState.RowDirection);
		}

		private static bool TryGridSnap(string plantName, float heldSpacing)
		{
			//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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00d6: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//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)
			Vector3 basePosition = PlantGridState.BasePosition;
			List<Transform> list = ScanForPlants(basePosition, ValConfig.PlantingSnapDistance.Value, plantName);
			if (list.Count == 0)
			{
				return false;
			}
			GridAnchor gridAnchor = null;
			float num = float.MaxValue;
			foreach (Transform item in list)
			{
				float num2 = SpacingForAnchor(item, heldSpacing);
				if (!(num2 <= 0.001f))
				{
					Vector3 position = item.position;
					Vector3 val = AxisRowFor(position, num2, list);
					Vector3 val2 = Vector3.Cross(Vector3.up, val);
					Vector3 val3 = basePosition - position;
					val3.y = 0f;
					int num3 = Mathf.RoundToInt(Vector3.Dot(val3, val) / num2);
					int num4 = Mathf.RoundToInt(Vector3.Dot(val3, val2) / num2);
					Vector3 val4 = position + val * (num2 * (float)num3) + val2 * (num2 * (float)num4);
					Vector3 val5 = val4 - basePosition;
					float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						gridAnchor = new GridAnchor
						{
							pos = position,
							axisRow = val,
							axisCol = val2,
							spacing = num2,
							cRow = num3,
							cCol = num4,
							idealPos = val4
						};
					}
				}
			}
			if (gridAnchor == null)
			{
				return false;
			}
			if (!TryFindFreeCell(gridAnchor, basePosition, out var result))
			{
				return false;
			}
			PlantGridState.RowDirection = gridAnchor.axisRow * heldSpacing;
			PlantGridState.ColumnDirection = gridAnchor.axisCol * heldSpacing;
			CommitSnap(new SnapPoint(result, PlantGridState.RowDirection, PlantGridState.ColumnDirection, gridAnchor.pos));
			PlantGridState.RowDirection = ChooseDirection(result, PlantGridState.RowDirection);
			PlantGridState.ColumnDirection = ChooseDirection(result, PlantGridState.ColumnDirection);
			return true;
		}

		private static float SpacingForAnchor(Transform anchorRoot, float fallback)
		{
			Plant componentInChildren = ((Component)anchorRoot).GetComponentInChildren<Plant>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return fallback;
			}
			return componentInChildren.m_growRadius * ValConfig.FarmingMultiPlantDistanceBufferModifier.Value + ValConfig.FarmingMultiPlantBufferSpace.Value;
		}

		private static Vector3 AxisRowFor(Vector3 anchorPos, float spacing, List<Transform> primaries)
		{
			//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_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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			float num = float.MaxValue;
			float num2 = spacing * 0.6f;
			float num3 = spacing * 1.4f;
			foreach (Transform primary in primaries)
			{
				Vector3 val2 = primary.position - anchorPos;
				val2.y = 0f;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				if (!(magnitude < 0.001f) && !(magnitude < num2) && !(magnitude > num3) && magnitude < num)
				{
					num = magnitude;
					val = val2 / magnitude;
				}
			}
			if (val == Vector3.zero)
			{
				val = PlantGridState.FixedRotation * Vector3.forward;
				val.y = 0f;
			}
			if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
			{
				return Vector3.forward;
			}
			((Vector3)(ref val)).Normalize();
			return val;
		}

		private static bool TryFindFreeCell(GridAnchor a, Vector3 cursor, out Vector3 result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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