Decompiled source of ValheimBestiary v0.2.0

ValheimBestiary.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ValheimBestiary;

public class MonsterEntry
{
	public string PrefabName;

	public string CleanName;

	public string Biome;

	public string Description = "Brak dostępnych zapisków o tym stworzeniu.";

	public float Health = 0f;

	public float Damage = 0f;

	public string Weaknesses = "Brak";

	public string Resistances = "Brak";

	public bool IsTameable = false;

	public List<TameFoodInfo> TameFoods = new List<TameFoodInfo>();

	public string Behavior = "Neutralny";

	public bool Discovered = false;

	public List<DropInfo> Drops = new List<DropInfo>();
}
public class TameFoodInfo
{
	public string Name;

	public Sprite Icon;
}
public class DropInfo
{
	public string ItemName;

	public string Amount;

	public int Chance;

	public Sprite ItemSprite;
}
[BepInPlugin("com.twojanazwa.valheimbestiary", "Valheim Bestiary", "0.2")]
public class BestiaryPlugin : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("com.twojanazwa.valheimbestiary");

	public static Dictionary<string, MonsterEntry> AllMonsters = new Dictionary<string, MonsterEntry>();

	public static Dictionary<string, int> KillCounts = new Dictionary<string, int>();

	public static bool ShowUI = false;

	private string searchText = "";

	private MonsterEntry selectedMonster = null;

	private Vector2 scrollPos;

	private Rect mainRect;

	private Rect detailRect;

	private bool rectsInitialized = false;

	private GUIStyle windowStyle;

	private GUIStyle titleStyle;

	private GUIStyle searchLabelStyle;

	private GUIStyle searchFieldStyle;

	private GUIStyle clearBtnStyle;

	private GUIStyle closeBtnStyle;

	private GUIStyle cardStyle;

	private GUIStyle lockedSlotStyle;

	private GUIStyle rowStyle;

	private GUIStyle footerStyle;

	private GUIStyle descStyle;

	private GUIStyle iconBoxStyle;

	private GUIStyle statBadgeStyle;

	private GUIStyle statLabelStyle;

	private GUIStyle tableHeaderStyle;

	private GUIStyle tableRowStyle;

	private bool stylesInitialized = false;

	private static Texture2D woodBoardTexture;

	private static Texture2D cardActiveTexture;

	private static Texture2D cardHoverTexture;

	private static Texture2D slotLockedTexture;

	private static Texture2D inputFieldTexture;

	private static Texture2D btnTexture;

	private static Texture2D rowTexture;

	private static GameObject previewRoot;

	private static Camera previewCamera;

	private static Light previewLight;

	private static RenderTexture previewRenderTexture;

	private static GameObject currentMonsterModel;

	private static readonly Vector3 StagePos = new Vector3(0f, -2500f, 0f);

	private static string SaveFilePath => Path.Combine(Paths.ConfigPath, "ValheimBestiary_Progress.txt");

	private void Awake()
	{
		LoadProgress();
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Valheim Bestiary v0.2 zaladowany!");
	}

	private void Update()
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown((KeyCode)287))
		{
			SetUIState(!ShowUI);
		}
		if (ShowUI && Input.GetKeyDown((KeyCode)27))
		{
			if (selectedMonster != null)
			{
				SelectMonster(null);
			}
			else
			{
				SetUIState(open: false);
			}
		}
		if (ShowUI)
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			if ((Object)(object)currentMonsterModel != (Object)null)
			{
				currentMonsterModel.transform.Rotate(Vector3.up, 35f * Time.deltaTime, (Space)0);
			}
		}
	}

	private void SetUIState(bool open)
	{
		ShowUI = open;
		if (!ShowUI)
		{
			SelectMonster(null);
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
			DestroyPreviewStudio();
		}
		else
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}
	}

	private void SelectMonster(MonsterEntry mob)
	{
		selectedMonster = mob;
		if (selectedMonster != null)
		{
			SetupModelPreview(selectedMonster.PrefabName);
		}
		else
		{
			DestroyPreviewModel();
		}
	}

	private void EnsurePreviewStudio()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Expected O, but got Unknown
		//IL_0166: 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)
		if (!((Object)(object)previewRoot != (Object)null))
		{
			previewRoot = new GameObject("Bestiary_3D_Studio");
			previewRoot.transform.position = StagePos;
			Object.DontDestroyOnLoad((Object)(object)previewRoot);
			previewRenderTexture = new RenderTexture(256, 256, 16, (RenderTextureFormat)0)
			{
				antiAliasing = 2
			};
			previewRenderTexture.Create();
			GameObject val = new GameObject("Bestiary_Cam");
			val.transform.SetParent(previewRoot.transform);
			previewCamera = val.AddComponent<Camera>();
			previewCamera.clearFlags = (CameraClearFlags)2;
			previewCamera.backgroundColor = new Color(0.08f, 0.06f, 0.05f, 1f);
			previewCamera.targetTexture = previewRenderTexture;
			previewCamera.nearClipPlane = 0.1f;
			previewCamera.farClipPlane = 100f;
			previewCamera.fieldOfView = 30f;
			GameObject val2 = new GameObject("Bestiary_Light");
			val2.transform.SetParent(previewRoot.transform);
			previewLight = val2.AddComponent<Light>();
			previewLight.type = (LightType)1;
			previewLight.intensity = 1.35f;
			previewLight.color = new Color(1f, 0.95f, 0.85f);
			val2.transform.rotation = Quaternion.Euler(25f, 30f, 0f);
		}
	}

	private void SetupModelPreview(string prefabName)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0502: Unknown result type (might be due to invalid IL or missing references)
		//IL_0511: Unknown result type (might be due to invalid IL or missing references)
		//IL_0495: 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_0488: Unknown result type (might be due to invalid IL or missing references)
		//IL_056f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_0585: Unknown result type (might be due to invalid IL or missing references)
		//IL_059a: Unknown result type (might be due to invalid IL or missing references)
		EnsurePreviewStudio();
		DestroyPreviewModel();
		if ((Object)(object)ZNetScene.instance == (Object)null)
		{
			return;
		}
		GameObject prefab = ZNetScene.instance.GetPrefab(prefabName);
		if ((Object)(object)prefab == (Object)null)
		{
			return;
		}
		bool activeSelf = prefab.activeSelf;
		prefab.SetActive(false);
		currentMonsterModel = Object.Instantiate<GameObject>(prefab, StagePos, Quaternion.identity);
		prefab.SetActive(activeSelf);
		((Object)currentMonsterModel).name = "Bestiary_Preview_" + prefabName;
		currentMonsterModel.transform.SetParent(previewRoot.transform);
		ZNetView[] componentsInChildren = currentMonsterModel.GetComponentsInChildren<ZNetView>(true);
		foreach (ZNetView val in componentsInChildren)
		{
			Object.DestroyImmediate((Object)(object)val);
		}
		ZSyncTransform[] componentsInChildren2 = currentMonsterModel.GetComponentsInChildren<ZSyncTransform>(true);
		foreach (ZSyncTransform val2 in componentsInChildren2)
		{
			Object.DestroyImmediate((Object)(object)val2);
		}
		ZSyncAnimation[] componentsInChildren3 = currentMonsterModel.GetComponentsInChildren<ZSyncAnimation>(true);
		foreach (ZSyncAnimation val3 in componentsInChildren3)
		{
			Object.DestroyImmediate((Object)(object)val3);
		}
		CharacterAnimEvent[] componentsInChildren4 = currentMonsterModel.GetComponentsInChildren<CharacterAnimEvent>(true);
		foreach (CharacterAnimEvent val4 in componentsInChildren4)
		{
			Object.DestroyImmediate((Object)(object)val4);
		}
		MonoBehaviour[] componentsInChildren5 = currentMonsterModel.GetComponentsInChildren<MonoBehaviour>(true);
		for (int num = componentsInChildren5.Length - 1; num >= 0; num--)
		{
			if ((Object)(object)componentsInChildren5[num] != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren5[num]);
			}
		}
		Component[] componentsInChildren6 = currentMonsterModel.GetComponentsInChildren<Component>(true);
		foreach (Component val5 in componentsInChildren6)
		{
			if ((Object)(object)val5 == (Object)null)
			{
				continue;
			}
			string name = ((object)val5).GetType().Name;
			if (name.EndsWith("Collider"))
			{
				PropertyInfo property = ((object)val5).GetType().GetProperty("enabled");
				if (property != null && property.CanWrite)
				{
					property.SetValue(val5, false, null);
				}
			}
			else if (name == "Rigidbody" || name == "AudioSource")
			{
				Object.DestroyImmediate((Object)(object)val5);
			}
		}
		Renderer[] componentsInChildren7 = currentMonsterModel.GetComponentsInChildren<Renderer>(true);
		Renderer[] array = componentsInChildren7;
		foreach (Renderer val6 in array)
		{
			if ((Object)(object)val6 != (Object)null)
			{
				((Component)val6).gameObject.SetActive(true);
				val6.enabled = true;
				SkinnedMeshRenderer val7 = (SkinnedMeshRenderer)(object)((val6 is SkinnedMeshRenderer) ? val6 : null);
				if (val7 != null)
				{
					val7.updateWhenOffscreen = true;
				}
			}
		}
		currentMonsterModel.SetActive(true);
		Component[] componentsInChildren8 = currentMonsterModel.GetComponentsInChildren<Component>(true);
		foreach (Component val8 in componentsInChildren8)
		{
			if (!((Object)(object)val8 != (Object)null) || !(((object)val8).GetType().Name == "Animator"))
			{
				continue;
			}
			PropertyInfo property2 = ((object)val8).GetType().GetProperty("enabled");
			if (property2 != null && property2.CanWrite)
			{
				property2.SetValue(val8, true, null);
			}
			try
			{
				MethodInfo method = ((object)val8).GetType().GetMethod("SetFloat", new Type[2]
				{
					typeof(string),
					typeof(float)
				});
				if (method != null)
				{
					method.Invoke(val8, new object[2] { "forward_speed", 0f });
					method.Invoke(val8, new object[2] { "sideway_speed", 0f });
				}
			}
			catch
			{
			}
		}
		Bounds bounds = default(Bounds);
		((Bounds)(ref bounds))..ctor(StagePos, Vector3.zero);
		bool flag = false;
		Renderer[] array2 = componentsInChildren7;
		foreach (Renderer val9 in array2)
		{
			if ((Object)(object)val9 != (Object)null && val9.enabled && ((Component)val9).gameObject.activeInHierarchy)
			{
				if (!flag)
				{
					bounds = val9.bounds;
					flag = true;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val9.bounds);
				}
			}
		}
		Vector3 val10 = (flag ? ((Bounds)(ref bounds)).center : (StagePos + new Vector3(0f, 1.2f, 0f)));
		float num4 = (flag ? Mathf.Max(new float[3]
		{
			((Bounds)(ref bounds)).size.x,
			((Bounds)(ref bounds)).size.y,
			((Bounds)(ref bounds)).size.z
		}) : 1.8f);
		if (num4 < 0.4f)
		{
			num4 = 1.8f;
		}
		float num5 = num4 / 2f / Mathf.Tan(previewCamera.fieldOfView * 0.5f * (MathF.PI / 180f)) * 1.35f;
		((Component)previewCamera).transform.position = val10 + new Vector3(0f, num4 * 0.12f, num5);
		((Component)previewCamera).transform.LookAt(val10);
	}

	private void DestroyPreviewModel()
	{
		if ((Object)(object)currentMonsterModel != (Object)null)
		{
			Object.Destroy((Object)(object)currentMonsterModel);
			currentMonsterModel = null;
		}
	}

	private void DestroyPreviewStudio()
	{
		DestroyPreviewModel();
		if ((Object)(object)previewRoot != (Object)null)
		{
			Object.Destroy((Object)(object)previewRoot);
			previewRoot = null;
		}
		if ((Object)(object)previewRenderTexture != (Object)null)
		{
			previewRenderTexture.Release();
			previewRenderTexture = null;
		}
	}

	private Texture2D CreateCleanWoodTexture(int w, int h)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(w, h);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.24f, 0.16f, 0.11f, 0.98f);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0.2f, 0.13f, 0.09f, 0.98f);
		Color val4 = default(Color);
		((Color)(ref val4))..ctor(0.12f, 0.08f, 0.05f, 1f);
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (j < 2 || j >= w - 2 || i < 2 || i >= h - 2)
				{
					val.SetPixel(j, i, val4);
					continue;
				}
				float num = Mathf.Sin((float)i * 0.4f) * 0.5f + 0.5f;
				val.SetPixel(j, i, Color.Lerp(val3, val2, num));
			}
		}
		val.Apply();
		return val;
	}

	private Texture2D CreateGradientSlot(int w, int h, Color top, Color bottom, Color border)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		//IL_0016: 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_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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(w, h);
		for (int i = 0; i < h; i++)
		{
			float num = (float)i / (float)(h - 1);
			Color val2 = Color.Lerp(bottom, top, num);
			for (int j = 0; j < w; j++)
			{
				if (j == 0 || j == w - 1 || i == 0 || i == h - 1)
				{
					val.SetPixel(j, i, border);
				}
				else
				{
					val.SetPixel(j, i, val2);
				}
			}
		}
		val.Apply();
		return val;
	}

	private Texture2D CreateSolid(int w, int h, Color c)
	{
		//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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		Color[] array = (Color[])(object)new Color[w * h];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = c;
		}
		Texture2D val = new Texture2D(w, h);
		val.SetPixels(array);
		val.Apply();
		return val;
	}

	private void InitStyles()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Expected O, but got Unknown
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Expected O, but got Unknown
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Expected O, but got Unknown
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Expected O, but got Unknown
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Expected O, but got Unknown
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Expected O, but got Unknown
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0306: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Expected O, but got Unknown
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Expected O, but got Unknown
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Expected O, but got Unknown
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Expected O, but got Unknown
		//IL_0458: Unknown result type (might be due to invalid IL or missing references)
		//IL_0462: Expected O, but got Unknown
		//IL_046e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Expected O, but got Unknown
		//IL_0499: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Expected O, but got Unknown
		//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Expected O, but got Unknown
		//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e6: Expected O, but got Unknown
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_050d: Expected O, but got Unknown
		//IL_0518: Unknown result type (might be due to invalid IL or missing references)
		//IL_0522: Expected O, but got Unknown
		//IL_0550: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Expected O, but got Unknown
		//IL_057c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0598: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a2: Expected O, but got Unknown
		//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c9: Expected O, but got Unknown
		//IL_05d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: Expected O, but got Unknown
		//IL_0602: Unknown result type (might be due to invalid IL or missing references)
		//IL_0607: Unknown result type (might be due to invalid IL or missing references)
		//IL_0610: Unknown result type (might be due to invalid IL or missing references)
		//IL_061d: Expected O, but got Unknown
		//IL_0628: Unknown result type (might be due to invalid IL or missing references)
		//IL_062d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0636: Unknown result type (might be due to invalid IL or missing references)
		//IL_0643: Expected O, but got Unknown
		if (!stylesInitialized)
		{
			woodBoardTexture = CreateCleanWoodTexture(64, 64);
			cardActiveTexture = CreateGradientSlot(32, 32, new Color(0.24f, 0.18f, 0.12f, 0.95f), new Color(0.16f, 0.12f, 0.08f, 0.95f), new Color(0.5f, 0.38f, 0.22f, 1f));
			cardHoverTexture = CreateGradientSlot(32, 32, new Color(0.35f, 0.26f, 0.16f, 0.98f), new Color(0.22f, 0.16f, 0.1f, 0.98f), new Color(0.7f, 0.54f, 0.28f, 1f));
			slotLockedTexture = CreateGradientSlot(32, 32, new Color(0.18f, 0.13f, 0.09f, 0.7f), new Color(0.12f, 0.09f, 0.06f, 0.7f), new Color(0.24f, 0.18f, 0.12f, 0.6f));
			inputFieldTexture = CreateSolid(2, 2, new Color(0.1f, 0.07f, 0.05f, 0.95f));
			btnTexture = CreateGradientSlot(16, 16, new Color(0.28f, 0.21f, 0.14f, 1f), new Color(0.16f, 0.12f, 0.08f, 1f), new Color(0.4f, 0.3f, 0.18f, 1f));
			rowTexture = CreateSolid(2, 2, new Color(0.15f, 0.11f, 0.08f, 0.88f));
			windowStyle = new GUIStyle(GUI.skin.window);
			windowStyle.normal.background = woodBoardTexture;
			windowStyle.onNormal.background = woodBoardTexture;
			windowStyle.border = new RectOffset(4, 4, 4, 4);
			windowStyle.padding = new RectOffset(24, 24, 20, 20);
			titleStyle = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)1,
				fontSize = 24
			};
			searchLabelStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)3
			};
			searchFieldStyle = new GUIStyle(GUI.skin.textField);
			searchFieldStyle.normal.background = inputFieldTexture;
			searchFieldStyle.normal.textColor = new Color(0.95f, 0.9f, 0.8f);
			searchFieldStyle.fontSize = 16;
			searchFieldStyle.padding = new RectOffset(8, 8, 4, 4);
			clearBtnStyle = new GUIStyle(GUI.skin.button);
			clearBtnStyle.normal.background = btnTexture;
			clearBtnStyle.normal.textColor = new Color(0.92f, 0.85f, 0.7f);
			clearBtnStyle.fontSize = 14;
			closeBtnStyle = new GUIStyle(GUI.skin.button);
			closeBtnStyle.normal.background = btnTexture;
			closeBtnStyle.normal.textColor = new Color(0.85f, 0.8f, 0.7f);
			closeBtnStyle.hover.textColor = Color.white;
			closeBtnStyle.fontSize = 14;
			cardStyle = new GUIStyle(GUI.skin.button);
			cardStyle.normal.background = cardActiveTexture;
			cardStyle.hover.background = cardHoverTexture;
			cardStyle.fontStyle = (FontStyle)1;
			cardStyle.fontSize = 16;
			cardStyle.alignment = (TextAnchor)3;
			cardStyle.padding = new RectOffset(16, 10, 6, 6);
			lockedSlotStyle = new GUIStyle(GUI.skin.box);
			lockedSlotStyle.normal.background = slotLockedTexture;
			rowStyle = new GUIStyle(GUI.skin.box);
			rowStyle.normal.background = rowTexture;
			rowStyle.padding = new RectOffset(12, 12, 10, 10);
			rowStyle.margin = new RectOffset(0, 0, 3, 3);
			descStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				wordWrap = true
			};
			iconBoxStyle = new GUIStyle(GUI.skin.box);
			iconBoxStyle.normal.background = slotLockedTexture;
			iconBoxStyle.alignment = (TextAnchor)4;
			statBadgeStyle = new GUIStyle(GUI.skin.box);
			statBadgeStyle.normal.background = CreateSolid(2, 2, new Color(0.08f, 0.06f, 0.05f, 0.85f));
			statBadgeStyle.padding = new RectOffset(12, 12, 8, 8);
			statLabelStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				alignment = (TextAnchor)3
			};
			tableHeaderStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)3
			};
			tableRowStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				alignment = (TextAnchor)3
			};
			footerStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 14,
				fontStyle = (FontStyle)1
			};
			stylesInitialized = true;
		}
	}

	private void OnGUI()
	{
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Expected O, but got Unknown
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected O, but got Unknown
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		if (ShowUI)
		{
			InitStyles();
			float num = Mathf.Clamp((float)Screen.width * 0.65f, 950f, 1300f);
			float num2 = Mathf.Clamp((float)Screen.height * 0.76f, 680f, 900f);
			if (!rectsInitialized)
			{
				mainRect = new Rect(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
				detailRect = new Rect(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
				rectsInitialized = true;
			}
			GUI.depth = -1000;
			GUI.backgroundColor = Color.white;
			if (selectedMonster == null)
			{
				mainRect = GUI.Window(99211, mainRect, new WindowFunction(DrawGridWindow), "", windowStyle);
			}
			else
			{
				detailRect = GUI.Window(99212, detailRect, new WindowFunction(DrawDetailWindow), "", windowStyle);
			}
		}
	}

	private void DrawGridWindow(int windowID)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: 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_02bf: Unknown result type (might be due to invalid IL or missing references)
		float width = ((Rect)(ref mainRect)).width;
		GUI.DragWindow(new Rect(0f, 0f, width - 50f, 30f));
		if (GUI.Button(new Rect(width - 38f, 10f, 26f, 24f), "✕", closeBtnStyle))
		{
			SetUIState(open: false);
		}
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(2f);
		GUILayout.Label("<color=#FFB444>✦   D Z I E N N I K   B E S T I A R I U S Z A   ✦</color>", titleStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Space(12f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("<color=#F0DFCB>Szukaj potwora:</color>", searchLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) });
		searchText = GUILayout.TextField(searchText, searchFieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
		GUILayout.Space(6f);
		if (GUILayout.Button("Wyczyść", clearBtnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(80f),
			GUILayout.Height(28f)
		}))
		{
			searchText = "";
		}
		GUILayout.EndHorizontal();
		GUILayout.Space(12f);
		List<MonsterEntry> list = (from m in AllMonsters.Values
			where string.IsNullOrEmpty(searchText) || (m.Discovered && m.CleanName.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0) || (!m.Discovered && "???".Contains(searchText))
			orderby !m.Discovered, m.CleanName
			select m).ToList();
		scrollPos = GUILayout.BeginScrollView(scrollPos, false, false, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
		int num = 2;
		float num2 = (width - 95f) / (float)num;
		for (int num3 = 0; num3 < list.Count; num3 += num)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			for (int num4 = 0; num4 < num; num4++)
			{
				int num5 = num3 + num4;
				if (num5 < list.Count)
				{
					MonsterEntry monsterEntry = list[num5];
					if (monsterEntry.Discovered)
					{
						KillCounts.TryGetValue(monsterEntry.PrefabName, out var value);
						GUI.contentColor = new Color(1f, 0.9f, 0.65f);
						if (GUILayout.Button($"■  {monsterEntry.CleanName}  <color=#8C7B68>({value})</color>", cardStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.Height(44f),
							GUILayout.Width(num2)
						}))
						{
							SelectMonster(monsterEntry);
						}
						GUI.contentColor = Color.white;
					}
					else
					{
						GUILayout.Label("", lockedSlotStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.Height(44f),
							GUILayout.Width(num2)
						});
					}
				}
				else
				{
					GUILayout.Label("", lockedSlotStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Height(44f),
						GUILayout.Width(num2)
					});
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
		}
		GUILayout.EndScrollView();
		GUILayout.Space(8f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		int num6 = AllMonsters.Values.Count((MonsterEntry m) => m.Discovered);
		GUILayout.Label($"<color=#E0D3C1>Postęp odkryć: </color><color=#FFB444><b>{num6}</b></color> <color=#9E8D79>/ {AllMonsters.Count}</color>", footerStyle, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		GUILayout.Label("<color=#8C7B68>Valheim Bestiary v0.2</color>", footerStyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
	}

	private void DrawSprite(Rect screenRect, Sprite sprite)
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)sprite == (Object)null || (Object)(object)sprite.texture == (Object)null)
		{
			return;
		}
		try
		{
			Rect textureRect = sprite.textureRect;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref textureRect)).x / (float)((Texture)sprite.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)sprite.texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)sprite.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)sprite.texture).height);
			GUI.DrawTextureWithTexCoords(screenRect, (Texture)(object)sprite.texture, val);
		}
		catch
		{
			GUI.DrawTexture(screenRect, (Texture)(object)sprite.texture, (ScaleMode)2);
		}
	}

	private void DrawDetailWindow(int windowID)
	{
		//IL_0037: 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_012e: 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_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0707: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
		if (selectedMonster == null)
		{
			return;
		}
		float width = ((Rect)(ref detailRect)).width;
		GUI.DragWindow(new Rect(0f, 0f, width - 50f, 30f));
		if (GUI.Button(new Rect(width - 38f, 10f, 26f, 24f), "✕", closeBtnStyle))
		{
			SelectMonster(null);
			return;
		}
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(2f);
		string text = (string.IsNullOrEmpty(selectedMonster.CleanName) ? selectedMonster.PrefabName : selectedMonster.CleanName);
		GUILayout.Label("<color=#FFB444><b>" + text.ToUpper() + "</b></color>", titleStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Space(8f);
		GUILayout.BeginHorizontal(rowStyle, Array.Empty<GUILayoutOption>());
		Rect rect = GUILayoutUtility.GetRect(160f, 160f, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(160f),
			GUILayout.Height(160f)
		});
		GUI.Box(rect, "", iconBoxStyle);
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref rect)).x + 4f, ((Rect)(ref rect)).y + 4f, ((Rect)(ref rect)).width - 8f, ((Rect)(ref rect)).height - 8f);
		if ((Object)(object)previewRenderTexture != (Object)null)
		{
			GUI.DrawTexture(val, (Texture)(object)previewRenderTexture, (ScaleMode)0);
		}
		GUILayout.Space(16f);
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		KillCounts.TryGetValue(selectedMonster.PrefabName ?? "", out var value);
		string arg = (string.IsNullOrEmpty(selectedMonster.Biome) ? "Nieznana" : selectedMonster.Biome);
		GUILayout.Label($"<color=#FFB444>Kategoria:</color> <color=#F0DFCB>{arg}</color>        <color=#FFB444>Zabito:</color> <color=#92F071><b>{value}</b></color>", statLabelStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		string text2 = (string.IsNullOrEmpty(selectedMonster.Description) ? "Brak zapisków." : selectedMonster.Description);
		GUILayout.Label("<color=#D0C1AD><i>„" + text2 + "”</i></color>", descStyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndVertical();
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		GUILayout.BeginHorizontal(statBadgeStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"<color=#E0D3C1>PŻ:</color> <color=#FFFFFF><b>{selectedMonster.Health}</b></color>", statLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
		GUILayout.Label($"<color=#E0D3C1>ATK:</color> <color=#FFFFFF><b>~{selectedMonster.Damage}</b></color>", statLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
		if (selectedMonster.IsTameable)
		{
			GUILayout.Label("<color=#E0D3C1>Oswajanie:</color> <color=#92F071>Tak</color> ", statLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			if (selectedMonster.TameFoods != null)
			{
				foreach (TameFoodInfo tameFood in selectedMonster.TameFoods)
				{
					if (tameFood != null)
					{
						GUILayout.Space(6f);
						if ((Object)(object)tameFood.Icon != (Object)null)
						{
							Rect rect2 = GUILayoutUtility.GetRect(24f, 24f, (GUILayoutOption[])(object)new GUILayoutOption[2]
							{
								GUILayout.Width(24f),
								GUILayout.Height(24f)
							});
							DrawSprite(rect2, tameFood.Icon);
							GUILayout.Space(4f);
						}
						GUILayout.Label("<color=#D4C2AA>" + (tameFood.Name ?? "Jedzenie") + "</color>", statLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
					}
				}
			}
		}
		else
		{
			GUILayout.Label("<color=#E0D3C1>Oswajanie:</color> <color=#FF8844>Nie</color>", statLabelStyle, Array.Empty<GUILayoutOption>());
		}
		GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(statBadgeStyle, Array.Empty<GUILayoutOption>());
		string text3 = (string.IsNullOrEmpty(selectedMonster.Weaknesses) ? "Brak" : selectedMonster.Weaknesses);
		string text4 = (string.IsNullOrEmpty(selectedMonster.Resistances) ? "Brak" : selectedMonster.Resistances);
		GUILayout.Label("<color=#92F071>Podatność:</color> <color=#F0DFCB>" + text3 + "</color>", statLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(width * 0.48f) });
		GUILayout.Label("<color=#F0904B>Odporność:</color> <color=#F0DFCB>" + text4 + "</color>", statLabelStyle, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.Space(8f);
		GUILayout.BeginHorizontal(rowStyle, Array.Empty<GUILayoutOption>());
		GUILayout.Label("<b><color=#FFB444>PRZEDMIOT</color></b>", tableHeaderStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
		GUILayout.Label("<b><color=#FFB444>ILOŚĆ</color></b>", tableHeaderStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
		GUILayout.Label("<b><color=#FFB444>SZANSA</color></b>", tableHeaderStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) });
		GUILayout.EndHorizontal();
		scrollPos = GUILayout.BeginScrollView(scrollPos, false, false, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.MinHeight(120f),
			GUILayout.MaxHeight(260f)
		});
		if (selectedMonster.Drops == null || selectedMonster.Drops.Count == 0)
		{
			GUILayout.Space(25f);
			GUILayout.Label("<color=#A08E7B>Ten stwór nie posiada zdefiniowanego łupu.</color>", descStyle, Array.Empty<GUILayoutOption>());
		}
		else
		{
			foreach (DropInfo drop in selectedMonster.Drops)
			{
				if (drop != null)
				{
					string arg2 = ((drop.Chance >= 75) ? "#92F071" : ((drop.Chance >= 30) ? "#F0DC71" : "#F0904B"));
					GUILayout.BeginHorizontal(rowStyle, Array.Empty<GUILayoutOption>());
					Rect rect3 = GUILayoutUtility.GetRect(28f, 28f, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(28f),
						GUILayout.Height(28f)
					});
					if ((Object)(object)drop.ItemSprite != (Object)null)
					{
						DrawSprite(rect3, drop.ItemSprite);
					}
					else
					{
						GUI.Label(rect3, "•", statLabelStyle);
					}
					GUILayout.Space(10f);
					string text5 = (string.IsNullOrEmpty(drop.ItemName) ? "Przedmiot" : drop.ItemName);
					string text6 = (string.IsNullOrEmpty(drop.Amount) ? "1" : drop.Amount);
					GUILayout.Label("<color=#FFFFFF>" + text5 + "</color>", tableRowStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
					GUILayout.Label("<color=#E0D3C1>" + text6 + " szt.</color>", tableRowStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
					GUILayout.Label($"<color={arg2}><b>{drop.Chance}%</b></color>", tableRowStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) });
					GUILayout.EndHorizontal();
				}
			}
		}
		GUILayout.EndScrollView();
		GUILayout.FlexibleSpace();
		GUILayout.BeginHorizontal(statBadgeStyle, Array.Empty<GUILayoutOption>());
		string text7 = (string.IsNullOrEmpty(selectedMonster.Behavior) ? "Neutralny" : selectedMonster.Behavior);
		GUILayout.Label("<color=#8C7B68>Status bojowy:</color> <color=#E0D3C1>" + text7 + "</color>", statLabelStyle, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		if (GUILayout.Button("◄ Wróć do spisu ([ESC])", cardStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(44f) }))
		{
			SelectMonster(null);
		}
		GUILayout.EndVertical();
	}

	public static void SaveProgress()
	{
		try
		{
			List<string> contents = AllMonsters.Values.Where((MonsterEntry m) => m.Discovered).Select(delegate(MonsterEntry m)
			{
				KillCounts.TryGetValue(m.PrefabName, out var value);
				return $"{m.PrefabName}:{value}";
			}).ToList();
			File.WriteAllLines(SaveFilePath, contents);
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[Valheim Bestiary] Błąd zapisu: " + ex.Message));
		}
	}

	public static void LoadProgress()
	{
		try
		{
			if (!File.Exists(SaveFilePath))
			{
				return;
			}
			string[] array = File.ReadAllLines(SaveFilePath);
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					string[] array3 = text.Split(':');
					string key = array3[0].Trim();
					int value = 1;
					if (array3.Length > 1 && int.TryParse(array3[1], out var result))
					{
						value = result;
					}
					KillCounts[key] = value;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[Valheim Bestiary] Błąd odczytu: " + ex.Message));
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "IsVisible")]
public static class InventoryGuiVisiblePatch
{
	public static void Postfix(ref bool __result)
	{
		if (BestiaryPlugin.ShowUI)
		{
			__result = true;
		}
	}
}
[HarmonyPatch(typeof(Player), "TakeInput")]
public static class PlayerTakeInputPatch
{
	public static bool Prefix(ref bool __result)
	{
		if (BestiaryPlugin.ShowUI)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
public static class ZNetScenePatch
{
	public static void Postfix(ZNetScene __instance)
	{
		if ((Object)(object)__instance == (Object)null || __instance.m_prefabs == null)
		{
			return;
		}
		BestiaryPlugin.AllMonsters.Clear();
		foreach (GameObject prefab in __instance.m_prefabs)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				continue;
			}
			Character component = prefab.GetComponent<Character>();
			if ((Object)(object)component == (Object)null || component.IsPlayer())
			{
				continue;
			}
			CharacterDrop component2 = prefab.GetComponent<CharacterDrop>();
			if ((Object)(object)component2 == (Object)null)
			{
				continue;
			}
			string text = component.m_name;
			if (Localization.instance != null)
			{
				text = Localization.instance.Localize(text);
			}
			if (string.IsNullOrEmpty(text))
			{
				text = ((Object)prefab).name;
			}
			if (BestiaryPlugin.AllMonsters.ContainsKey(((Object)prefab).name))
			{
				continue;
			}
			bool discovered = BestiaryPlugin.KillCounts.ContainsKey(((Object)prefab).name);
			MonsterAI component3 = prefab.GetComponent<MonsterAI>();
			string behavior = "Agresywny stwór";
			if ((Object)(object)component3 != (Object)null && ((BaseAI)component3).m_avoidFire)
			{
				behavior = "Boi się ognia";
			}
			if (((Object)prefab).name.Equals("Deer", StringComparison.OrdinalIgnoreCase))
			{
				behavior = "Płochliwa zwierzyna";
			}
			MonsterEntry monsterEntry = new MonsterEntry
			{
				PrefabName = ((Object)prefab).name,
				CleanName = text,
				Biome = FormatBiomeCategory(component, ((Object)prefab).name),
				Health = component.m_health,
				Behavior = behavior,
				Discovered = discovered
			};
			Humanoid val = (Humanoid)(object)((component is Humanoid) ? component : null);
			if ((Object)(object)val != (Object)null && val.m_defaultItems != null && val.m_defaultItems.Length != 0)
			{
				GameObject[] defaultItems = val.m_defaultItems;
				foreach (GameObject val2 in defaultItems)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						ItemDrop component4 = val2.GetComponent<ItemDrop>();
						if ((Object)(object)component4 != (Object)null)
						{
							monsterEntry.Damage = Mathf.Max(monsterEntry.Damage, ((DamageTypes)(ref component4.m_itemData.m_shared.m_damages)).GetTotalDamage());
						}
					}
				}
			}
			if (monsterEntry.Damage <= 0f)
			{
				monsterEntry.Damage = 10f;
			}
			ParseDamageModifiers(component, monsterEntry);
			Tameable component5 = prefab.GetComponent<Tameable>();
			if ((Object)(object)component5 != (Object)null)
			{
				monsterEntry.IsTameable = true;
				MonsterAI component6 = prefab.GetComponent<MonsterAI>();
				if ((Object)(object)component6 != (Object)null && component6.m_consumeItems != null && component6.m_consumeItems.Count > 0)
				{
					foreach (ItemDrop consumeItem in component6.m_consumeItems)
					{
						if (!((Object)(object)consumeItem == (Object)null))
						{
							string fName = ((Localization.instance != null) ? Localization.instance.Localize(consumeItem.m_itemData.m_shared.m_name) : ((Object)consumeItem).name);
							Sprite icon = null;
							if (consumeItem.m_itemData.m_shared.m_icons != null && consumeItem.m_itemData.m_shared.m_icons.Length != 0)
							{
								icon = consumeItem.m_itemData.m_shared.m_icons[0];
							}
							if (!monsterEntry.TameFoods.Any((TameFoodInfo x) => x.Name == fName))
							{
								monsterEntry.TameFoods.Add(new TameFoodInfo
								{
									Name = fName,
									Icon = icon
								});
							}
						}
					}
				}
			}
			if (component2.m_drops != null)
			{
				foreach (Drop drop in component2.m_drops)
				{
					if ((Object)(object)drop.m_prefab == (Object)null)
					{
						continue;
					}
					string itemName = ((Object)drop.m_prefab).name;
					Sprite itemSprite = null;
					ItemDrop component7 = drop.m_prefab.GetComponent<ItemDrop>();
					if ((Object)(object)component7 != (Object)null)
					{
						if (Localization.instance != null)
						{
							itemName = Localization.instance.Localize(component7.m_itemData.m_shared.m_name);
						}
						if (component7.m_itemData.m_shared.m_icons != null && component7.m_itemData.m_shared.m_icons.Length != 0)
						{
							itemSprite = component7.m_itemData.m_shared.m_icons[0];
						}
						if (((Object)drop.m_prefab).name.StartsWith("Trophy", StringComparison.OrdinalIgnoreCase) && Localization.instance != null)
						{
							string description = component7.m_itemData.m_shared.m_description;
							string text2 = Localization.instance.Localize(description);
							if (!string.IsNullOrEmpty(text2) && text2 != description)
							{
								monsterEntry.Description = text2;
							}
						}
					}
					int chance = Mathf.RoundToInt(drop.m_chance * 100f);
					string amount = ((drop.m_amountMin == drop.m_amountMax) ? $"{drop.m_amountMin}" : $"{drop.m_amountMin}–{drop.m_amountMax}");
					monsterEntry.Drops.Add(new DropInfo
					{
						ItemName = itemName,
						Amount = amount,
						Chance = chance,
						ItemSprite = itemSprite
					});
				}
			}
			if (monsterEntry.Description == "Brak dostępnych zapisków o tym stworzeniu.")
			{
				monsterEntry.Description = "Groźna istota należąca do ugrupowania " + monsterEntry.Biome + ".";
			}
			BestiaryPlugin.AllMonsters[((Object)prefab).name] = monsterEntry;
		}
	}

	private static string FormatBiomeCategory(Character character, string prefabName)
	{
		if (prefabName.Equals("Boar", StringComparison.OrdinalIgnoreCase) || prefabName.Equals("Deer", StringComparison.OrdinalIgnoreCase))
		{
			return "Zwierzyna leśna (Łąki)";
		}
		switch (((object)Unsafe.As<Faction, Faction>(ref character.m_faction)/*cast due to .constrained prefix*/).ToString())
		{
		case "ForestMonsters":
			return "Leśne istoty (Czarny Las)";
		case "Undead":
			return "Nieumarli (Bagna / Krypty)";
		case "Demon":
			return "Pomioty / Demony (Popieliska)";
		case "MountainMonsters":
			return "Górskie bestie (Góry)";
		case "PlainsMonsters":
			return "Mieszkańcy Równin";
		case "MistlandsMonsters":
			return "Mgliska";
		case "SeaMonsters":
			return "Morskie bestie (Ocean)";
		case "Animals":
		case "AnimalsVegetables":
			return "Fauna i flora";
		case "Boss":
			return "Starożytny Władca (Boss)";
		default:
			return "Dzika kraina";
		}
	}

	private static void ParseDamageModifiers(Character character, MonsterEntry entry)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_0094: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			DamageModifiers damageModifiers = character.m_damageModifiers;
			List<string> weaks = new List<string>();
			List<string> res = new List<string>();
			Check(damageModifiers.m_blunt, "Obuch");
			Check(damageModifiers.m_slash, "Cięcie");
			Check(damageModifiers.m_pierce, "Kłucie");
			Check(damageModifiers.m_fire, "Ogień");
			Check(damageModifiers.m_frost, "Mróz");
			Check(damageModifiers.m_lightning, "Błyskawice");
			Check(damageModifiers.m_poison, "Trucizna");
			Check(damageModifiers.m_spirit, "Duch");
			if (weaks.Count > 0)
			{
				entry.Weaknesses = string.Join(", ", weaks);
			}
			if (res.Count > 0)
			{
				entry.Resistances = string.Join(", ", res);
			}
			void Check(DamageModifier mod, string name)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0003: Invalid comparison between Unknown and I4
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Invalid comparison between Unknown and I4
				//IL_0025: 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_002b: Invalid comparison between Unknown and I4
				if ((int)mod == 2 || (int)mod == 6)
				{
					weaks.Add(name);
				}
				else if ((int)mod == 1 || (int)mod == 5 || (int)mod == 3)
				{
					res.Add(name);
				}
			}
		}
		catch
		{
		}
	}
}
[HarmonyPatch(typeof(Character), "OnDeath")]
public static class UnlockOnDeathPatch
{
	public static void Postfix(Character __instance)
	{
		if ((Object)(object)__instance == (Object)null || __instance.IsPlayer())
		{
			return;
		}
		string key = ((Object)__instance).name.Replace("(Clone)", "").Trim();
		MonsterEntry value = null;
		if (!BestiaryPlugin.AllMonsters.TryGetValue(key, out value))
		{
			value = BestiaryPlugin.AllMonsters.Values.FirstOrDefault((MonsterEntry m) => m.CleanName == __instance.m_name);
		}
		if (value != null)
		{
			bool flag = !value.Discovered;
			value.Discovered = true;
			BestiaryPlugin.KillCounts.TryGetValue(value.PrefabName, out var value2);
			BestiaryPlugin.KillCounts[value.PrefabName] = value2 + 1;
			BestiaryPlugin.SaveProgress();
			if (flag && (Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)2, "<color=#FFB444>Nowy wpis w Bestiariuszu:</color>\n<color=#FFFFFF><b>" + value.CleanName + "</b></color>", 0, (Sprite)null, false, true);
			}
		}
	}
}