Decompiled source of ServersideQoL CreatureLevelUp BETA v1.99.6

ServersideQoL.CreatureLevelUp.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArgusMagnus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("ArgusMagnus")]
[assembly: AssemblyDescription("Configure the max level of creature and let it increase with world progression")]
[assembly: AssemblyFileVersion("1.99.6.0")]
[assembly: AssemblyInformationalVersion("1.99.6-beta+810d35747174203543d1f1abdc6d70470b52f9c0")]
[assembly: AssemblyProduct("ServersideQoL.CreatureLevelUp")]
[assembly: AssemblyTitle("ServersideQoL.CreatureLevelUp")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("1.99.6.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ServersideQoL.CreatureLevelUp
{
	public sealed class Config : ConfigBase<Config>
	{
		public enum RespawnOneTimeSpawnsConditions
		{
			Never,
			Always,
			AfterBossDefeated
		}

		public sealed class AdvancedConfig
		{
			public bool ScaleSizeExponentially { get; init; } = true;

			private string Star { get; init; } = "⭐";

			private string HigherLevelStarNameFormat { get; init; } = "<line-height=150%><voffset=-2em>{0}<size=70%><br><color=yellow>{1}</color></size></voffset></line-height>";

			public string HigherLevelStarName(Character character, int level)
			{
				return string.Format(HigherLevelStarNameFormat, character.m_name, string.Concat(Enumerable.Repeat(Star, level - 1)));
			}
		}

		private const string Section = "CreatureLevelUp";

		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "CreatureLevelUp", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated<Config>)null, "Enabled");

		public ConfigEntry<bool> ShowHigherLevelStars { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "CreatureLevelUp", true, "True to show stars for higher level creatures (> 2 stars)", (AcceptableValueBase)null, (Deprecated<Config>)null, "ShowHigherLevelStars");

		public ConfigEntry<float> SizeIncreasePerStar { get; } = ConfigBase<Config>.BindEx<float>(cfg, "CreatureLevelUp", 0.1f, "The relative size increase a starred creature will have", (AcceptableValueBase)null, (Deprecated<Config>)null, "SizeIncreasePerStar");

		public ConfigEntry<int> MaxLevelIncrease { get; } = ConfigBase<Config>.BindEx<int>(cfg, "CreatureLevelUp", 0, "Amount the max level of creatures is incremented throughout the world.\r\nThe level up chance increases with the max level.\r\nExample: if this value is set to 2, a creature will spawn with 4 stars with the same probability as it would spawn with 2 stars without this setting.", (AcceptableValueBase)null, (Deprecated<Config>)null, "MaxLevelIncrease");

		public ConfigEntry<int> MaxLevelIncreasePerDefeatedBoss { get; } = ConfigBase<Config>.BindEx<int>(cfg, "CreatureLevelUp", 1, "Amount the max level of creatures is incremented per defeated boss.\r\nThe respective boss's biome and previous biomes are affected and the level up chance increases with the max level.\r\nExample: If this value is set to 1 and Eikthyr and the Elder is defeated, the max creature level in the Black Forest will be raised by 1 and in the Meadows by 2.", (AcceptableValueBase)null, (Deprecated<Config>)null, "MaxLevelIncreasePerDefeatedBoss");

		public ConfigEntry<Biome> TreatOceanAs { get; } = ConfigBase<Config>.BindEx<Biome>(cfg, "CreatureLevelUp", (Biome)8, "Biome to treat the ocean as for the purpose of leveling up creatures", (AcceptableValueBase)(object)new AcceptableEnum<Biome>(AcceptableEnum<Biome>.Default.AcceptableValues.Where((Biome x) => (int)x != 256)), (Deprecated<Config>)null, "TreatOceanAs");

		public ConfigEntry<bool> LevelUpBosses { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "CreatureLevelUp", false, "True to also level up bosses", (AcceptableValueBase)null, (Deprecated<Config>)null, "LevelUpBosses");

		public ConfigEntry<RespawnOneTimeSpawnsConditions> RespawnOneTimeSpawnsCondition { get; } = ConfigBase<Config>.BindEx<RespawnOneTimeSpawnsConditions>(cfg, "CreatureLevelUp", RespawnOneTimeSpawnsConditions.AfterBossDefeated, "Condition for one-time spawns to respawn", (AcceptableValueBase)null, (Deprecated<Config>)null, "RespawnOneTimeSpawnsCondition");

		public ConfigEntry<float> RespawnOneTimeSpawnsAfterMinutes { get; } = ConfigBase<Config>.BindEx<float>(cfg, "CreatureLevelUp", 240f, "Time after one-time spawns are respawned in minutes", (AcceptableValueBase)null, (Deprecated<Config>)null, "RespawnOneTimeSpawnsAfterMinutes");

		public YamlConfigEntry<AdvancedConfig> Advanced { get; } = ConfigBase<Config>.BindYaml<AdvancedConfig>(cfg, "Advanced");

		public Config(ConfigFile cfg, Logger logger)
			: base(cfg, logger)
		{
		}
	}
	[BepInPlugin("ArgusMagnus.ServersideQoL.CreatureLevelUp", "ServersideQoL.CreatureLevelUp", "1.99.6")]
	public sealed class CreatureLevelUpPlugin : ServersideQoLPluginBase<CreatureLevelUpPlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.CreatureLevelUp";

		public const string PluginGuid = "ArgusMagnus.ServersideQoL.CreatureLevelUp";

		public const string PluginVersion = "1.99.6";

		public const string PluginInformationalVersion = "1.99.6-beta";

		private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639210949083631058L, default(TimeSpan));

		protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger)
		{
			return new Config(configFile, logger);
		}

		protected override void RegisterProcessors(IProcessorCollection processors)
		{
			processors.Add<CreatureLevelUpProcessor>().Add<CreatureProcessor>();
		}

		private void Awake()
		{
			ServersideQoLPluginBase<CreatureLevelUpPlugin, Config>.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.6-beta", BuildTimestamp.LocalDateTime));
		}
	}
	[Processor("5ab42c92-d2fd-4efe-8904-720a46ac7f5b")]
	public sealed class CreatureLevelUpProcessor : Processor<CreatureLevelUpProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(Character? Character, CreatureSpawner? CreatureSpawner, SpawnArea? SpawnArea) : ProcessorPrefabInfo()
		{
			[CompilerGenerated]
			public override string ToString()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("PrefabInfo");
				stringBuilder.Append(" { ");
				if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append('}');
				return stringBuilder.ToString();
			}

			[CompilerGenerated]
			protected override bool PrintMembers(StringBuilder builder)
			{
				if (((ProcessorPrefabInfo)this).PrintMembers(builder))
				{
					builder.Append(", ");
				}
				builder.Append("Character = ");
				builder.Append(Character);
				builder.Append(", CreatureSpawner = ");
				builder.Append(CreatureSpawner);
				builder.Append(", SpawnArea = ");
				builder.Append(SpawnArea);
				return true;
			}

			[CompilerGenerated]
			public override int GetHashCode()
			{
				return ((((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<Character>.Default.GetHashCode(Character)) * -1521134295 + EqualityComparer<CreatureSpawner>.Default.GetHashCode(CreatureSpawner)) * -1521134295 + EqualityComparer<SpawnArea>.Default.GetHashCode(SpawnArea);
			}

			[CompilerGenerated]
			public sealed override bool Equals(ProcessorPrefabInfo? other)
			{
				return ((object)this).Equals((object?)other);
			}

			[CompilerGenerated]
			public bool Equals(PrefabInfo? other)
			{
				if ((object)this != other)
				{
					if (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<Character>.Default.Equals(Character, other.Character) && EqualityComparer<CreatureSpawner>.Default.Equals(CreatureSpawner, other.CreatureSpawner))
					{
						return EqualityComparer<SpawnArea>.Default.Equals(SpawnArea, other.SpawnArea);
					}
					return false;
				}
				return true;
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				Character = original.Character;
				CreatureSpawner = original.CreatureSpawner;
				SpawnArea = original.SpawnArea;
			}
		}

		private record SpawnData(int Prefab, int MinLevel, int MaxLevel, float LevelUpChance);

		private sealed record SpawnSystemData(SpawnData Data, Biome? BiomeOverwrite) : SpawnData(StringExtensionMethods.GetStableHashCode(((Object)Data.m_prefab).name, true), Data.m_minLevel, Data.m_maxLevel, Data.m_overrideLevelupChance);

		private sealed class SectorState
		{
			public sealed record SpawnAreaData : SpawnData
			{
				public ZDOID ID { get; init; }

				public Vector3 Position { get; init; }

				public Biome Biome { get; init; }

				public float Radius { get; init; }

				public SpawnAreaData(ZDOID ID, Vector3 Position, Biome Biome, float Radius, int Prefab, int MinLevel, int MaxLevel, float LevelUpChance)
				{
					//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_0008: Unknown result type (might be due to invalid IL or missing references)
					//IL_0009: Unknown result type (might be due to invalid IL or missing references)
					//IL_000f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0010: Unknown result type (might be due to invalid IL or missing references)
					this.ID = ID;
					this.Position = Position;
					this.Biome = Biome;
					this.Radius = Radius;
					base..ctor(Prefab, MinLevel, MaxLevel, LevelUpChance);
				}

				[CompilerGenerated]
				public void Deconstruct(out ZDOID ID, out Vector3 Position, out Biome Biome, out float Radius, out int Prefab, out int MinLevel, out int MaxLevel, out float LevelUpChance)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0013: Unknown result type (might be due to invalid IL or missing references)
					//IL_001a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0020: Expected I4, but got Unknown
					ID = this.ID;
					Position = this.Position;
					Biome = (Biome)(int)this.Biome;
					Radius = this.Radius;
					Prefab = base.Prefab;
					MinLevel = base.MinLevel;
					MaxLevel = base.MaxLevel;
					LevelUpChance = base.LevelUpChance;
				}
			}

			public Dictionary<int, List<ServersideQoLZDO>> CreatureSpawnersBySpawned { get; } = new Dictionary<int, List<ServersideQoLZDO>>();

			public Dictionary<int, List<SpawnAreaData>> SpawnAreasBySpawned { get; } = new Dictionary<int, List<SpawnAreaData>>();
		}

		private sealed record EventInfo(Biome Biome)
		{
			public Dictionary<int, SpawnSystemData> SpawnData { get; } = new Dictionary<int, SpawnSystemData>();

			public HashSet<int> SpawnAreas { get; } = new HashSet<int>();

			[CompilerGenerated]
			public void Deconstruct(out Biome Biome)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected I4, but got Unknown
				Biome = (Biome)(int)this.Biome;
			}
		}

		private readonly Dictionary<Biome, int> _levelIncreasePerBiome = new Dictionary<Biome, int>();

		private readonly Dictionary<Vector2s, SectorState> _sectorStates = new Dictionary<Vector2s, SectorState>();

		private readonly Dictionary<(Biome, int Prefab), List<SpawnSystemData>> _spawnData = new Dictionary<(Biome, int), List<SpawnSystemData>>();

		private readonly Dictionary<string, EventInfo> _spawnDataByEvent = new Dictionary<string, EventInfo>();

		private static readonly int __initialLevelHash = ServersideQoLPluginBase<CreatureLevelUpPlugin, Config>.RegisterServerVar("InitialLevel");

		protected override void Initialize()
		{
			_sectorStates.Clear();
			_spawnData.Clear();
			ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged -= InitializeData;
			if (ConfigBase<Config>.Instance.MaxLevelIncrease.Value > 0 || ConfigBase<Config>.Instance.MaxLevelIncreasePerDefeatedBoss.Value > 0)
			{
				InitializeData();
				ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged += InitializeData;
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: 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_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: 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_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Expected I4, but got Unknown
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			ProcessResult val = (ProcessResult)2;
			if ((object)prefabInfo != null)
			{
				CreatureSpawner creatureSpawner = prefabInfo.CreatureSpawner;
				if (creatureSpawner == null)
				{
					SpawnArea spawnArea = prefabInfo.SpawnArea;
					if (spawnArea == null)
					{
						Character character = prefabInfo.Character;
						if (character != null)
						{
							Faction faction = character.m_faction;
							if ((int)faction != 11)
							{
								val |= LevelUpCharacter(zdo, prefabInfo.Character);
							}
						}
					}
					else
					{
						Vector2s zone = ZoneSystem.GetZone(zdo.ZDO.GetPosition() - new Vector3(prefabInfo.SpawnArea.m_spawnRadius, 0f, prefabInfo.SpawnArea.m_spawnRadius));
						Vector2s zone2 = ZoneSystem.GetZone(zdo.ZDO.GetPosition() + new Vector3(prefabInfo.SpawnArea.m_spawnRadius, 0f, prefabInfo.SpawnArea.m_spawnRadius));
						ZDOVars vars = zdo.Vars;
						Biome val2 = (Biome)((ZDOVars)(ref vars)).GetLevel(0);
						if ((int)val2 == 0)
						{
							val2 = Processor.GetBiome(zdo.ZDO.GetPosition());
							RandomEvent currentEvent = PrivateAccessor.GetCurrentEvent(RandEventSystem.instance);
							if (currentEvent != null && GetEventInfo(currentEvent, out EventInfo eventInfo) && eventInfo.SpawnAreas.Contains(zdo.ZDO.GetPrefab()))
							{
								Vector2s val3 = ZoneSystem.GetZone(currentEvent.m_pos - new Vector3(currentEvent.m_eventRange, 0f, currentEvent.m_eventRange)) - new Vector2s(1, 1);
								Vector2s val4 = ZoneSystem.GetZone(currentEvent.m_pos + new Vector3(currentEvent.m_eventRange, 0f, currentEvent.m_eventRange)) + new Vector2s(1, 1);
								Vector2s sector = zdo.ZDO.GetSector();
								if (sector.x >= val3.x && sector.x <= val4.x && sector.y >= val3.y && sector.y <= val4.y)
								{
									val2 = eventInfo.Biome;
									vars = zdo.Vars;
									((ZDOVars)(ref vars)).SetLevel((int)val2, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureLevelUpProcessor.cs", 79);
								}
							}
						}
						Vector2s key = default(Vector2s);
						for (short num = zone.x; num <= zone2.x; num++)
						{
							for (short num2 = zone.y; num2 <= zone2.y; num2++)
							{
								((Vector2s)(ref key))..ctor(num, num2);
								if (!_sectorStates.TryGetValue(key, out SectorState value))
								{
									_sectorStates.Add(key, value = new SectorState());
								}
								foreach (SpawnData prefab in prefabInfo.SpawnArea.m_prefabs)
								{
									int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)prefab.m_prefab).name, true);
									if (!value.SpawnAreasBySpawned.TryGetValue(stableHashCode, out List<SectorState.SpawnAreaData> list))
									{
										value.SpawnAreasBySpawned.Add(stableHashCode, list = new List<SectorState.SpawnAreaData>());
									}
									list.Add(new SectorState.SpawnAreaData(zdo.ZDO.m_uid, zdo.ZDO.GetPosition(), val2, prefabInfo.SpawnArea.m_spawnRadius, stableHashCode, prefab.m_minLevel, prefab.m_maxLevel, prefabInfo.SpawnArea.m_levelupChance));
									zdo.Destroyed += delegate(ServersideQoLZDO x)
									{
										list.RemoveAll((SectorState.SpawnAreaData y) => y.ID == x.ZDO.m_uid);
									};
								}
							}
						}
					}
				}
				else
				{
					val |= LevelUpSpawner(zdo, prefabInfo.CreatureSpawner);
					if ((val & 8) != 0)
					{
						Vector2s sector2 = zdo.ZDO.GetSector();
						if (!_sectorStates.TryGetValue(sector2, out SectorState value2))
						{
							_sectorStates.Add(sector2, value2 = new SectorState());
						}
						int stableHashCode2 = StringExtensionMethods.GetStableHashCode(((Object)prefabInfo.CreatureSpawner.m_creaturePrefab).name, true);
						if (!value2.CreatureSpawnersBySpawned.TryGetValue(stableHashCode2, out List<ServersideQoLZDO> list2))
						{
							value2.CreatureSpawnersBySpawned.Add(stableHashCode2, list2 = new List<ServersideQoLZDO>());
						}
						if (!list2.Contains(zdo))
						{
							list2.Add(zdo);
							zdo.Destroyed += delegate(ServersideQoLZDO x)
							{
								list2.Remove(x);
							};
						}
					}
				}
			}
			return val;
		}

		private void InitializeData()
		{
			//IL_006c: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			_levelIncreasePerBiome.Clear();
			Dictionary<string, Biome> dictionary = new Dictionary<string, Biome>();
			if (ConfigBase<Config>.Instance.MaxLevelIncreasePerDefeatedBoss.Value > 0)
			{
				int num = 0;
				foreach (var (val3, val4) in Processor.BossesByBiome.OrderByDescending((KeyValuePair<Biome, Character> x) => x.Value.m_health))
				{
					if (ZoneSystem.instance.GetGlobalKey(val4.m_defeatSetGlobalKey))
					{
						num += ConfigBase<Config>.Instance.MaxLevelIncreasePerDefeatedBoss.Value;
					}
					_levelIncreasePerBiome.Add(val3, num);
					dictionary.Add(val4.m_defeatSetGlobalKey, val3);
				}
				if (_levelIncreasePerBiome.TryGetValue(ConfigBase<Config>.Instance.TreatOceanAs.Value, out var value))
				{
					_levelIncreasePerBiome.Add((Biome)256, value);
				}
			}
			_spawnData.Clear();
			foreach (SpawnData item in ZoneSystem.instance.m_zoneCtrlPrefab.GetComponent<SpawnSystem>().m_spawnLists.SelectMany((SpawnSystemList x) => x.m_spawners))
			{
				if (!item.m_enabled || item.m_prefab.GetComponent<Character>() == null || (!string.IsNullOrEmpty(item.m_requiredGlobalKey) && !ZoneSystem.instance.GetGlobalKey(item.m_requiredGlobalKey)))
				{
					continue;
				}
				foreach (Biome acceptableValue in AcceptableEnum<Biome>.Default.AcceptableValues)
				{
					if (((Enum)item.m_biome).HasFlag((Enum)(object)acceptableValue))
					{
						int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)item.m_prefab).name, true);
						if (!_spawnData.TryGetValue((acceptableValue, stableHashCode), out List<SpawnSystemData> value2))
						{
							_spawnData.Add((acceptableValue, stableHashCode), value2 = new List<SpawnSystemData>());
						}
						value2.Add(new SpawnSystemData(item, dictionary.TryGetValue(item.m_requiredGlobalKey ?? "", out var value3) ? new Biome?(value3) : ((Biome?)null)));
					}
				}
			}
			foreach (List<SpawnSystemData> value4 in _spawnData.Values)
			{
				value4.Sort((SpawnSystemData a, SpawnSystemData b) => b.MaxLevel - a.MaxLevel);
			}
		}

		private ProcessResult LevelUpSpawner(ServersideQoLZDO zdo, CreatureSpawner creatureSpawner)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			ProcessResult val = (ProcessResult)0;
			Biome? val2 = null;
			ComponentFieldAccessor<CreatureSpawner> val3 = zdo.Fields<CreatureSpawner>();
			if (creatureSpawner.m_respawnTimeMinuts <= 0f)
			{
				float num = ConfigBase<Config>.Instance.RespawnOneTimeSpawnsAfterMinutes.Value;
				if (num > 0f)
				{
					if (ConfigBase<Config>.Instance.RespawnOneTimeSpawnsCondition.Value == Config.RespawnOneTimeSpawnsConditions.Never)
					{
						num = 0f;
					}
					else if (ConfigBase<Config>.Instance.RespawnOneTimeSpawnsCondition.Value == Config.RespawnOneTimeSpawnsConditions.AfterBossDefeated)
					{
						Biome valueOrDefault = val2.GetValueOrDefault();
						if (!val2.HasValue)
						{
							valueOrDefault = Processor.GetBiome(zdo.ZDO.GetPosition());
							val2 = valueOrDefault;
						}
						if (!Processor.BossesByBiome.TryGetValue(val2.Value, out var value) || !ZoneSystem.instance.GetGlobalKey(value.m_defeatSetGlobalKey))
						{
							num = 0f;
						}
					}
				}
				if (val3.UpdateValue((Func<Expression<Func<CreatureSpawner, float>>>)(() => (CreatureSpawner x) => x.m_respawnTimeMinuts), num, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureLevelUpProcessor.cs", 177))
				{
					val = (ProcessResult)(val | 8);
				}
			}
			int num2 = ConfigBase<Config>.Instance.MaxLevelIncrease.Value;
			if (ConfigBase<Config>.Instance.MaxLevelIncreasePerDefeatedBoss.Value > 0)
			{
				Biome valueOrDefault = val2.GetValueOrDefault();
				if (!val2.HasValue)
				{
					valueOrDefault = Processor.GetBiome(zdo.ZDO.GetPosition());
					val2 = valueOrDefault;
				}
				if (_levelIncreasePerBiome.TryGetValue(val2.Value, out var value2))
				{
					num2 += value2;
				}
			}
			int num3 = creatureSpawner.m_maxLevel + num2;
			if (val3.UpdateValue((Func<Expression<Func<CreatureSpawner, int>>>)(() => (CreatureSpawner x) => x.m_maxLevel), num3, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureLevelUpProcessor.cs", 190))
			{
				val = (ProcessResult)(val | 8);
			}
			float levelupChance = creatureSpawner.m_levelupChance;
			int num4 = num3 - creatureSpawner.m_minLevel;
			if (num4 > 0)
			{
				levelupChance /= 100f;
				if (creatureSpawner.m_maxLevel > creatureSpawner.m_minLevel)
				{
					levelupChance = Mathf.Pow(levelupChance, (float)(creatureSpawner.m_maxLevel - creatureSpawner.m_minLevel));
				}
				levelupChance = Mathf.Pow(levelupChance, 1f / (float)num4) * 100f;
				if (val3.UpdateValue((Func<Expression<Func<CreatureSpawner, float>>>)(() => (CreatureSpawner x) => x.m_levelupChance), levelupChance, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureLevelUpProcessor.cs", 201))
				{
					val = (ProcessResult)(val | 8);
				}
			}
			return val;
		}

		private ProcessResult LevelUpCharacter(ServersideQoLZDO zdo, Character character)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			ProcessResult val = (ProcessResult)0;
			if (character is Player)
			{
				return val;
			}
			int initialLevel = GetInitialLevel(zdo);
			ZDOVars vars;
			if (initialLevel != 0)
			{
				if (initialLevel > 0 && ConfigBase<Config>.Instance.MaxLevelIncrease.Value == 0 && ConfigBase<Config>.Instance.MaxLevelIncreasePerDefeatedBoss.Value == 0)
				{
					vars = zdo.Vars;
					((ZDOVars)(ref vars)).SetLevel(initialLevel, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureLevelUpProcessor.cs", 220);
					RemoveInitialLevel(zdo);
				}
				return val;
			}
			if (ConfigBase<Config>.Instance.MaxLevelIncrease.Value == 0 && ConfigBase<Config>.Instance.MaxLevelIncreasePerDefeatedBoss.Value == 0)
			{
				return val;
			}
			vars = zdo.Vars;
			if (((ZDOVars)(ref vars)).GetTamed(false))
			{
				return val;
			}
			if (_sectorStates.TryGetValue(zdo.ZDO.GetSector(), out SectorState value) && value.CreatureSpawnersBySpawned.TryGetValue(zdo.ZDO.GetPrefab(), out List<ServersideQoLZDO> value2) && value2.Any((ServersideQoLZDO x) => x.ZDO.GetConnectionZDOID((ConnectionType)3) == zdo.ZDO.m_uid))
			{
				initialLevel = -1;
			}
			else
			{
				vars = zdo.Vars;
				initialLevel = ((ZDOVars)(ref vars)).GetLevel(1);
			}
			SetInitialLevel(zdo, initialLevel);
			if (initialLevel <= 0)
			{
				return val;
			}
			vars = zdo.Vars;
			Vector3 pos = ((ZDOVars)(ref vars)).GetSpawnPoint(zdo.ZDO.GetPosition());
			int num = ConfigBase<Config>.Instance.MaxLevelIncrease.Value;
			SpawnData spawnData;
			if (character.m_boss)
			{
				if (!ConfigBase<Config>.Instance.LevelUpBosses.Value)
				{
					return val;
				}
				spawnData = new SpawnData(zdo.ZDO.GetPrefab(), 1, 1, 0f);
				Biome biome;
				if (_levelIncreasePerBiome.TryGetValue(biome = Processor.GetBiome(pos), out var value3))
				{
					num += value3;
				}
			}
			else
			{
				vars = zdo.Vars;
				Biome biome;
				if (!((ZDOVars)(ref vars)).GetEventCreature(false))
				{
					if (value != null && value.SpawnAreasBySpawned.TryGetValue(zdo.ZDO.GetPrefab(), out List<SectorState.SpawnAreaData> value4))
					{
						SectorState.SpawnAreaData spawnAreaData = value4.FirstOrDefault((SectorState.SpawnAreaData x) => Vector3.Distance(x.Position, pos) <= x.Radius);
						if ((object)spawnAreaData != null)
						{
							spawnData = spawnAreaData;
							if (_levelIncreasePerBiome.TryGetValue(biome = spawnAreaData.Biome, out var value5))
							{
								num += value5;
							}
							goto IL_049d;
						}
					}
					biome = Processor.GetBiome(pos);
					float? distanceFromCenter = null;
					if (_spawnData.TryGetValue((biome, zdo.ZDO.GetPrefab()), out List<SpawnSystemData> value6))
					{
						SpawnSystemData spawnSystemData = value6.FirstOrDefault(delegate(SpawnSystemData x)
						{
							//IL_0020: Unknown result type (might be due to invalid IL or missing references)
							float valueOrDefault = distanceFromCenter.GetValueOrDefault();
							float distanceFromCenter2;
							if (!distanceFromCenter.HasValue)
							{
								valueOrDefault = Utils.LengthXZ(pos);
								distanceFromCenter = valueOrDefault;
								distanceFromCenter2 = valueOrDefault;
							}
							else
							{
								distanceFromCenter2 = valueOrDefault;
							}
							return IsValidSpawnData(x, distanceFromCenter2);
						});
						if ((object)spawnSystemData != null)
						{
							spawnData = spawnSystemData;
							if (spawnSystemData.BiomeOverwrite.HasValue)
							{
								biome = spawnSystemData.BiomeOverwrite.Value;
							}
							if (_levelIncreasePerBiome.TryGetValue(biome, out var value7))
							{
								num += value7;
							}
							goto IL_049d;
						}
					}
					string text = ((value6 == null) ? "" : string.Join(Environment.NewLine + "  ", value6.Select((SpawnSystemData x) => $"{((Object)x.Data.m_prefab).name} ({x.Prefab}): {x.Data.m_biome}, day: {x.Data.m_spawnAtDay}, night: {x.Data.m_spawnAtNight}").Prepend("")));
					((Processor)this).Logger.LogWarning((object)$"{zdo.PrefabInfo.PrefabName} ({zdo.ZDO.GetPrefab()}): Spawn source not found in {biome}, day: {EnvMan.IsDay()}, night: {EnvMan.IsNight()}{text}");
					return val;
				}
				RandomEvent currentEvent = PrivateAccessor.GetCurrentEvent(RandEventSystem.instance);
				if (currentEvent == null)
				{
					((Processor)this).Logger.LogWarning((object)(zdo.PrefabInfo.PrefabName + " is an event creature, but no active event was found"));
					return val;
				}
				if (!GetEventInfo(currentEvent, out EventInfo eventInfo))
				{
					return val;
				}
				if (!eventInfo.SpawnData.TryGetValue(zdo.ZDO.GetPrefab(), out SpawnSystemData value8))
				{
					((Processor)this).Logger.LogWarning((object)(zdo.PrefabInfo.PrefabName + ": Spawn source not found in event " + currentEvent.m_name));
					return val;
				}
				spawnData = value8;
				if (_levelIncreasePerBiome.TryGetValue(biome = eventInfo.Biome, out var value9))
				{
					num += value9;
				}
			}
			goto IL_049d;
			IL_049d:
			if (num <= 0)
			{
				return val;
			}
			int num2 = spawnData.MaxLevel + num;
			float num3 = SpawnSystem.GetLevelUpChance(spawnData.LevelUpChance);
			int num4 = num2 - spawnData.MinLevel;
			if (num4 != 0)
			{
				num3 /= 100f;
				if (spawnData.MaxLevel > spawnData.MinLevel)
				{
					num3 = Mathf.Pow(num3, (float)(spawnData.MaxLevel - spawnData.MinLevel));
				}
				num3 = Mathf.Pow(num3, 1f / (float)num4) * 100f;
			}
			int num5;
			for (num5 = Math.Min(spawnData.MinLevel, spawnData.MaxLevel); num5 < num2; num5++)
			{
				if (!(Random.Range(0f, 100f) <= num3))
				{
					break;
				}
			}
			if (num5 == initialLevel)
			{
				return val;
			}
			vars = zdo.Vars;
			((ZDOVars)(ref vars)).SetLevel(num5, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureLevelUpProcessor.cs", 332);
			return (ProcessResult)(val | 8);
		}

		private static bool IsValidSpawnData(SpawnSystemData data, float distanceFromCenter)
		{
			if (!data.Data.m_spawnAtDay && EnvMan.IsDay())
			{
				return false;
			}
			if (!data.Data.m_spawnAtNight && EnvMan.IsNight())
			{
				return false;
			}
			if (data.Data.m_minDistanceFromCenter > 0f && data.Data.m_minDistanceFromCenter > distanceFromCenter)
			{
				return false;
			}
			if (data.Data.m_maxDistanceFromCenter > 0f && data.Data.m_maxDistanceFromCenter < distanceFromCenter)
			{
				return false;
			}
			return true;
		}

		private bool GetEventInfo(RandomEvent currentEvent, [NotNullWhen(true)] out EventInfo? eventInfo)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			if (!_spawnDataByEvent.TryGetValue(currentEvent.m_name, out eventInfo))
			{
				Biome val = (Biome)0;
				foreach (var (val4, val5) in Processor.BossesByBiome.OrderBy((KeyValuePair<Biome, Character> x) => x.Value.m_health))
				{
					if ((int)val == 0)
					{
						if (currentEvent.m_requiredGlobalKeys.Contains(val5.m_defeatSetGlobalKey))
						{
							val = val4;
						}
						continue;
					}
					val = val4;
					break;
				}
				if ((int)val == 0)
				{
					((Processor)this).Logger.LogWarning((object)("Associated boss for event " + currentEvent.m_name + " not found"));
					return false;
				}
				eventInfo = new EventInfo(val);
				_spawnDataByEvent.Add(currentEvent.m_name, eventInfo);
				foreach (SpawnData item in currentEvent.m_spawn)
				{
					if (item.m_prefab.GetComponent<Character>() != null)
					{
						eventInfo.SpawnData.Add(StringExtensionMethods.GetStableHashCode(((Object)item.m_prefab).name, true), new SpawnSystemData(item, val));
					}
					else if (item.m_prefab.GetComponent<SpawnArea>() != null)
					{
						eventInfo.SpawnAreas.Add(StringExtensionMethods.GetStableHashCode(((Object)item.m_prefab).name, true));
					}
				}
			}
			return true;
		}

		private static int GetInitialLevel(ServersideQoLZDO zdo, int defaultValue = 0)
		{
			return zdo.ZDO.GetInt(__initialLevelHash, defaultValue);
		}

		private static void SetInitialLevel(ServersideQoLZDO zdo, int value)
		{
			zdo.ZDO.Set(__initialLevelHash, value, false);
		}

		private static void RemoveInitialLevel(ServersideQoLZDO zdo)
		{
			zdo.ZDO.RemoveInt(__initialLevelHash);
		}
	}
	[Processor("0d2b80d6-03bc-49d7-87e0-6b97bd10925e")]
	[RunAfter<CreatureLevelUpProcessor>]
	public sealed class CreatureProcessor : Processor<CreatureProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(Character Character, LevelEffects? LevelEffects, ZSyncTransform? ZSyncTransform) : ProcessorPrefabInfo()
		{
			public bool SyncsInitialScale { get; } = ((Component)Character).GetComponent<ZNetView>().m_syncInitialScale;

			[CompilerGenerated]
			public override string ToString()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("PrefabInfo");
				stringBuilder.Append(" { ");
				if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append('}');
				return stringBuilder.ToString();
			}

			[CompilerGenerated]
			protected override bool PrintMembers(StringBuilder builder)
			{
				if (((ProcessorPrefabInfo)this).PrintMembers(builder))
				{
					builder.Append(", ");
				}
				builder.Append("Character = ");
				builder.Append(Character);
				builder.Append(", LevelEffects = ");
				builder.Append(LevelEffects);
				builder.Append(", ZSyncTransform = ");
				builder.Append(ZSyncTransform);
				builder.Append(", SyncsInitialScale = ");
				builder.Append(SyncsInitialScale.ToString());
				return true;
			}

			[CompilerGenerated]
			public override int GetHashCode()
			{
				return (((((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<Character>.Default.GetHashCode(Character)) * -1521134295 + EqualityComparer<LevelEffects>.Default.GetHashCode(LevelEffects)) * -1521134295 + EqualityComparer<ZSyncTransform>.Default.GetHashCode(ZSyncTransform)) * -1521134295 + EqualityComparer<bool>.Default.GetHashCode(SyncsInitialScale);
			}

			[CompilerGenerated]
			public sealed override bool Equals(ProcessorPrefabInfo? other)
			{
				return ((object)this).Equals((object?)other);
			}

			[CompilerGenerated]
			public bool Equals(PrefabInfo? other)
			{
				if ((object)this != other)
				{
					if (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<Character>.Default.Equals(Character, other.Character) && EqualityComparer<LevelEffects>.Default.Equals(LevelEffects, other.LevelEffects) && EqualityComparer<ZSyncTransform>.Default.Equals(ZSyncTransform, other.ZSyncTransform))
					{
						return EqualityComparer<bool>.Default.Equals(SyncsInitialScale, other.SyncsInitialScale);
					}
					return false;
				}
				return true;
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				Character = original.Character;
				LevelEffects = original.LevelEffects;
				ZSyncTransform = original.ZSyncTransform;
				SyncsInitialScale = original.SyncsInitialScale;
			}
		}

		private HashSet<ServersideQoLZDO> _zdos = new HashSet<ServersideQoLZDO>();

		private HashSet<ServersideQoLZDO> _zdosPrev = new HashSet<ServersideQoLZDO>();

		private DateTimeOffset _nextCheck;

		protected override void PreProcess(PeersEnumerable peers)
		{
			HashSet<ServersideQoLZDO> zdosPrev = _zdosPrev;
			HashSet<ServersideQoLZDO> zdos = _zdos;
			_zdos = zdosPrev;
			_zdosPrev = zdos;
			_zdos.Clear();
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			ZDOVars vars = zdo.Vars;
			int level = ((ZDOVars)(ref vars)).GetLevel(1);
			if (level <= 1)
			{
				return (ProcessResult)2;
			}
			int num = (prefabInfo.LevelEffects?.m_levelSetups.Count ?? 0) + 1;
			if (level <= num)
			{
				return (ProcessResult)2;
			}
			ProcessResult val = (ProcessResult)0;
			if (level > 3)
			{
				ComponentFieldAccessor<Character> val2 = zdo.Fields<Character>();
				if (!ConfigBase<Config>.Instance.ShowHigherLevelStars.Value)
				{
					val2.Reset((Func<Expression<Func<Character, string>>>)(() => (Character x) => x.m_name), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureProcessor.cs", 39);
				}
				else if (val2.UpdateValue((Func<Expression<Func<Character, string>>>)(() => (Character x) => x.m_name), ConfigBase<Config>.Instance.Advanced.Value.HigherLevelStarName(prefabInfo.Character, level), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureProcessor.cs", 40))
				{
					val = (ProcessResult)8;
				}
			}
			if (prefabInfo.ZSyncTransform == null)
			{
				return (ProcessResult)(val | 2);
			}
			float num2 = (ConfigBase<Config>.Instance.Advanced.Value.ScaleSizeExponentially ? Mathf.Pow(1f + ConfigBase<Config>.Instance.SizeIncreasePerStar.Value, (float)(level - 1)) : (1f + (float)(level - 1) * ConfigBase<Config>.Instance.SizeIncreasePerStar.Value));
			if (num2 == 1f)
			{
				zdo.Fields<ZSyncTransform>().Reset((Func<Expression<Func<ZSyncTransform, bool>>>)(() => (ZSyncTransform x) => x.m_syncScale), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureProcessor.cs", 51);
			}
			else if (zdo.Fields<ZSyncTransform>().UpdateValue((Func<Expression<Func<ZSyncTransform, bool>>>)(() => (ZSyncTransform x) => x.m_syncScale), true, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureProcessor.cs", 52))
			{
				return (ProcessResult)8;
			}
			if (prefabInfo.SyncsInitialScale)
			{
				if (zdo.ZDO.GetFloat(ZDOVars.s_scaleScalarHash, 0f) != num2)
				{
					zdo.ZDO.RemoveVec3(ZDOVars.s_scaleHash);
					zdo.ZDO.Set(ZDOVars.s_scaleScalarHash, num2);
					return (ProcessResult)8;
				}
				return (ProcessResult)2;
			}
			if (num2 == 1f)
			{
				return (ProcessResult)(val | 2);
			}
			_zdos.Add(zdo);
			if (!_zdosPrev.Contains(zdo))
			{
				vars = zdo.Vars;
				((ZDOVars)(ref vars)).RemoveScale("C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureProcessor.cs", 75);
				_nextCheck = DateTimeOffset.UtcNow.AddSeconds(1.0);
				vars = zdo.Vars;
				((ZDOVars)(ref vars)).SetScaleScalar(num2, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.CreatureLevelUp\\CreatureProcessor.cs", 78);
				zdo.ReleaseOwnership();
			}
			val = (ProcessResult)(val | 0x20);
			if (!zdo.ZDO.HasOwner())
			{
				return val;
			}
			if (DateTimeOffset.UtcNow < _nextCheck)
			{
				return val;
			}
			vars = zdo.Vars;
			if (((ZDOVars)(ref vars)).GetScale(default(Vector3)).x != num2)
			{
				_zdos.Remove(zdo);
			}
			return val;
		}
	}
}