Decompiled source of balrond amazing nature v1.3.7

plugins/BalrondAmazingNature.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using LitJson2;
using SoftReferenceableAssets;
using UnityEngine;
using UnityEngine.Events;
using UpgradeWorld;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BalrondNature")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BalrondNature")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cde312a0-cf19-4264-8616-e1c74774beed")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public static class BalrondHashCompat
{
	private static readonly MethodInfo _getStableHashCodeStringBool;

	private static readonly MethodInfo _getStableHashCodeString;

	private static readonly bool _initialized;

	static BalrondHashCompat()
	{
		try
		{
			Type typeFromHandle = typeof(StringExtensionMethods);
			_getStableHashCodeStringBool = typeFromHandle.GetMethod("GetStableHashCode", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
			{
				typeof(string),
				typeof(bool)
			}, null);
			_getStableHashCodeString = typeFromHandle.GetMethod("GetStableHashCode", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null);
			_initialized = true;
		}
		catch
		{
			_initialized = false;
		}
	}

	public static int StableHash(string value)
	{
		if (value == null)
		{
			return 0;
		}
		try
		{
			if (_getStableHashCodeStringBool != null)
			{
				return (int)_getStableHashCodeStringBool.Invoke(null, new object[2] { value, false });
			}
			if (_getStableHashCodeString != null)
			{
				return (int)_getStableHashCodeString.Invoke(null, new object[1] { value });
			}
		}
		catch
		{
		}
		return FallbackStableHash(value);
	}

	private static int FallbackStableHash(string value)
	{
		int num = 5381;
		int num2 = num;
		for (int i = 0; i < value.Length; i += 2)
		{
			num = ((num << 5) + num) ^ value[i];
			if (i == value.Length - 1)
			{
				break;
			}
			num2 = ((num2 << 5) + num2) ^ value[i + 1];
		}
		return num + num2 * 1566083941;
	}
}
public class MonsterDoorSensor : MonoBehaviour
{
	private static readonly Collider[] Hits = (Collider[])(object)new Collider[32];

	private static readonly int CharacterMask = LayerMask.GetMask(new string[3] { "character", "character_net", "character_noenv" });

	private const float MinCheckInterval = 0.1f;

	private const float MinDetectRadius = 0.5f;

	private const float NotifyPlayerDistance = 18f;

	private const float NotifyPlayerDistanceSqr = 324f;

	[Header("Monster Door Sensor")]
	public string[] AllowedMonsterPrefabNames = Array.Empty<string>();

	public float DetectRadius = 2.8f;

	public float CheckInterval = 0.35f;

	public bool AllowOpening = true;

	public bool RespectPrivateArea = true;

	public bool MakeAttackTargetIfBlockedByWard = true;

	public bool IgnoreKeyedDoors = true;

	public bool RequireMonsterTarget = true;

	public bool RequireMovingOrFacingDoor = true;

	public float MinFacingDot = 0.35f;

	private Door _door;

	private ZNetView _doorView;

	private Piece _piece;

	private Transform _doorTransform;

	private float _nextCheck;

	private float _detectRadiusCached;

	private float _checkIntervalCached;

	private HashSet<string> _allowedMonsterCache;

	private void Awake()
	{
		CacheComponents();
		CacheTuning();
		BuildAllowedMonsterCache();
	}

	private void OnValidate()
	{
		CacheTuning();
	}

	private void CacheTuning()
	{
		_detectRadiusCached = Mathf.Max(0.5f, DetectRadius);
		_checkIntervalCached = Mathf.Max(0.1f, CheckInterval);
	}

	private void CacheComponents()
	{
		if ((Object)(object)_door == (Object)null)
		{
			_door = ((Component)this).GetComponentInChildren<Door>();
		}
		if ((Object)(object)_door == (Object)null)
		{
			_door = ((Component)this).GetComponent<Door>();
		}
		if ((Object)(object)_door != (Object)null)
		{
			_doorTransform = ((Component)_door).transform;
			if ((Object)(object)_doorView == (Object)null)
			{
				_doorView = ((Component)_door).GetComponent<ZNetView>();
			}
			if ((Object)(object)_piece == (Object)null)
			{
				_piece = ((Component)_door).GetComponent<Piece>();
			}
		}
		if ((Object)(object)_piece == (Object)null)
		{
			_piece = ((Component)this).GetComponent<Piece>();
		}
	}

	private void BuildAllowedMonsterCache()
	{
		_allowedMonsterCache = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
		if (AllowedMonsterPrefabNames == null)
		{
			return;
		}
		for (int i = 0; i < AllowedMonsterPrefabNames.Length; i++)
		{
			string text = AllowedMonsterPrefabNames[i];
			if (!string.IsNullOrEmpty(text))
			{
				_allowedMonsterCache.Add(text);
			}
		}
	}

	private void Update()
	{
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		float time = Time.time;
		if (time < _nextCheck)
		{
			return;
		}
		_nextCheck = time + _checkIntervalCached;
		if ((Object)(object)_door == (Object)null || (Object)(object)_doorView == (Object)null || (Object)(object)_doorTransform == (Object)null)
		{
			CacheComponents();
		}
		if ((Object)(object)_door == (Object)null || (Object)(object)_doorView == (Object)null || (Object)(object)_doorTransform == (Object)null || !_doorView.IsValid() || !_doorView.IsOwner() || _allowedMonsterCache == null || _allowedMonsterCache.Count == 0)
		{
			return;
		}
		Vector3 position = _doorTransform.position;
		int num = Physics.OverlapSphereNonAlloc(position, _detectRadiusCached, Hits, CharacterMask, (QueryTriggerInteraction)1);
		if (num <= 0)
		{
			return;
		}
		for (int i = 0; i < num; i++)
		{
			Collider val = Hits[i];
			if (!((Object)(object)val == (Object)null))
			{
				Character componentInParent = ((Component)val).GetComponentInParent<Character>();
				if (IsValidMonster(componentInParent, out var ai) && ShouldReactToMonster(componentInParent, ai, position))
				{
					HandleMonster(componentInParent, position);
					ClearHits(num);
					return;
				}
			}
		}
		ClearHits(num);
	}

	private bool IsValidMonster(Character character, out BaseAI ai)
	{
		ai = null;
		if ((Object)(object)character == (Object)null)
		{
			return false;
		}
		if (character.IsPlayer() || character.IsDead() || character.IsFlying())
		{
			return false;
		}
		ai = character.GetBaseAI();
		if ((Object)(object)ai == (Object)null || ai.IsSleeping())
		{
			return false;
		}
		string prefabName = Utils.GetPrefabName(((Component)character).gameObject);
		return _allowedMonsterCache.Contains(prefabName);
	}

	private bool ShouldReactToMonster(Character character, BaseAI ai, Vector3 doorPosition)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		if (RequireMonsterTarget)
		{
			Character targetCreature = ai.GetTargetCreature();
			if ((Object)(object)targetCreature == (Object)null || targetCreature.IsDead())
			{
				return false;
			}
		}
		if (!RequireMovingOrFacingDoor)
		{
			return true;
		}
		Vector3 val = doorPosition - ((Component)character).transform.position;
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			return true;
		}
		((Vector3)(ref val)).Normalize();
		Vector3 moveDir = character.GetMoveDir();
		moveDir.y = 0f;
		if (((Vector3)(ref moveDir)).sqrMagnitude > 0.01f)
		{
			((Vector3)(ref moveDir)).Normalize();
			if (Vector3.Dot(moveDir, val) >= MinFacingDot)
			{
				return true;
			}
		}
		Vector3 forward = ((Component)character).transform.forward;
		forward.y = 0f;
		if (((Vector3)(ref forward)).sqrMagnitude < 0.01f)
		{
			return false;
		}
		((Vector3)(ref forward)).Normalize();
		return Vector3.Dot(forward, val) >= MinFacingDot;
	}

	private static bool IsDoorProtectedByPrivateArea(Vector3 point)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Invalid comparison between Unknown and I4
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		List<PrivateArea> allAreas = PrivateArea.m_allAreas;
		if (allAreas == null)
		{
			return false;
		}
		for (int i = 0; i < allAreas.Count; i++)
		{
			PrivateArea val = allAreas[i];
			if (!((Object)(object)val == (Object)null) && (int)val.m_ownerFaction <= 0 && val.IsEnabled() && val.IsInside(point, 0f))
			{
				return true;
			}
		}
		return false;
	}

	private void NotifyNearbyPlayer(Character monster, Vector3 doorPosition)
	{
		//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_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)
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null))
		{
			Vector3 val = ((Component)localPlayer).transform.position - doorPosition;
			if (!(((Vector3)(ref val)).sqrMagnitude > 324f))
			{
				((Character)localPlayer).Message((MessageType)1, monster.m_name + " forced the door open!", 0, (Sprite)null);
			}
		}
	}

	private void HandleMonster(Character character, Vector3 doorPosition)
	{
		//IL_0038: 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)
		if (IgnoreKeyedDoors && (Object)(object)_door.m_keyItem != (Object)null)
		{
			return;
		}
		if (RespectPrivateArea && _door.m_checkGuardStone && IsDoorProtectedByPrivateArea(doorPosition))
		{
			if (MakeAttackTargetIfBlockedByWard)
			{
				MakeDoorAttackTarget();
			}
		}
		else if (AllowOpening)
		{
			OpenDoor(character, doorPosition);
		}
	}

	private void OpenDoor(Character character, Vector3 doorPosition)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_doorView == (Object)null || !_doorView.IsValid())
		{
			return;
		}
		ZDO zDO = _doorView.GetZDO();
		if (zDO != null && zDO.GetInt(ZDOVars.s_state, 0) == 0)
		{
			Vector3 val = ((Component)character).transform.position - doorPosition;
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = -_doorTransform.forward;
			}
			((Vector3)(ref val)).Normalize();
			bool flag = Vector3.Dot(_doorTransform.forward, val) < 0f;
			_doorView.InvokeRPC("UseDoor", new object[1] { flag });
			NotifyNearbyPlayer(character, doorPosition);
		}
	}

	private void MakeDoorAttackTarget()
	{
		if ((Object)(object)_piece == (Object)null)
		{
			if ((Object)(object)_door != (Object)null)
			{
				_piece = ((Component)_door).GetComponent<Piece>();
			}
			if ((Object)(object)_piece == (Object)null)
			{
				_piece = ((Component)this).GetComponent<Piece>();
			}
		}
		if (!((Object)(object)_piece == (Object)null))
		{
			((StaticTarget)_piece).m_primaryTarget = true;
			((StaticTarget)_piece).m_randomTarget = true;
		}
	}

	private static void ClearHits(int count)
	{
		for (int i = 0; i < count; i++)
		{
			Hits[i] = null;
		}
	}
}
public static class MonsterDoorSensorService
{
	private static readonly List<MonsterDoorSensorRule> Rules = new List<MonsterDoorSensorRule>();

	private static readonly Dictionary<string, MonsterDoorSensorRule> RuleByDoorPrefabName = new Dictionary<string, MonsterDoorSensorRule>(StringComparer.OrdinalIgnoreCase);

	public static void RegisterDefaultRules()
	{
		Rules.Clear();
		RuleByDoorPrefabName.Clear();
		MonsterDoorSensorRule monsterDoorSensorRule = new MonsterDoorSensorRule();
		monsterDoorSensorRule.DoorPrefabNames = new string[8] { "raw_wood_door_bal", "wood_door", "darkwood_gate", "wood_gate", "ashwood_door", "hardwood_door_bal", "wood_gate_cage_bal", "wood_plot_gate_bal" };
		monsterDoorSensorRule.AllowedMonsterPrefabNames = new string[39]
		{
			"Goblin", "GoblinShaman", "Draugr", "Draugr_Elite", "Skeleton_Poison", "Skeleton", "Surtling", "Ghost", "Skeleton_NoArcher", "Draugr_Ranged",
			"Greydwarf", "Greydwarf_Shaman", "Greydwarf_Elite", "Dverger", "DvergerMage", "DvergerMageFire", "DvergerMageIce", "DvergerMageSupport", "Dverger_event", "DvergerMage_event",
			"DvergerMageFire_event", "DvergerMageIce_event", "DvergerMageSupport_event", "Fenring", "Fenring_Cultist", "Fenring_Brute_bal", "LostSoul_bal", "Frostbjorn_bal", "GhostYagluth_bal", "Greydwarf_Crusher_bal",
			"Greydwarf_Frozen_bal", "Greydwarf_Moss_bal", "Greydwarf_Scorched_bal", "Charred_Mage", "Charred_Melee", "Charred_Melee_Dyrnwyn", "Charred_Melee_Fader", "Charred_Twitcher", "Charred_Archer"
		};
		monsterDoorSensorRule.DetectRadius = 2.8f;
		monsterDoorSensorRule.CheckInterval = 0.35f;
		monsterDoorSensorRule.AllowOpening = true;
		monsterDoorSensorRule.RespectPrivateArea = true;
		monsterDoorSensorRule.MakeAttackTargetIfBlockedByWard = true;
		monsterDoorSensorRule.IgnoreKeyedDoors = true;
		monsterDoorSensorRule.RequireMonsterTarget = true;
		monsterDoorSensorRule.RequireMovingOrFacingDoor = true;
		monsterDoorSensorRule.MinFacingDot = 0.35f;
		AddRule(monsterDoorSensorRule);
		monsterDoorSensorRule = new MonsterDoorSensorRule();
		monsterDoorSensorRule.DoorPrefabNames = new string[10] { "iron_gate", "wood_iron_gate_large_bal", "wood_gate_large_bal", "plate_gate_bal", "flametal_gate", "dverger_gate_bal", "corewood_gate_large_bal", "copper_dropgate_large_bal", "bronze_gate_left_bal", "bronze_gate_right_bal" };
		monsterDoorSensorRule.AllowedMonsterPrefabNames = new string[7] { "Troll", "GoblinBrute", "Fenring", "Fenring_Cultist", "Fenring_Brute_bal", "Greydwarf_Crusher_bal", "Frostbjorn_bal" };
		monsterDoorSensorRule.DetectRadius = 3.2f;
		monsterDoorSensorRule.CheckInterval = 0.4f;
		monsterDoorSensorRule.AllowOpening = true;
		monsterDoorSensorRule.RespectPrivateArea = true;
		monsterDoorSensorRule.MakeAttackTargetIfBlockedByWard = true;
		monsterDoorSensorRule.IgnoreKeyedDoors = true;
		monsterDoorSensorRule.RequireMonsterTarget = true;
		monsterDoorSensorRule.RequireMovingOrFacingDoor = true;
		monsterDoorSensorRule.MinFacingDot = 0.25f;
		AddRule(monsterDoorSensorRule);
	}

	private static void AddRule(MonsterDoorSensorRule rule)
	{
		if (rule == null)
		{
			return;
		}
		Rules.Add(rule);
		if (rule.DoorPrefabNames == null)
		{
			return;
		}
		for (int i = 0; i < rule.DoorPrefabNames.Length; i++)
		{
			string text = rule.DoorPrefabNames[i];
			if (!string.IsNullOrEmpty(text))
			{
				RuleByDoorPrefabName[text] = rule;
			}
		}
	}

	public static void ApplyToZNetScene()
	{
		ZNetScene instance = ZNetScene.instance;
		if ((Object)(object)instance == (Object)null || instance.m_prefabs == null)
		{
			return;
		}
		List<GameObject> prefabs = instance.m_prefabs;
		for (int i = 0; i < prefabs.Count; i++)
		{
			GameObject val = prefabs[i];
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			MonsterDoorSensorRule monsterDoorSensorRule = FindRuleForPrefab(((Object)val).name);
			if (monsterDoorSensorRule == null)
			{
				continue;
			}
			Door componentInChildren = val.GetComponentInChildren<Door>();
			if (!((Object)(object)componentInChildren == (Object)null))
			{
				MonsterDoorSensor monsterDoorSensor = val.GetComponent<MonsterDoorSensor>();
				if ((Object)(object)monsterDoorSensor == (Object)null)
				{
					monsterDoorSensor = val.AddComponent<MonsterDoorSensor>();
				}
				ApplyRule(monsterDoorSensor, monsterDoorSensorRule);
				Debug.Log((object)("[MonsterDoorSensor] Applied to prefab: " + ((Object)val).name));
			}
		}
	}

	private static void ApplyRule(MonsterDoorSensor sensor, MonsterDoorSensorRule rule)
	{
		sensor.AllowedMonsterPrefabNames = rule.AllowedMonsterPrefabNames;
		sensor.DetectRadius = rule.DetectRadius;
		sensor.CheckInterval = rule.CheckInterval;
		sensor.AllowOpening = rule.AllowOpening;
		sensor.RespectPrivateArea = rule.RespectPrivateArea;
		sensor.MakeAttackTargetIfBlockedByWard = rule.MakeAttackTargetIfBlockedByWard;
		sensor.IgnoreKeyedDoors = rule.IgnoreKeyedDoors;
		sensor.RequireMonsterTarget = rule.RequireMonsterTarget;
		sensor.RequireMovingOrFacingDoor = rule.RequireMovingOrFacingDoor;
		sensor.MinFacingDot = rule.MinFacingDot;
	}

	private static MonsterDoorSensorRule FindRuleForPrefab(string prefabName)
	{
		if (string.IsNullOrEmpty(prefabName))
		{
			return null;
		}
		RuleByDoorPrefabName.TryGetValue(prefabName, out var value);
		return value;
	}
}
public sealed class MonsterDoorSensorRule
{
	public string[] DoorPrefabNames;

	public string[] AllowedMonsterPrefabNames;

	public float DetectRadius = 2f;

	public float CheckInterval = 0.35f;

	public bool AllowOpening = true;

	public bool RespectPrivateArea = true;

	public bool MakeAttackTargetIfBlockedByWard = true;

	public bool IgnoreKeyedDoors = true;

	public bool RequireMonsterTarget = true;

	public bool RequireMovingOrFacingDoor = true;

	public float MinFacingDot = 0.35f;
}
internal static class Compatibility
{
	private const string AlienID = "ZenDragon.ZenWorldSettings";

	private static bool _isLoaded;

	private static bool _Check;

	public static bool IsLoaded()
	{
		if (!_Check)
		{
			_isLoaded = Chainloader.PluginInfos.ContainsKey("ZenDragon.ZenWorldSettings");
			if (_isLoaded)
			{
				Debug.Log((object)"Amazing Nature: Using ZenWorldSettings, Disabled Crypt Key consume");
			}
			_Check = true;
		}
		return _isLoaded;
	}
}
internal static class Compatibility2
{
	public const string AlienID = "ZenDragon.ZenCombat";

	private static bool _isLoaded;

	private static bool _Check;

	public static bool IsLoaded()
	{
		if (!_Check)
		{
			_isLoaded = Chainloader.PluginInfos.ContainsKey("ZenDragon.ZenCombat");
			if (_isLoaded)
			{
				Debug.Log((object)"Amazing Nature: Using ZenDragon.ZenCombat, Disabled Parry/Block changes");
			}
			_Check = true;
		}
		return _isLoaded;
	}
}
namespace UpgradeWorld
{
	public class CommandRegistration
	{
		public string name = "";

		public string description = "";

		public string[] commands = new string[0];

		public void AddCommand()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			new ConsoleCommand(name, description, (ConsoleEvent)delegate(ConsoleEventArgs args)
			{
				string[] array = commands;
				foreach (string text in array)
				{
					args.Context.TryRunCommand(text, false, false);
				}
			}, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}
	}
	[HarmonyPatch(typeof(Terminal), "InitTerminal")]
	public static class Upgrade
	{
		private static List<CommandRegistration> registrations = new List<CommandRegistration>();

		public const string GUID = "upgrade_world";

		public static void Register(string name, string description, params string[] commands)
		{
			if (Chainloader.PluginInfos.ContainsKey("upgrade_world"))
			{
				registrations.Add(new CommandRegistration
				{
					name = name,
					description = description,
					commands = commands
				});
			}
		}

		private static void Postfix()
		{
			foreach (CommandRegistration registration in registrations)
			{
				registration.AddCommand();
			}
		}
	}
}
namespace YourModNamespace.Portals
{
	[HarmonyPatch]
	public static class PortalRestrictionPatches
	{
		[HarmonyPatch]
		public static class AddCustomPortalsToGamePatch
		{
			private static IEnumerable<MethodInfo> TargetMethods()
			{
				yield return AccessTools.DeclaredMethod(typeof(Game), "Awake", (Type[])null, (Type[])null);
			}

			private static void Prefix(Game __instance)
			{
				if ((Object)(object)__instance == (Object)null || __instance.PortalPrefabHash == null)
				{
					return;
				}
				foreach (int extraPortalPrefabHash in ExtraPortalPrefabHashes)
				{
					if (!__instance.PortalPrefabHash.Contains(extraPortalPrefabHash))
					{
						__instance.PortalPrefabHash.Add(extraPortalPrefabHash);
					}
				}
			}
		}

		private static PortalItemRules _currentRules;

		public static readonly HashSet<int> ExtraPortalPrefabHashes = new HashSet<int>
		{
			BalrondHashCompat.StableHash("portal_StoneSmall_bal"),
			BalrondHashCompat.StableHash("portal_NatureSmall_bal")
		};

		[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
		[HarmonyPrefix]
		private static void TeleportWorld_UpdatePortal_Prefix(TeleportWorld __instance)
		{
			_currentRules = PortalRuleRegistry.GetRulesForPortal(__instance);
		}

		[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
		[HarmonyPostfix]
		private static void TeleportWorld_UpdatePortal_Postfix()
		{
			_currentRules = null;
		}

		[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
		[HarmonyPrefix]
		private static void TeleportWorld_Teleport_Prefix(TeleportWorld __instance)
		{
			_currentRules = PortalRuleRegistry.GetRulesForPortal(__instance);
		}

		[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
		[HarmonyPostfix]
		private static void TeleportWorld_Teleport_Postfix()
		{
			_currentRules = null;
		}

		public static void SetCurrentRulesFromNearestPortal()
		{
			//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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			Collider[] array = Physics.OverlapSphere(position, 2f);
			TeleportWorld val = null;
			float num = 5f;
			Collider[] array2 = array;
			foreach (Collider val2 in array2)
			{
				if ((Object)(object)val2 == (Object)null || (Object)(object)((Component)val2).gameObject == (Object)null)
				{
					continue;
				}
				TeleportWorldTrigger component = ((Component)val2).gameObject.GetComponent<TeleportWorldTrigger>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				TeleportWorld componentInParent = ((Component)component).GetComponentInParent<TeleportWorld>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					Vector3 val3 = ((Component)val2).transform.position - position;
					float num2 = val3.x * val3.x + val3.y * val3.y + val3.z * val3.z;
					if (num2 < num)
					{
						val = componentInParent;
						num = num2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				_currentRules = PortalRuleRegistry.GetRulesForPortal(val);
			}
		}

		public static void ClearCurrentRules()
		{
			_currentRules = null;
		}

		[HarmonyPatch(typeof(Inventory), "IsTeleportable")]
		[HarmonyPostfix]
		[HarmonyPriority(600)]
		private static void Inventory_IsTeleportable_Postfix(Inventory __instance, ref bool __result)
		{
			if (_currentRules != null)
			{
				__result = PortalRuleEvaluator.IsInventoryAllowed(__instance, _currentRules);
			}
		}
	}
	public sealed class PortalItemRules
	{
		public readonly RuleSet Whitelist = new RuleSet();

		public readonly RuleSet Blacklist = new RuleSet();

		public bool UseWhitelist = true;

		public bool UseBlacklist = true;
	}
	public sealed class RuleSet
	{
		public readonly HashSet<ItemType> ItemTypes = new HashSet<ItemType>();

		public readonly HashSet<string> PrefabNames = new HashSet<string>();

		public readonly HashSet<int> PrefabHashes = new HashSet<int>();

		public readonly HashSet<string> ItemNames = new HashSet<string>();

		public readonly HashSet<bool> IsTeleportableValues = new HashSet<bool>();

		public bool Matches(ItemData item)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (item == null || item.m_shared == null)
			{
				return false;
			}
			if (ItemTypes.Contains(item.m_shared.m_itemType))
			{
				return true;
			}
			if (!string.IsNullOrEmpty(item.m_shared.m_name) && ItemNames.Contains(item.m_shared.m_name))
			{
				return true;
			}
			if (IsTeleportableValues.Contains(item.m_shared.m_teleportable))
			{
				return true;
			}
			GameObject dropPrefab = item.m_dropPrefab;
			if ((Object)(object)dropPrefab != (Object)null)
			{
				string text = PortalRuleRegistry.CleanPrefabName(((Object)dropPrefab).name);
				if (PrefabNames.Contains(text))
				{
					return true;
				}
				if (PrefabHashes.Contains(StringExtensionMethods.GetStableHashCode(text)))
				{
					return true;
				}
			}
			return false;
		}
	}
	public static class PortalRuleRegistry
	{
		private static bool _initialized;

		public static readonly Dictionary<string, PortalItemRules> RulesByPortalPrefabName = new Dictionary<string, PortalItemRules>();

		public static readonly Dictionary<int, PortalItemRules> RulesByPortalPrefabHash = new Dictionary<int, PortalItemRules>();

		public static void InitializeOnce()
		{
			if (!_initialized)
			{
				_initialized = true;
				RulesByPortalPrefabName.Clear();
				RulesByPortalPrefabHash.Clear();
				RegisterDefaultRules();
			}
		}

		private static void RegisterDefaultRules()
		{
			RegisterTrophyPortal();
			RegisterOrePortal();
			RegisterProgressionPortal();
			RegisterEverythingExceptDragonEggPortal();
			RegisterHeavyOnlyPortal();
			RegisterEverythingPortal();
			RegisterBossTrophyPortal();
			RegisterItemNamePortal();
			RegisterHashPortal();
			RegisterVanillaOnlyPortal();
		}

		private static void RegisterTrophyPortal()
		{
			PortalRuleGenerator.ForPortal("portal_trophy").WhitelistTeleportable(isTeleportable: true).WhitelistItemType((ItemType)13)
				.Register();
		}

		private static void RegisterOrePortal()
		{
			PortalRuleGenerator.ForPortal("portal_ore").WhitelistPrefabName("CopperOre").WhitelistPrefabName("TinOre")
				.WhitelistPrefabName("IronScrap")
				.WhitelistPrefabName("SilverOre")
				.WhitelistPrefabName("BlackMetalScrap")
				.Register();
		}

		private static void RegisterProgressionPortal()
		{
			PortalRuleGenerator.ForPortal("portal_progression").WhitelistPrefabName("CryptKey").WhitelistPrefabName("Wishbone")
				.WhitelistPrefabName("DragonEgg")
				.WhitelistPrefabName("YmirRemains")
				.Register();
		}

		private static void RegisterEverythingExceptDragonEggPortal()
		{
			PortalRuleGenerator.ForPortal("portal_no_egg").WhitelistTeleportable(isTeleportable: true).WhitelistTeleportable(isTeleportable: false)
				.BlacklistPrefabName("DragonEgg")
				.Register();
		}

		private static void RegisterHeavyOnlyPortal()
		{
			PortalRuleGenerator.ForPortal("portal_heavy").WhitelistTeleportable(isTeleportable: false).Register();
		}

		private static void RegisterEverythingPortal()
		{
			PortalRuleGenerator.ForPortal("portal_everything").WhitelistTeleportable(isTeleportable: true).WhitelistTeleportable(isTeleportable: false)
				.Register();
		}

		private static void RegisterBossTrophyPortal()
		{
			PortalRuleGenerator.ForPortal("portal_boss").WhitelistItemType((ItemType)13).BlacklistPrefabName("TrophyDeer")
				.BlacklistPrefabName("TrophyBoar")
				.BlacklistPrefabName("TrophyNeck")
				.Register();
		}

		private static void RegisterItemNamePortal()
		{
			PortalRuleGenerator.ForPortal("portal_itemname").WhitelistItemName("$item_dragonegg").WhitelistItemName("$item_wishbone")
				.Register();
		}

		private static void RegisterHashPortal()
		{
			PortalRuleGenerator.ForPortal("portal_hash").WhitelistPrefabHash(StringExtensionMethods.GetStableHashCode("CopperOre")).WhitelistPrefabHash(StringExtensionMethods.GetStableHashCode("TinOre"))
				.WhitelistPrefabHash(StringExtensionMethods.GetStableHashCode("IronScrap"))
				.Register();
		}

		private static void RegisterVanillaOnlyPortal()
		{
			PortalRuleGenerator.ForPortal("portal_vanilla_only").WhitelistTeleportable(isTeleportable: true).Register();
		}

		public static PortalItemRules GetRulesForPortal(TeleportWorld portal)
		{
			if ((Object)(object)portal == (Object)null || (Object)(object)((Component)portal).gameObject == (Object)null)
			{
				return null;
			}
			string text = CleanPrefabName(((Object)((Component)portal).gameObject).name);
			if (RulesByPortalPrefabName.TryGetValue(text, out var value))
			{
				return value;
			}
			int stableHashCode = StringExtensionMethods.GetStableHashCode(text);
			if (RulesByPortalPrefabHash.TryGetValue(stableHashCode, out value))
			{
				return value;
			}
			return null;
		}

		public static void RegisterPortalByName(string portalPrefabName, PortalItemRules rules, bool addToGamePortalHashList)
		{
			if (!string.IsNullOrEmpty(portalPrefabName) && rules != null)
			{
				string text = CleanPrefabName(portalPrefabName);
				RulesByPortalPrefabName[text] = rules;
				int stableHashCode = StringExtensionMethods.GetStableHashCode(text);
				RulesByPortalPrefabHash[stableHashCode] = rules;
				if (addToGamePortalHashList)
				{
					PortalRestrictionPatches.ExtraPortalPrefabHashes.Add(stableHashCode);
				}
			}
		}

		public static void RegisterPortalByHash(int portalPrefabHash, PortalItemRules rules, bool addToGamePortalHashList)
		{
			if (rules != null)
			{
				RulesByPortalPrefabHash[portalPrefabHash] = rules;
				if (addToGamePortalHashList)
				{
					PortalRestrictionPatches.ExtraPortalPrefabHashes.Add(portalPrefabHash);
				}
			}
		}

		public static string CleanPrefabName(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return name;
			}
			string text = Utils.GetPrefabName(name);
			if (string.IsNullOrEmpty(text))
			{
				text = name;
			}
			return text;
		}
	}
	public static class PortalRuleEvaluator
	{
		public static bool IsInventoryAllowed(Inventory inventory, PortalItemRules rules)
		{
			if (inventory == null)
			{
				return true;
			}
			List<ItemData> allItems = inventory.GetAllItems();
			for (int i = 0; i < allItems.Count; i++)
			{
				if (!IsItemAllowed(allItems[i], rules))
				{
					return false;
				}
			}
			return true;
		}

		public static bool IsItemAllowed(ItemData item, PortalItemRules rules)
		{
			if (item == null || item.m_shared == null)
			{
				return true;
			}
			if (rules == null)
			{
				return item.m_shared.m_teleportable;
			}
			if (rules.UseBlacklist && rules.Blacklist.Matches(item))
			{
				return false;
			}
			if (rules.UseWhitelist)
			{
				return rules.Whitelist.Matches(item);
			}
			return item.m_shared.m_teleportable;
		}
	}
	public sealed class PortalRuleGenerator
	{
		private readonly string _portalPrefabName;

		private readonly PortalItemRules _rules = new PortalItemRules();

		private bool _addToGamePortalHashList = true;

		private PortalRuleGenerator(string portalPrefabName)
		{
			_portalPrefabName = portalPrefabName;
		}

		public static PortalRuleGenerator ForPortal(string portalPrefabName)
		{
			return new PortalRuleGenerator(portalPrefabName);
		}

		public PortalRuleGenerator AddPortalHashToGameList(bool value)
		{
			_addToGamePortalHashList = value;
			return this;
		}

		public PortalRuleGenerator UseWhitelist(bool value)
		{
			_rules.UseWhitelist = value;
			return this;
		}

		public PortalRuleGenerator UseBlacklist(bool value)
		{
			_rules.UseBlacklist = value;
			return this;
		}

		public PortalRuleGenerator WhitelistItemType(ItemType itemType)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			_rules.Whitelist.ItemTypes.Add(itemType);
			return this;
		}

		public PortalRuleGenerator BlacklistItemType(ItemType itemType)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			_rules.Blacklist.ItemTypes.Add(itemType);
			return this;
		}

		public PortalRuleGenerator WhitelistPrefabName(string prefabName)
		{
			AddPrefabName(_rules.Whitelist, prefabName);
			return this;
		}

		public PortalRuleGenerator BlacklistPrefabName(string prefabName)
		{
			AddPrefabName(_rules.Blacklist, prefabName);
			return this;
		}

		public PortalRuleGenerator WhitelistPrefabHash(int prefabHash)
		{
			_rules.Whitelist.PrefabHashes.Add(prefabHash);
			return this;
		}

		public PortalRuleGenerator BlacklistPrefabHash(int prefabHash)
		{
			_rules.Blacklist.PrefabHashes.Add(prefabHash);
			return this;
		}

		public PortalRuleGenerator WhitelistItemName(string itemName)
		{
			if (!string.IsNullOrEmpty(itemName))
			{
				_rules.Whitelist.ItemNames.Add(itemName);
			}
			return this;
		}

		public PortalRuleGenerator BlacklistItemName(string itemName)
		{
			if (!string.IsNullOrEmpty(itemName))
			{
				_rules.Blacklist.ItemNames.Add(itemName);
			}
			return this;
		}

		public PortalRuleGenerator WhitelistTeleportable(bool isTeleportable)
		{
			_rules.Whitelist.IsTeleportableValues.Add(isTeleportable);
			return this;
		}

		public PortalRuleGenerator BlacklistTeleportable(bool isTeleportable)
		{
			_rules.Blacklist.IsTeleportableValues.Add(isTeleportable);
			return this;
		}

		public PortalItemRules Build()
		{
			return _rules;
		}

		public PortalItemRules Register()
		{
			PortalRuleRegistry.RegisterPortalByName(_portalPrefabName, _rules, _addToGamePortalHashList);
			return _rules;
		}

		private static void AddPrefabName(RuleSet ruleSet, string prefabName)
		{
			if (ruleSet != null && !string.IsNullOrEmpty(prefabName))
			{
				string text = PortalRuleRegistry.CleanPrefabName(prefabName);
				ruleSet.PrefabNames.Add(text);
				ruleSet.PrefabHashes.Add(StringExtensionMethods.GetStableHashCode(text));
			}
		}
	}
}
namespace BalrondNature
{
	public class BalrondTranslator
	{
		public static Dictionary<string, Dictionary<string, string>> translations = new Dictionary<string, Dictionary<string, string>>();

		public static Dictionary<string, string> getLanguage(string language)
		{
			if (string.IsNullOrEmpty(language))
			{
				return null;
			}
			if (translations.TryGetValue(language, out var value))
			{
				return value;
			}
			return null;
		}
	}
	[HarmonyPatch]
	public static class DeepNorthRegion
	{
		[HarmonyPatch(typeof(EnvMan), "GetBiome")]
		private static class EnvMan_GetBiome_Patch
		{
			private static bool Prefix(EnvMan __instance, ref Biome __result)
			{
				//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_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: 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_009f: Expected I4, but got Unknown
				Camera mainCamera = Utils.GetMainCamera();
				if ((Object)(object)mainCamera == (Object)null)
				{
					__result = (Biome)0;
					return false;
				}
				Vector3 position = ((Component)mainCamera).transform.position;
				Heightmap val = GetCachedHeightmap(__instance);
				if ((Object)(object)val == (Object)null || !val.IsPointInside(position, 0f))
				{
					val = Heightmap.FindHeightmap(position);
					SetCachedHeightmap(__instance, val);
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					__result = (Biome)0;
					return false;
				}
				bool flag = DeepNorthZone.IsAshlandsOrDeepNorthArea(position.x, position.z);
				__result = (Biome)(int)val.GetBiome(position, __instance.m_oceanLevelEnvCheckAshlandsDeepnorth, flag);
				return false;
			}
		}

		[HarmonyPatch(typeof(EnvMan), "UpdateEnvironment")]
		private static class EnvMan_UpdateEnvironment_Patch
		{
			private static bool Prefix(EnvMan __instance, long sec, Biome biome)
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: 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_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
				string text = CallGetEnvironmentOverride(__instance);
				if (!string.IsNullOrEmpty(text))
				{
					SetEnvironmentPeriod(__instance, -1L);
					SetCurrentBiomeField(__instance, __instance.GetCurrentBiome());
					CallQueueEnvironment(__instance, text);
					return false;
				}
				Camera mainCamera = Utils.GetMainCamera();
				if ((Object)(object)mainCamera == (Object)null)
				{
					return false;
				}
				long num = sec / __instance.m_environmentDuration;
				Vector3 position = ((Component)mainCamera).transform.position;
				bool flag = WorldGenerator.IsAshlands(position.x, position.z);
				bool flag2 = DeepNorthZone.ShouldUseOverrideEnvironment(position.x, position.z, biome);
				bool flag3 = flag || flag2;
				__instance.m_dirLight.renderMode = (LightRenderMode)((!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !((Character)Player.m_localPlayer).InInterior()) ? 1 : 2);
				if (GetEnvironmentPeriod(__instance) == num && GetCurrentBiomeField(__instance) == biome && flag3 == GetInAshlandsOrDeepnorth(__instance))
				{
					return false;
				}
				SetEnvironmentPeriod(__instance, num);
				SetCurrentBiomeField(__instance, biome);
				SetInAshlandsOrDeepnorth(__instance, flag3);
				State state = Random.state;
				Random.InitState((int)num);
				List<EnvEntry> list = CallGetAvailableEnvironments(__instance, biome);
				if (list != null && list.Count > 0)
				{
					EnvSetup val = CallSelectWeightedEnvironment(__instance, list);
					foreach (EnvEntry item in list)
					{
						if (item.m_ashlandsOverride && flag)
						{
							val = item.m_env;
						}
						if (item.m_deepnorthOverride && flag2)
						{
							val = item.m_env;
						}
					}
					if (val != null)
					{
						CallQueueEnvironment(__instance, val);
					}
				}
				Random.state = state;
				return false;
			}
		}

		[HarmonyPatch(typeof(Minimap), "GetMaskColor")]
		private static class Minimap_GetMaskColor_Patch
		{
			private static void Postfix(float wx, float wy, float height, Biome biome, ref Color __result)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				__result = ApplyDeepNorthOceanMask(__result, wx, wy, height, biome);
			}
		}

		[HarmonyPatch(typeof(Minimap), "GetPixelColor")]
		private static class Minimap_GetPixelColor_Patch
		{
			private static void Postfix(Biome biome, ref Color __result)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0004: Invalid comparison between Unknown and I4
				//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)
				if ((int)biome == 64)
				{
					__result = DeepNorthMapColor;
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "GenerateWorldMap")]
		private static class Minimap_GenerateWorldMap_Patch
		{
			private static void Postfix(Minimap __instance)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Invalid comparison between Unknown and I4
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Invalid comparison between Unknown and I4
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				Texture2D val = (Texture2D)FI_Minimap_m_mapTexture.GetValue(__instance);
				if ((Object)(object)val == (Object)null || WorldGenerator.instance == null)
				{
					return;
				}
				int textureSize = __instance.m_textureSize;
				int num = textureSize / 2;
				float pixelSize = __instance.m_pixelSize;
				float num2 = pixelSize / 2f;
				Color[] pixels = val.GetPixels();
				for (int i = 0; i < textureSize; i++)
				{
					for (int j = 0; j < textureSize; j++)
					{
						float num3 = (float)(j - num) * pixelSize + num2;
						float num4 = (float)(i - num) * pixelSize + num2;
						Biome biome = WorldGenerator.instance.GetBiome(num3, num4, 0.02f, false);
						if (DeepNorthZone.IsAreaOrNearbyOcean(num3, num4, biome))
						{
							int num5 = i * textureSize + j;
							if ((int)biome == 64)
							{
								pixels[num5] = Color.Lerp(pixels[num5], DeepNorthMapColor, 0.55f);
							}
							else if ((int)biome == 256)
							{
								pixels[num5] = GetDeepNorthOceanTintedColor(pixels[num5], num3, num4);
							}
						}
					}
				}
				val.SetPixels(pixels);
				val.Apply();
			}
		}

		public static readonly Color DeepNorthMapColor = new Color(0.82f, 0.9f, 1f, 1f);

		public static readonly Color DeepNorthOceanColor = new Color(0.56f, 0.72f, 0.96f, 1f);

		public static readonly Color DeepNorthIceColor = new Color(0.82f, 0.92f, 1f, 1f);

		private static readonly BindingFlags InstNonPublic = BindingFlags.Instance | BindingFlags.NonPublic;

		private static readonly FieldInfo FI_EnvMan_m_cachedHeightmap = typeof(EnvMan).GetField("m_cachedHeightmap", InstNonPublic);

		private static readonly FieldInfo FI_EnvMan_m_currentBiome = typeof(EnvMan).GetField("m_currentBiome", InstNonPublic);

		private static readonly FieldInfo FI_EnvMan_m_inAshlandsOrDeepnorth = typeof(EnvMan).GetField("m_inAshlandsOrDeepnorth", InstNonPublic);

		private static readonly FieldInfo FI_EnvMan_m_environmentPeriod = typeof(EnvMan).GetField("m_environmentPeriod", InstNonPublic);

		private static readonly MethodInfo MI_EnvMan_GetEnvironmentOverride = typeof(EnvMan).GetMethod("GetEnvironmentOverride", InstNonPublic);

		private static readonly MethodInfo MI_EnvMan_GetAvailableEnvironments = typeof(EnvMan).GetMethod("GetAvailableEnvironments", InstNonPublic);

		private static readonly MethodInfo MI_EnvMan_SelectWeightedEnvironment = typeof(EnvMan).GetMethod("SelectWeightedEnvironment", InstNonPublic);

		private static readonly MethodInfo MI_EnvMan_QueueEnvironment_String = typeof(EnvMan).GetMethod("QueueEnvironment", InstNonPublic, null, new Type[1] { typeof(string) }, null);

		private static readonly MethodInfo MI_EnvMan_QueueEnvironment_EnvSetup = typeof(EnvMan).GetMethod("QueueEnvironment", InstNonPublic, null, new Type[1] { typeof(EnvSetup) }, null);

		private static readonly FieldInfo FI_Minimap_m_mapTexture = typeof(Minimap).GetField("m_mapTexture", InstNonPublic);

		public static Color GetDeepNorthOceanTintedColor(Color baseColor, float x, float z)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0018: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			float oceanBlend = DeepNorthZone.GetOceanBlend(x, z);
			if (oceanBlend <= 0f)
			{
				return baseColor;
			}
			Color val = Color.Lerp(baseColor, DeepNorthOceanColor, Mathf.Clamp01(oceanBlend * 1.15f));
			float num = Mathf.Clamp01(Mathf.InverseLerp(0.35f, 1f, oceanBlend));
			return Color.Lerp(val, DeepNorthIceColor, num * 0.55f);
		}

		public static Color ApplyDeepNorthOceanMask(Color originalMask, float x, float z, float height, Biome biome)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0080: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (height >= 30f)
			{
				return originalMask;
			}
			if ((int)biome != 256 && (int)biome != 64)
			{
				return originalMask;
			}
			float oceanBlend = DeepNorthZone.GetOceanBlend(x, z);
			if (oceanBlend <= 0f)
			{
				return originalMask;
			}
			originalMask.b = Mathf.Max(originalMask.b, oceanBlend * 0.45f);
			originalMask.a = Mathf.Max(originalMask.a, oceanBlend * 0.15f);
			return originalMask;
		}

		private static Heightmap GetCachedHeightmap(EnvMan envMan)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (Heightmap)FI_EnvMan_m_cachedHeightmap.GetValue(envMan);
		}

		private static void SetCachedHeightmap(EnvMan envMan, Heightmap heightmap)
		{
			FI_EnvMan_m_cachedHeightmap.SetValue(envMan, heightmap);
		}

		private static Biome GetCurrentBiomeField(EnvMan envMan)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return (Biome)FI_EnvMan_m_currentBiome.GetValue(envMan);
		}

		private static void SetCurrentBiomeField(EnvMan envMan, Biome biome)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			FI_EnvMan_m_currentBiome.SetValue(envMan, biome);
		}

		private static bool GetInAshlandsOrDeepnorth(EnvMan envMan)
		{
			return (bool)FI_EnvMan_m_inAshlandsOrDeepnorth.GetValue(envMan);
		}

		private static void SetInAshlandsOrDeepnorth(EnvMan envMan, bool value)
		{
			FI_EnvMan_m_inAshlandsOrDeepnorth.SetValue(envMan, value);
		}

		private static long GetEnvironmentPeriod(EnvMan envMan)
		{
			return (long)FI_EnvMan_m_environmentPeriod.GetValue(envMan);
		}

		private static void SetEnvironmentPeriod(EnvMan envMan, long value)
		{
			FI_EnvMan_m_environmentPeriod.SetValue(envMan, value);
		}

		private static string CallGetEnvironmentOverride(EnvMan envMan)
		{
			return (string)MI_EnvMan_GetEnvironmentOverride.Invoke(envMan, null);
		}

		private static List<EnvEntry> CallGetAvailableEnvironments(EnvMan envMan, Biome biome)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return (List<EnvEntry>)MI_EnvMan_GetAvailableEnvironments.Invoke(envMan, new object[1] { biome });
		}

		private static EnvSetup CallSelectWeightedEnvironment(EnvMan envMan, List<EnvEntry> environments)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			return (EnvSetup)MI_EnvMan_SelectWeightedEnvironment.Invoke(envMan, new object[1] { environments });
		}

		private static void CallQueueEnvironment(EnvMan envMan, string name)
		{
			MI_EnvMan_QueueEnvironment_String.Invoke(envMan, new object[1] { name });
		}

		private static void CallQueueEnvironment(EnvMan envMan, EnvSetup env)
		{
			MI_EnvMan_QueueEnvironment_EnvSetup.Invoke(envMan, new object[1] { env });
		}
	}
	internal static class DeepNorthTuning
	{
		public static float MinDistance = 12000f;

		public static float YOffset = 4000f;

		public static float OceanGradientRange = 170f;

		public static float GapRange = 1000f;

		public static float NearbyOceanMargin = 0.75f;

		public static float MainMaskDistance = 1750f;

		public static float SideTaper = 7800f;

		public static float OceanFadeStart = 9750f;

		public static float OceanFadeRange = 1150f;

		public static float CellularLargeStartScale = 0.28f;

		public static int CellularLargeOctaves = 6;

		public static float CellularLargeGain = 0.55f;

		public static float CellularSharpStartScale = 7f;

		public static int CellularSharpOctaves = 4;

		public static float CellularSharpGain = 0.55f;

		public static float CellularSharpPow = 3.5f;

		public static float CellularSharpMul = 2.35f;

		public static float ShelfTarget = 0.2f;

		public static float ShelfBlend = 0.8f;

		public static float MainHeightMul = 1.2f;

		public static float Perlin1 = 0.009f;

		public static float Perlin2 = 0.019f;

		public static float Perlin3 = 0.048f;

		public static float Perlin4 = 0.095f;

		public static float SimplexScale = 0.065f;

		public static float SimplexPow = 1.35f;

		public static float CrackBaseHeight = 0.16f;

		public static float CrackThresholdMin = 0.009f;

		public static float CrackThresholdMax = 0.038f;

		public static float CrackNoiseScale = 0.045f;

		public static float CrackNoiseOffsetX = 5124f;

		public static float CrackNoiseOffsetY = 5000f;

		public static float FbmScale = 0.012f;

		public static int FbmOctaves = 4;

		public static float FbmLacunarity = 2.1f;

		public static float FbmGain = 0.55f;

		public static float BlendMaskMin = 0.62f;

		public static float BlendMaskMax = 1f;

		public static float HeightGateMin = 0.13f;

		public static float HeightGateRange = 0.03f;

		public static float DetailScale1 = 0.09f;

		public static float DetailStrength1 = 0.018f;

		public static float DetailScale2 = 0.35f;

		public static float DetailStrength2 = 0.007f;
	}
	internal static class DeepNorthZone
	{
		public static bool IsCore(float x, float z)
		{
			return WorldGenerator.IsDeepnorth(x, z);
		}

		public static bool IsCore(Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return IsCore(position.x, position.z);
		}

		public static double GetAngleOffset(float x, float z)
		{
			return (double)WorldGenerator.WorldAngle(x, z + DeepNorthTuning.YOffset) * 100.0;
		}

		public static double GetShiftedDistance(float x, float z)
		{
			return DUtils.Length(x, z + DeepNorthTuning.YOffset);
		}

		public static float GetOceanGradient(float x, float z)
		{
			double shiftedDistance = GetShiftedDistance(x, z);
			double angleOffset = GetAngleOffset(x, z);
			return (float)((shiftedDistance - ((double)DeepNorthTuning.MinDistance + angleOffset)) / (double)DeepNorthTuning.OceanGradientRange);
		}

		public static bool IsNearbyOcean(float x, float z)
		{
			return GetOceanGradient(x, z) > 0f - DeepNorthTuning.NearbyOceanMargin;
		}

		public static bool IsNearbyOcean(float x, float z, Biome biome)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			return (int)biome == 256 && IsNearbyOcean(x, z);
		}

		public static bool IsAreaOrNearbyOcean(float x, float z, Biome biome)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return (int)biome == 64 || IsNearbyOcean(x, z, biome);
		}

		public static bool ShouldUseOverrideEnvironment(float x, float z, Biome biome)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return IsAreaOrNearbyOcean(x, z, biome);
		}

		public static bool IsAshlandsOrDeepNorthArea(float x, float z)
		{
			return WorldGenerator.IsAshlands(x, z) || IsCore(x, z) || IsNearbyOcean(x, z);
		}

		public static float GetOceanBlend(float x, float z)
		{
			float oceanGradient = GetOceanGradient(x, z);
			return Mathf.Clamp01(Mathf.InverseLerp(0f - DeepNorthTuning.NearbyOceanMargin, 0.75f, oceanGradient));
		}

		public static double CreateGap(float x, float z)
		{
			double shiftedDistance = GetShiftedDistance(x, z);
			double angleOffset = GetAngleOffset(x, z);
			return DUtils.MathfLikeSmoothStep(0.0, 1.0, DUtils.Clamp01(Math.Abs(shiftedDistance - ((double)DeepNorthTuning.MinDistance + angleOffset)) / (double)DeepNorthTuning.GapRange));
		}

		public static bool ShouldApplyFreezingWater(float x, float z, Biome biome)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return IsAreaOrNearbyOcean(x, z, biome);
		}

		public static bool ShouldApplyFreezingWater(Character character)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null)
			{
				return false;
			}
			if (!character.InWater() && !character.IsSwimming())
			{
				return false;
			}
			if (character.IsDead())
			{
				return false;
			}
			Vector3 position = ((Component)character).transform.position;
			Biome biome = (Biome)0;
			if (WorldGenerator.instance != null)
			{
				biome = WorldGenerator.instance.GetBiome(position.x, position.z, 0.02f, false);
			}
			return ShouldApplyFreezingWater(position.x, position.z, biome);
		}
	}
	internal class VfxList
	{
		public static readonly string[] vfx = new string[56]
		{
			"yggashoot_log_halfDry_bal", "yggashoot_logDry_bal", "DeadTreeLog1_bal", "DeadTreeLogHalf1_bal", "ElderMushroomCapPurple_bal", "ElderMushroomCapYellow_bal", "ElderMushroomCapGreen_bal", "waterbucket_projectile_bal", "vfx_mammothhead_destruction", "vfx_dragonhead_destruction",
			"ElderMushroomCap_bal", "ElderMushroomLog_bal", "Acai_log_bal", "IcedTree_log_bal", "ElderTreeLog_bal", "ElderTreeLogHalf_bal", "vfx_MeteoriteDestroyed_bal", "vfx_MeteoriteDestroyed_large_bal", "radiation1_bal", "radiation2_bal",
			"vfx_wood_ember_stack_destroyed_bal", "Acai_log_half_bal", "Wet_log_bal", "Wet_log_half_bal", "Cypress_log_bal", "Willow_log_bal", "Maple_log_bal", "Oak2_log_bal", "Oak2_log_half_bal", "Poplar_log_bal",
			"YewTreeLog_bal", "vfx_coin_silver_pile_destroyed_bal", "vfx_coin_silver_stack_destroyed_bal", "bow_projectile_blizzard_bal", "bow_projectile_chitin_bal", "bow_projectile_flametal_bal", "bigyggashoot_log_bal", "bigyggashoot_log_half_bal", "bigyggashoot_log_quarter_bal", "stalagmite_ash_destruction_bal",
			"waterSplashAoe_bal", "vfx_taunted_bal", "vfx_Bleeding_bal", "vfx_FreezingWater_bal", "vfx_Sick_bal", "vfx_Fractured_bal", "vfx_Lacerated_bal", "vfx_Punctured_bal", "vfx_Scorched_bal", "vfx_Chilled_bal",
			"vfx_Staticcharge_bal", "vfx_Soulsapped_bal", "vfx_Enfeebled_bal", "vfx_Firstaidkit_bal", "vfx_basalt_hit_bal", "vfx_basalt_destroyed_bal"
		};
	}
	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	public static class DamageConditionsPatch
	{
		private delegate WeakSpot GetWeakSpotDelegate(Character character, short weakSpotIndex);

		private sealed class DebuffProcConfig
		{
			public float DamageThreshold;

			public float BaseProcChance;

			public int StatusEffectHash;
		}

		private static readonly int BleedingStatusHash = BalrondHashCompat.StableHash("SE_Bleeding_bal");

		private static readonly int FracturedStatusHash = BalrondHashCompat.StableHash("SE_Fractured_bal");

		private static readonly int LaceratedStatusHash = BalrondHashCompat.StableHash("SE_Lacerated_bal");

		private static readonly int PuncturedStatusHash = BalrondHashCompat.StableHash("SE_Punctured_bal");

		private static readonly GetWeakSpotDelegate GetWeakSpotFast = AccessTools.MethodDelegate<GetWeakSpotDelegate>(AccessTools.Method(typeof(Character), "GetWeakSpot", new Type[1] { typeof(short) }, (Type[])null), (object)null, true);

		private static readonly FieldRef<Character, float> BackstabTimeRef = AccessTools.FieldRefAccess<Character, float>("m_backstabTime");

		private static readonly Dictionary<DamageType, DebuffProcConfig> ProcConfigs = new Dictionary<DamageType, DebuffProcConfig>
		{
			{
				(DamageType)32,
				new DebuffProcConfig
				{
					DamageThreshold = 12f,
					BaseProcChance = 0.05f,
					StatusEffectHash = BalrondHashCompat.StableHash("SE_Scorched_bal")
				}
			},
			{
				(DamageType)64,
				new DebuffProcConfig
				{
					DamageThreshold = 12f,
					BaseProcChance = 0.05f,
					StatusEffectHash = BalrondHashCompat.StableHash("SE_Chilled_bal")
				}
			},
			{
				(DamageType)256,
				new DebuffProcConfig
				{
					DamageThreshold = 10f,
					BaseProcChance = 0.05f,
					StatusEffectHash = BalrondHashCompat.StableHash("SE_Enfeebled_bal")
				}
			},
			{
				(DamageType)128,
				new DebuffProcConfig
				{
					DamageThreshold = 14f,
					BaseProcChance = 0.05f,
					StatusEffectHash = BalrondHashCompat.StableHash("SE_StaticCharge_bal")
				}
			},
			{
				(DamageType)512,
				new DebuffProcConfig
				{
					DamageThreshold = 10f,
					BaseProcChance = 0.05f,
					StatusEffectHash = BalrondHashCompat.StableHash("SE_SoulSapped_bal")
				}
			},
			{
				(DamageType)1,
				new DebuffProcConfig
				{
					DamageThreshold = 10f,
					BaseProcChance = 0.05f,
					StatusEffectHash = FracturedStatusHash
				}
			},
			{
				(DamageType)2,
				new DebuffProcConfig
				{
					DamageThreshold = 10f,
					BaseProcChance = 0.05f,
					StatusEffectHash = LaceratedStatusHash
				}
			},
			{
				(DamageType)4,
				new DebuffProcConfig
				{
					DamageThreshold = 10f,
					BaseProcChance = 0.05f,
					StatusEffectHash = PuncturedStatusHash
				}
			}
		};

		private static void Prefix(Character __instance, HitData hit)
		{
			if (!((Object)(object)__instance == (Object)null) && hit != null && __instance.IsOwner() && !(__instance.GetHealth() <= 0f) && !__instance.IsDead() && !__instance.IsTeleporting() && !__instance.InCutscene() && (!hit.m_dodgeable || !__instance.IsDodgeInvincible()))
			{
				HitData val = CreateSimulatedHit(__instance, hit);
				if (val != null)
				{
					TryApplyMajorityDamageDebuff(__instance, val);
				}
			}
		}

		private static HitData CreateSimulatedHit(Character target, HitData originalHit)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			HitData val = CloneHit(originalHit);
			if (val == null)
			{
				return null;
			}
			Character attacker = originalHit.GetAttacker();
			if ((Object)(object)attacker != (Object)null && !attacker.IsPlayer())
			{
				float difficultyDamageScalePlayer = Game.instance.GetDifficultyDamageScalePlayer(((Component)target).transform.position);
				val.ApplyModifier(difficultyDamageScalePlayer);
				val.ApplyModifier(Game.m_enemyDamageRate);
			}
			BaseAI baseAI = target.GetBaseAI();
			if ((Object)(object)baseAI != (Object)null && !baseAI.IsAlerted() && val.m_backstabBonus > 1f && Time.time - GetBackstabTime(target) > 300f && (!ZoneSystem.instance.GetGlobalKey((GlobalKeys)25) || !baseAI.CanSeeTarget(attacker)))
			{
				val.ApplyModifier(val.m_backstabBonus);
			}
			if (target.IsStaggering() && !target.IsPlayer())
			{
				val.ApplyModifier(2f);
			}
			WeakSpot weakSpot = GetWeakSpot(target, val.m_weakSpot);
			DamageModifiers damageModifiers = target.GetDamageModifiers(weakSpot);
			DamageModifier val2 = default(DamageModifier);
			val.ApplyResistance(damageModifiers, ref val2);
			if (target.IsPlayer())
			{
				val.ApplyArmor(target.GetBodyArmor());
			}
			else if (Game.m_worldLevel > 0)
			{
				val.ApplyArmor((float)(Game.m_worldLevel * Game.instance.m_worldLevelEnemyBaseAC));
			}
			return val;
		}

		private static void TryApplyMajorityDamageDebuff(Character target, HitData simulatedHit)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null || simulatedHit == null)
			{
				return;
			}
			SEMan sEMan = target.GetSEMan();
			if (sEMan == null)
			{
				return;
			}
			float num = default(float);
			DamageType majorityDamageType = ((DamageTypes)(ref simulatedHit.m_damage)).GetMajorityDamageType(ref num);
			if (ProcConfigs.TryGetValue(majorityDamageType, out var value) && num >= value.DamageThreshold && !sEMan.HaveStatusEffect(value.StatusEffectHash))
			{
				DamageModifiers damageModifiers = target.GetDamageModifiers((WeakSpot)null);
				DamageModifier modifier = ((DamageModifiers)(ref damageModifiers)).GetModifier(majorityDamageType);
				float num2 = (target.IsPlayer() ? 1f : 0.75f);
				float num3 = value.BaseProcChance * GetResistanceChanceMultiplier(modifier) * num2;
				if (num3 > 0f && Random.value <= Mathf.Clamp01(num3))
				{
					sEMan.AddStatusEffect(value.StatusEffectHash, true, 0, 0f);
				}
			}
			TryApplyBleeding(sEMan, majorityDamageType, num);
		}

		private static void TryApplyBleeding(SEMan seMan, DamageType majorityType, float majorityDamage)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			if (seMan == null || ((int)majorityType != 2 && (int)majorityType != 4) || majorityDamage < 12f || seMan.HaveStatusEffect(BleedingStatusHash))
			{
				return;
			}
			int num = 0;
			if (seMan.HaveStatusEffect(LaceratedStatusHash))
			{
				num++;
			}
			if (seMan.HaveStatusEffect(PuncturedStatusHash))
			{
				num++;
			}
			if (seMan.HaveStatusEffect(FracturedStatusHash))
			{
				num++;
			}
			if (num != 0)
			{
				float bleedChanceFromWounds = GetBleedChanceFromWounds(num);
				if (bleedChanceFromWounds > 0f && Random.value <= bleedChanceFromWounds)
				{
					seMan.AddStatusEffect(BleedingStatusHash, true, 0, 0f);
				}
			}
		}

		private static float GetBleedChanceFromWounds(int woundCount)
		{
			return woundCount switch
			{
				1 => 0.05f, 
				2 => 0.25f, 
				3 => 0.75f, 
				_ => 0f, 
			};
		}

		private static HitData CloneHit(HitData original)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (original == null)
			{
				return null;
			}
			HitData val = original.Clone();
			val.m_damage = ((DamageTypes)(ref original.m_damage)).Clone();
			return val;
		}

		private static WeakSpot GetWeakSpot(Character character, short weakSpotIndex)
		{
			if ((Object)(object)character == (Object)null || GetWeakSpotFast == null)
			{
				return null;
			}
			return GetWeakSpotFast(character, weakSpotIndex);
		}

		private static float GetBackstabTime(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return -99999f;
			}
			return BackstabTimeRef.Invoke(character);
		}

		private static float GetResistanceChanceMultiplier(DamageModifier modifier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected I4, but got Unknown
			switch ((int)modifier)
			{
			case 3:
			case 4:
				return 0f;
			case 5:
				return 0.11f;
			case 1:
				return 0.33f;
			case 7:
				return 0.66f;
			case 0:
				return 1f;
			case 8:
				return 1.33f;
			case 2:
				return 1.66f;
			case 6:
				return 2f;
			default:
				return 1f;
			}
		}
	}
	[HarmonyPatch]
	internal static class CombatPatches
	{
		[HarmonyPatch(typeof(Character), "CustomFixedUpdate")]
		public static class MonsterClimbPatch
		{
			private static readonly Dictionary<Character, float> NextCheck = new Dictionary<Character, float>();

			private static readonly int GroundMask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "vehicle", "Default_small", "piece", "terrain" });

			private const float CheckInterval = 0.02f;

			private const float BaseUpBoost = 10f;

			private const float BaseForwardBoost = 4.5f;

			private const float ReferenceHeight = 1.5f;

			private const float MaxSizeMultiplier = 4.5f;

			private const float MinTargetHeightDifference = 0.45f;

			private const float TargetClimbXZRange = 10f;

			private const float TargetClimbXZRangeSqr = 100f;

			private const float MinTargetXZRangeSqr = 0.0025000002f;

			private static void Postfix(Character __instance, float dt)
			{
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02af: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02df: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0300: Unknown result type (might be due to invalid IL or missing references)
				//IL_0302: Unknown result type (might be due to invalid IL or missing references)
				//IL_0309: Unknown result type (might be due to invalid IL or missing references)
				//IL_030e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0313: Unknown result type (might be due to invalid IL or missing references)
				//IL_0347: Unknown result type (might be due to invalid IL or missing references)
				//IL_034b: Unknown result type (might be due to invalid IL or missing references)
				//IL_035d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0361: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0192: Unknown result type (might be due to invalid IL or missing references)
				//IL_0197: Unknown result type (might be due to invalid IL or missing references)
				//IL_0392: Unknown result type (might be due to invalid IL or missing references)
				//IL_038e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0394: Unknown result type (might be due to invalid IL or missing references)
				//IL_0398: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_042d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0404: Unknown result type (might be due to invalid IL or missing references)
				//IL_0407: Unknown result type (might be due to invalid IL or missing references)
				//IL_040c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0410: Unknown result type (might be due to invalid IL or missing references)
				//IL_041e: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance == (Object)null || __instance.IsPlayer() || __instance.IsFlying() || !__instance.IsOwner() || __instance.IsDead() || !__instance.IsOnGround())
				{
					return;
				}
				float time = Time.time;
				if (NextCheck.TryGetValue(__instance, out var value) && time < value)
				{
					return;
				}
				NextCheck[__instance] = time + 0.02f;
				BaseAI baseAI = __instance.GetBaseAI();
				if ((Object)(object)baseAI == (Object)null || baseAI.IsSleeping())
				{
					return;
				}
				Vector3 val = __instance.GetMoveDir();
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude >= 0.01f)
				{
					((Vector3)(ref val)).Normalize();
				}
				else
				{
					Character targetCreature = baseAI.GetTargetCreature();
					if ((Object)(object)targetCreature == (Object)null || targetCreature.IsDead())
					{
						return;
					}
					Vector3 val2 = ((Component)targetCreature).transform.position - ((Component)__instance).transform.position;
					float y = val2.y;
					if (y < 0.45f)
					{
						return;
					}
					val2.y = 0f;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude > 100f || sqrMagnitude < 0.0025000002f)
					{
						return;
					}
					float num = Mathf.Sqrt(sqrMagnitude);
					val = val2 / num;
				}
				Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				CapsuleCollider collider = __instance.GetCollider();
				if ((Object)(object)collider == (Object)null)
				{
					return;
				}
				Bounds bounds = ((Collider)collider).bounds;
				float num2 = Mathf.Max(0.5f, ((Bounds)(ref bounds)).size.y);
				float num3 = Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z);
				float num4 = Mathf.Clamp(num2 / 1.5f, 0.75f, 4.5f);
				float num5 = Mathf.InverseLerp(1f, 4.5f, num4);
				float num6 = 10f * Mathf.Lerp(0.85f, 1.65f, num5);
				float num7 = 4.5f * Mathf.Lerp(0.9f, 1.65f, num5);
				float num8 = Mathf.Clamp(num2 * 0.08f, 0.1f, 0.45f);
				float num9 = Mathf.Clamp(num2 * 0.28f, 0.25f, 1.6f);
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).center.z);
				Vector3 val4 = val3 + val * Mathf.Max(0.15f, num3 * 0.65f);
				Vector3 val5 = val4 + Vector3.up * num8;
				Vector3 val6 = val4 + Vector3.up * num9;
				float num10 = Mathf.Clamp(num3 * 0.22f, 0.14f, 0.65f);
				float num11 = Mathf.Clamp(num3 * 0.75f, 0.45f, 1.8f);
				RaycastHit val7 = default(RaycastHit);
				bool flag = Physics.SphereCast(val5, num10, val, ref val7, num11, GroundMask, (QueryTriggerInteraction)1);
				RaycastHit val8 = default(RaycastHit);
				bool flag2 = Physics.SphereCast(val6, num10, val, ref val8, num11, GroundMask, (QueryTriggerInteraction)1);
				if (!flag && !flag2)
				{
					return;
				}
				RaycastHit val9 = (flag2 ? val8 : val7);
				if (!(((RaycastHit)(ref val9)).normal.y > 0.58f))
				{
					Vector3 linearVelocity = component.linearVelocity;
					if (linearVelocity.y < num6)
					{
						linearVelocity.y = num6;
					}
					Vector3 val10 = default(Vector3);
					((Vector3)(ref val10))..ctor(linearVelocity.x, 0f, linearVelocity.z);
					if (Vector3.Dot(val10, val) < num7)
					{
						Vector3 val11 = val * num7;
						linearVelocity.x = val11.x;
						linearVelocity.z = val11.z;
					}
					component.linearVelocity = linearVelocity;
					__instance.TimeoutGroundForce(0.06f);
				}
			}

			public static void Remove(Character character)
			{
				if ((Object)(object)character != (Object)null)
				{
					NextCheck.Remove(character);
				}
			}
		}

		[HarmonyPatch(typeof(Character), "OnDestroy")]
		public static class MonsterClimbCleanupPatch
		{
			private static void Prefix(Character __instance)
			{
				MonsterClimbPatch.Remove(__instance);
			}
		}

		[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
		internal static class ResetLoaded
		{
			private const string CbowLoadedKey = "bal_cbow_loaded";

			private const string CbowLoadedChangedKey = "bal_cbow_loaded_changed";

			private static void Prefix(Attack __instance)
			{
				if (__instance == null || (Object)(object)__instance.m_character == (Object)null || (Object)(object)__instance.m_character != (Object)(object)Player.m_localPlayer)
				{
					return;
				}
				ItemData currentWeapon = __instance.m_character.GetCurrentWeapon();
				if (IsCrossbowItem(currentWeapon))
				{
					currentWeapon.m_customData["bal_cbow_loaded"] = "false";
					if (currentWeapon.m_customData.ContainsKey("bal_cbow_loaded_changed"))
					{
						currentWeapon.m_customData.Remove("bal_cbow_loaded_changed");
						currentWeapon.m_shared.m_attack.m_requiresReload = true;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
		internal static class CheckIfCrossbowWasUnequipped
		{
			private const string CbowLoadedKey = "bal_cbow_loaded";

			private const string CbowLoadedChangedKey = "bal_cbow_loaded_changed";

			private static void Prefix(Humanoid __instance, ItemData item, bool triggerEquipEffects = true)
			{
				if ((Object)(object)__instance == (Object)null || item == null)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)__instance != (Object)(object)localPlayer) && !localPlayer.m_isLoading && IsCrossbowItem(item) && __instance.IsWeaponLoaded())
				{
					item.m_customData["bal_cbow_loaded"] = "true";
					if (item.m_shared.m_attack.m_requiresReload)
					{
						item.m_customData["bal_cbow_loaded_changed"] = "1";
						item.m_shared.m_attack.m_requiresReload = false;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Character), "CustomFixedUpdate")]
		public static class Patch_Player_StaminaRegenSmoothCurve
		{
			private const float MinRegenMultiplier = 0.75f;

			private const float MaxRegenMultiplier = 1.5f;

			private const float CurveExponent = 1.35f;

			private static void Prefix(Character __instance, ref float __state)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				__state = (((Object)(object)val != (Object)null) ? val.GetStamina() : (-1f));
			}

			private static void Postfix(Character __instance, float __state)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if ((Object)(object)val == (Object)null || ((Character)val).IsDead() || __state < 0f)
				{
					return;
				}
				float stamina = val.GetStamina();
				if (stamina <= __state)
				{
					return;
				}
				float maxStamina = ((Character)val).GetMaxStamina();
				if (!(maxStamina <= 0f))
				{
					float num = stamina - __state;
					float num2 = Mathf.Clamp01((maxStamina - stamina) / maxStamina);
					float num3 = Mathf.Pow(num2, 1.35f);
					float num4 = Mathf.Lerp(1.5f, 0.75f, num3);
					float num5 = Mathf.Clamp(__state + num * num4, 0f, maxStamina);
					float num6 = num5 - stamina;
					if (Mathf.Abs(num6) > 0.001f)
					{
						((Character)val).AddStamina(num6);
					}
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Attack), "DoMeleeAttack")]
		private static void Attack_DoMeleeAttack(Attack __instance)
		{
			if (!Compatibility2.IsLoaded() && __instance != null)
			{
				Humanoid character = __instance.m_character;
				Player val = (Player)(object)((character is Player) ? character : null);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)Player.m_localPlayer))
				{
					__instance.m_maxYAngle = 180f;
					__instance.m_attackHeight = 1f;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "AlwaysRotateCamera")]
		private static void Player_AlwaysRotateCamera(Character __instance, ref bool __result)
		{
			if (!Compatibility2.IsLoaded())
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && ((Character)val).IsBlocking() && val.m_attackTowardsPlayerLookDir)
				{
					__result = false;
				}
			}
		}

		public static bool IsCrossbowItem(ItemData item)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			if (item == null || item.m_shared == null)
			{
				return false;
			}
			SkillType skillType = item.m_shared.m_skillType;
			return (int)skillType == 14 || (int)skillType == 9 || (int)skillType == 10;
		}
	}
	internal class ClutterList
	{
		public static string[] clutter = new string[24]
		{
			"instanced_heathgrass_red_bal", "instanced_mushroom_brown_bal", "instanced_dandelionflower_blue_bal", "instanced_heathflowers_purple_bal", "instanced_heathflowers_pink_bal", "instanced_heathflowers_blue_bal", "instanced_heathflowers_yellow_bal", "instanced_mistlands_grass_short_white_bal", "mistlandsBush6", "ormbunke_bal",
			"seaBush6", "seaBush8", "seaBush9", "seaBush10", "seaBush11", "instanced_brown_grass_short_bal", "instanced_clover_bal", "instanced_springflowers_purplewhite_bal", "instanced_springflowers_yellow_bal", "instanced_shrub_blue_bal",
			"instanced_shrub_white_bal", "instanced_shrub_brown_bal", "instanced_bushleafsfruit_bal", "instanced_dead_straw_short_bal"
		};
	}
	public class ConversionChanges
	{
		private enum ConversionType
		{
			smelter,
			fermenter,
			cooking,
			balrondConverter
		}

		private List<GameObject> buildPieces = new List<GameObject>();

		private List<GameObject> items = new List<GameObject>();

		public static List<TutorialText> m_texts = new List<TutorialText>();

		public static List<BalrondConverter.ItemConversion> sawmillConverions = new List<BalrondConverter.ItemConversion>();

		public static List<BalrondConverter.ItemConversion> stonekilnConverions = new List<BalrondConverter.ItemConversion>();

		public static List<BalrondConverter.ItemConversion> tanneryConverions = new List<BalrondConverter.ItemConversion>();

		public static List<ItemConversion> kilnConverions = new List<ItemConversion>();

		public static List<ItemConversion> smelterConverions = new List<ItemConversion>();

		public static List<ItemConversion> furnaceConverions = new List<ItemConversion>();

		private static readonly string[] buildPieceNames = new string[18]
		{
			"portal_wood", "piece_workbench", "forge", "blackforge", "piece_magetable", "piece_artisanstation", "piece_stonecutter", "piece_banner01", "piece_banner02", "piece_banner03",
			"piece_banner04", "piece_banner05", "piece_banner06", "piece_banner07", "piece_banner08", "piece_banner09", "piece_banner10", "piece_banner11"
		};

		private string[] convertToBits = new string[41]
		{
			"WillowSeeds_bal", "WillowBark_bal", "YewBark_bal", "WoodNails_bal", "WaterLilySeeds_bal", "SwampTreeSeeds_bal", "Straw_bal", "StrawSeeds_bal", "Snowleaf_bal", "StrawThread_bal",
			"RedwoodSeeds_bal", "Plantain_bal", "PoplarSeeds_bal", "Peningar_bal", "Sage_bal", "Lavender_bal", "Mint_bal", "OilBase_bal", "Oil_bal", "Nettle_bal",
			"Moss_bal", "Mugwort_bal", "MushroomIcecap_bal", "MushroomInkcap_bal", "Iceberry_bal", "Ignicap_bal", "GarlicSeeds_bal", "Garlic_bal", "CypressSeeds_bal", "CabbageLeaf_bal",
			"CabbageSeeds_bal", "Cabbage_bal", "BirdFeed_bal", "Blackberries_bal", "AppleSeeds_bal", "BasicSeed_bal", "AcaiSeeds_bal", "MapleSeeds_bal", "WaterLily_bal", "Yarrow_bal",
			"MeatScrap_bal"
		};

		private string[] convertToCoal = new string[194]
		{
			"ClayBrickMold_bal", "AcidSludge_bal", "AncientRelic_bal", "AppleVinegar_bal", "Apple_bal", "BatWingCooked_bal", "BatWing_bal", "BeltForester_bal", "BeltMountaineer_bal", "BeltSailor_bal",
			"BlackMetalCultivator_bal", "BlackMetalHoe_bal", "BlackSkin_bal", "BlackTissue_bal", "Bloodfruit_bal", "Bloodshard_bal", "BoarHide_bal", "BoraxCrystal_bal", "BundleHut_bal", "CarvedCarcass_bal",
			"CarvedDeerSkull_bal", "CeramicMold_bal", "Cheese_bal", "CabbageSoup_bal", "ClamMeat_bal", "ClayBrick_bal", "ClayPot_bal", "Clay_bal", "CoalPowder_bal", "CookedCrowMeat_bal",
			"CookedDragonRibs_bal", "CorruptedEitr_bal", "CrabLegsCooked_bal", "CrabLegs_bal", "CrystalWood_bal", "CultInsignia_bal", "CursedBone_bal", "Darkbul_bal", "DeadEgo_bal", "DragonSoul_bal",
			"DrakeMeatCooked_bal", "DrakeMeat_bal", "DrakeSkin_bal", "DyeKit_bal", "EmberWood_bal", "EnrichedEitr_bal", "EnrichedSoil_bal", "FenringInsygnia_bal", "FenringMeatCooked_bal", "FenringMeat_bal",
			"FireGland_bal", "FishWrapsUncooked_bal", "ForsakenHeart_bal", "FoxFur_bal", "CarvedWood_bal", "WispCore_bal", "GoatMeatCooked_bal", "GoatMeat_bal", "GrayMushroom_bal", "GrilledCheese_bal",
			"HammerBlackmetal_bal", "HammerDverger_bal", "HammerIron_bal", "HammerMythic_bal", "HardWood_bal", "HelmetCrown_bal", "InfusedCarapace_bal", "JotunFinger_bal", "JuteThread_bal", "KingMug_bal",
			"MagmaStone_bal", "MeadBase_bal", "MedPack_bal", "MincedMeat_bal", "NeckSkin_bal", "NorthernFur_bal", "NumbMeal_bal", "PickaxeFlametal_bal", "RawCrowMeat_bal", "RawDragonRibs_bal",
			"RawSilkScrap_bal", "RawSilk_bal", "RawSteak_bal", "RedKelp_bal", "RefinedOil_bal", "Sapphire_bal", "SawBlade_bal", "Seaberries_bal", "SeekerBrain_bal", "SerpentEgg_bal",
			"SharkMeatCooked_bal", "SharkMeat_bal", "SilkReinforcedThread_bal", "SmallBloodSack_bal", "SoulCore_bal", "SpiceSet_bal", "SpiritShard_bal", "SteakCooked_bal", "StormScale_bal", "TarBase_bal",
			"ThornHeart_bal", "ThunderGland_bal", "TormentedSoul_bal", "TrollMeatCooked_bal", "TrollMeat_bal", "WatcherHeart_bal", "SurtlingCoreCasing_bal", "ApplePieUncooked_bal", "ApplePie_bal", "AshlandCurry_bal",
			"BlackBerryJuice_bal", "BloodfruitSoup_bal", "BloodyBearJerky_bal", "BloodyCreamPie_bal", "BloodyVial_bal", "BlueberryPieUncooked_bal", "BlueberryPie_bal", "Breakfast_bal", "Burger_bal", "ChickenMarsala_bal",
			"ChickenNuggets_bal", "DragonfireBarbecue_bal", "FishSkewer_bal", "FruitPunch_bal", "FruitSalad_bal", "GrilledShrooms_bal", "HappyMeal_bal", "HoneyGlazedApple_bal", "IceBerryPancake_bal", "KingsJam_bal",
			"Liverwurst_bal", "MagmaCoctail_bal", "MeadBaseWhiteCheese_bal", "SeaFoodPlatter_bal", "SpicyBurger_bal", "SpiecedDrakeChop_bal", "SurstrommingBase_bal", "Surstromming_bal", "SwampSkause_bal", "VegetablePuree_bal",
			"VegetableSoup_bal", "WhiteCheese_bal", "WinterStew_bal", "CarrotFries_bal", "PowderedSalt_bal", "PowderedPepper_bal", "BundlePortal_bal", "BundlePortalStone_bal", "HelmetLeatherCap_bal", "HelmetBronzeHorned_bal",
			"BlackBerryJuiceBase_bal", "MagmaCoctailBase_bal", "FruitPunchBase_bal", "VineBerryJuice_bal", "VineBerryJuiceBase_bal", "RostedTrollBits_bal", "RoastedFish_bal", "CabbageWrapDrake_bal", "Cotlet_bal", "RedStew_bal",
			"GoatStew_bal", "CrustedMeat_bal", "MeatBalls_bal", "MeatRoll_bal", "MagnaTarta_bal", "ShrededMeat_bal", "MincedFenringStew_bal", "CarrotCrowSalad_bal", "Bulion_bal", "CookedMeatScrap_bal",
			"WoodBucket_bal", "BeltVidar_bal", "BeltAssasin_bal", "TrophyBattleHog_bal", "TrophyGoat_bal", "TrophyNeckBrute_bal", "TrophyObsidianCrab_bal", "TrophyShark_bal", "TrophySouling_bal", "TrophyCorpseCollector_bal",
			"TrophyForsaken_bal", "TrophyGreywatcher_bal", "TrophyHaugbui_bal", "TrophySpectre_bal", "TrophyStormdrake_bal", "TrophyTrollAshlands_bal", "TrophyTrollSkeleton_bal", "TrophyStag_bal", "TrophyLeechPrimal_bal", "TrophyStagGhost_bal",
			"Larva_bal", "WaterJugEmpty_bal", "SwordFakeSilver_Bal", "MaceFakeSilver_bal"
		};

		private string[] arrowsNbolts = new string[10] { "BoltBlunt_bal", "BoltChitin_bal", "BoltFire_bal", "BoltSilver_bal", "BoltThunder_bal", "ArrowBlizzard_bal", "ArrowBlunt_bal", "ArrowBone_bal", "ArrowChitin_bal", "ArrowFlametal_bal" };

		public void editBuidlPieces(List<GameObject> allPrefabs)
		{
			buildPieces = allPrefabs;
			items = allPrefabs;
			editFermenter();
			editOven();
			editKiln();
			editStoneboundKiln();
			editWHeel();
			editSap();
			editBeehive();
			editSmelter();
			editPress();
			editComposter();
			editFurnace();
			editRefinery();
			editCooking();
			editIronCooking();
			editSmallIronCooking();
			editSawMill();
			editLeatherRack();
			editIncinerator();
			EditRecipes();
		}

		private void EditRecipes()
		{
			string[] array = buildPieceNames;
			foreach (string name in array)
			{
				GameObject val = FindBuildPiece(name);
				if ((Object)(object)val != (Object)null)
				{
					ModifyBuildPiece(val);
				}
			}
		}

		private void ModifyBuildPiece(GameObject piece)
		{
			string name = ((Object)piece).name;
			string text = name;
			switch (text)
			{
			case "forge":
			case "piece_workbench":
			case "blackforge":
			case "piece_magetable":
			case "piece_artisanstation":
			case "piece_stonecutter":
				SetCraftingStationRequiresRoof(piece, requireRoof: false);
				return;
			}
			if (text.StartsWith("piece_banner"))
			{
				SetBannerRecipe(piece);
			}
		}

		private void SetCraftingStationRequiresRoof(GameObject piece, bool requireRoof)
		{
			CraftingStation component = piece.GetComponent<CraftingStation>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_craftRequireRoof = requireRoof;
			}
		}

		private void SetBannerRecipe(GameObject piece)
		{
			Piece component = piece.GetComponent<Piece>();
			component.m_resources = (Requirement[])(object)new Requirement[4]
			{
				CreateRequirement("DyeKit_bal", 1),
				CreateRequirement("FineWood", 2),
				CreateRequirement("LeatherScraps", 3),
				CreateRequirement("StrawThread_bal", 3)
			};
		}

		private Requirement CreateRequirement(string itemName, int amount)
		{
			//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_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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			return new Requirement
			{
				m_resItem = FindItem(itemName).GetComponent<ItemDrop>(),
				m_amount = amount,
				m_amountPerLevel = 0,
				m_recover = true
			};
		}

		private GameObject FindBuildPiece(string name)
		{
			return ((IEnumerable<GameObject>)buildPieces).FirstOrDefault((Func<GameObject, bool>)((GameObject x) => ((Object)x).name == name));
		}

		private GameObject FindItem(string name)
		{
			if (items == null)
			{
				items = ZNetScene.instance?.m_prefabs;
			}
			if (items == null)
			{
				Debug.LogError((object)("Items list is null while looking for " + name));
				return null;
			}
			GameObject val = items.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == name.Trim());
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Debug.LogWarning((object)("Item Not Found - " + name + ", Replaced With Wood"));
			GameObject val2 = items.Find((GameObject x) => (Object)(object)x != (Object)null && ((Object)x).name == "Wood");
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.LogError((object)("Fallback item Wood not found while looking for " + name));
			}
			return val2;
		}

		private void removeConversionFromSmelter(string fromItem, List<ItemConversion> list)
		{
			if (list != null && list.Count != 0)
			{
				list.RemoveAll((ItemConversion x) => x == null || (Object)(object)x.m_from == (Object)null || x.m_from.m_itemData == null || (Object)(object)x.m_from.m_itemData.m_dropPrefab == (Object)null || ((Object)x.m_from.m_itemData.m_dropPrefab).name == fromItem);
			}
		}

		private Requirement createReq(string name, int amount, int amountPerLevel)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			Requirement val = new Requirement();
			val.m_recover = true;
			ItemDrop component = FindItem(name).GetComponent<ItemDrop>();
			val.m_resItem = component;
			val.m_amount = amount;
			val.m_amountPerLevel = amountPerLevel;
			return val;
		}

		public void editLeatherRack(BalrondConverter leatherRack = null)
		{
			if (buildPieces != null && (Object)(object)leatherRack == (Object)null)
			{
				GameObject val = buildPieces.Find((GameObject x) => ((Object)x).name == "piece_leatherRack_bal");
				leatherRack = val.GetComponent<BalrondConverter>();
			}
			if (tanneryConverions.Count > 0)
			{
				leatherRack.m_conversion = tanneryConverions;
				return;
			}
			leatherRack.m_conversion = new List<BalrondConverter.ItemConversion>();
			addConversion(((Component)leatherRack).gameObject, "NeckSkin_bal", "NeckSkin_bal", ConversionType.balrondConverter, 0, 2);
			addConversion(((Component)leatherRack).gameObject, "DeerHide", "DeerHide", ConversionType.balrondConverter, 0, 2, 2);
			addConversion(((Component)leatherRack).gameObject, "BoarHide_bal", "BoarHide_bal", ConversionType.balrondConverter, 0, 2, 2);
			addConversion(((Component)leatherRack).gameObject, "BjornHide", "BjornHide", ConversionType.balrondConverter, 0, 2, 3);
			addConversion(((Component)leatherRack).gameObject, "TrollHide", "TrollHide", ConversionType.balrondConverter, 0, 2, 3);
			addConversion(((Component)leatherRack).gameObject, "DrakeSkin_bal", "DrakeSkin_bal", ConversionType.balrondConverter, 0, 2, 4);
			addConversion(((Component)leatherRack).gameObject, "WolfPelt", "WolfPelt", ConversionType.balrondConverter, 0, 2, 4);
			addConversion(((Component)leatherRack).gameObject, "LoxPelt", "LoxPelt", ConversionType.balrondConverter, 0, 2, 5);
			addConversion(((Component)leatherRack).gameObject, "AskHide", "AskHide", ConversionType.balrondConverter, 0, 2, 5);
		}

		public void editRefinery(Smelter refinery = null)
		{
			string text = "";
			if (buildPieces != null && (Object)(object)refinery == (Object)null)
			{
				GameObject val = buildPieces.Find((GameObject x) => ((Object)x).name == "eitrrefinery");
				refinery = val.GetComponent<Smelter>();
			}
			if (refinery.m_maxFuel == 20)
			{
				refinery.m_maxFuel = 60;
			}
			if (refinery.m_maxOre == 20)
			{
				refinery.m_maxOre = 60;
			}
			if (refinery.m_secPerProduct == 40f)
			{
				refinery.m_secPerProduct = 60f;
			}
			text += addConversion(((Component)refinery).gameObject, "Oil_bal", "RefinedOil_bal", ConversionType.smelter);
			text += addConversion(((Component)refinery).gameObject, "BlackTissue_bal", "CorruptedEitr_bal", ConversionType.smelter);
			buildConversionStationTutorialTag(((Component)refinery).gameObject, text);
		}

		public void editComposter(Smelter composter = null)
		{
			string text = "";
			if (buildPieces != null && (Object)(object)composter == (Object)null)
			{
				GameObject val = buildPieces.Find((GameObject x) => ((Object)x).name == "composter_bal");
				composter = val.GetComponent<Smelter>();
			}
			if (composter.m_conversion == null)
			{
				composter.m_conversion = new List<ItemConversion>();
			}
			text += addConversion(((Component)composter).gameObject, "RottenMeat", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "RottenVegetable_bal", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "Pukeberries", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "StrawBundle_bal", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "Cabbage_bal", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "Turnip", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "Carrot", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "Onion", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "Garlic_bal", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "BirdFeed_bal", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "Apple_bal", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "PoisonApple_bal", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "BoneFragments", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "RawMeat", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "NeckTail", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "FishRaw", "EnrichedSoil_bal", ConversionType.smelter);
			text += addConversion(((Component)composter).gameObject, "SerpentMeat", "EnrichedSoil_bal", Conve