Decompiled source of BangBang WildHunt v1.0.0

BangBang.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace BangBangMod;

[BepInPlugin("com.coarstal.bangbang.wildhunt", "BangBang - Дикая охота", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BangBangPlugin : BaseUnityPlugin
{
	public const string PluginGUID = "com.coarstal.bangbang.wildhunt";

	public const string PluginName = "BangBang - Дикая охота";

	public const string PluginVersion = "1.0.0";

	internal static ManualLogSource ModLogger;

	public static ConfigEntry<float> NightRaidChance;

	public static ConfigEntry<bool> RequireEikthyrDefeated;

	public static ConfigEntry<float> BaseBossHealth;

	public static ConfigEntry<float> BaseKatanaSlashDamage;

	public static ConfigEntry<float> BaseRevolverDamage;

	public static ConfigEntry<float> ProgressionMultiplierScale;

	public static ConfigEntry<float> BossMusicVolume;

	public static ConfigEntry<string> CustomMusicFileName;

	public static ConfigEntry<bool> EnableCustomMenuCover;

	private Harmony m_harmony;

	private void Awake()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		ModLogger = ((BaseUnityPlugin)this).Logger;
		BindConfigs();
		RegisterLocalizations();
		WildHuntAssets.EnsureCoverSpriteLoaded();
		WildHuntAssets.StartLoadingBossMusic((MonoBehaviour)(object)this);
		PrefabManager.OnVanillaPrefabsAvailable += WildHuntBossModule.RegisterBossAndWeapons;
		try
		{
			m_harmony = new Harmony("com.coarstal.bangbang.wildhunt");
			Type[] types = typeof(BangBangPlugin).Assembly.GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				object[] customAttributes = types[i].GetCustomAttributes(typeof(HarmonyPatch), inherit: false);
				if (customAttributes != null && customAttributes.Length > 0)
				{
					try
					{
						m_harmony.CreateClassProcessor(types[i]).Patch();
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)("[BangBang] Harmony patch failed on " + types[i].Name + ": " + ex.Message));
					}
				}
			}
		}
		catch (Exception ex2)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[BangBang] Harmony initialization error: " + ex2));
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"BangBang - Дикая охота v1.0.0 loaded! Готовься к ночной 'Дикой охоте'!");
	}

	private void OnDestroy()
	{
		PrefabManager.OnVanillaPrefabsAvailable -= WildHuntBossModule.RegisterBossAndWeapons;
		if (m_harmony != null)
		{
			m_harmony.UnpatchSelf();
		}
	}

	private void BindConfigs()
	{
		NightRaidChance = ((BaseUnityPlugin)this).Config.Bind<float>("1. Событие Дикая охота (Wild Hunt Raid)", "NightRaidChance", 0.6f, "Шанс начала набега 'Дикая охота' каждую ночь (0.60 = 60% каждую ночь).");
		RequireEikthyrDefeated = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Событие Дикая охота (Wild Hunt Raid)", "RequireEikthyrDefeated", true, "Если true — Олень начинает мстить по ночам после убийства первого босса Эйктюра (defeated_eikthyr).");
		BaseBossHealth = ((BaseUnityPlugin)this).Config.Bind<float>("2. Характеристики Босса и Масштабирование", "BaseBossHealth", 900f, "Базовое здоровье босса на 1-м тире (после Эйктюра). Автоматически растёт с каждым убитым боссом вплоть до 13000+ HP!");
		BaseKatanaSlashDamage = ((BaseUnityPlugin)this).Config.Bind<float>("2. Характеристики Босса и Масштабирование", "BaseKatanaSlashDamage", 36f, "Базовый рубящий урон катаны на 1-м тире (автоматически растёт после убийства Древнего, Массы Костей, Моудер, Яглута, Королевы, Фадера).");
		BaseRevolverDamage = ((BaseUnityPlugin)this).Config.Bind<float>("2. Характеристики Босса и Масштабирование", "BaseRevolverDamage", 42f, "Базовый урон пули револьвера на 1-м тире (растёт с прогрессом убитых боссов).");
		ProgressionMultiplierScale = ((BaseUnityPlugin)this).Config.Bind<float>("2. Характеристики Босса и Масштабирование", "ProgressionMultiplierScale", 1f, "Глобальный множитель сложности прогрессии босса (1.0 = стандартный баланс по биомам).");
		BossMusicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("3. Музыка Dark Souls и Обложка Меню", "BossMusicVolume", 0.8f, "Громкость босс-файт музыки Dark Souls III (Vordt of the Boreal Valley) от 0.0 до 1.5.");
		CustomMusicFileName = ((BaseUnityPlugin)this).Config.Bind<string>("3. Музыка Dark Souls и Обложка Меню", "CustomMusicFileName", "", "Необязательно: имя своего аудиофайла (.mp3 / .ogg / .wav) в папке Music рядом с BangBang.dll (по умолчанию играет встроенный VordtBossTheme.mp3).");
		EnableCustomMenuCover = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Музыка Dark Souls и Обложка Меню", "EnableCustomMenuCover", true, "Заменять обложку главного меню, загрузочный экран и подзаголовок 'Deep North' на фотографию Оленя и надпись 'ДИКАЯ ОХОТА'.");
	}

	private void RegisterLocalizations()
	{
		CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
		string text = "Russian";
		localization.AddTranslation(ref text, new Dictionary<string, string>
		{
			{ "enemy_wildhunt_deerboss", "Олень в пальто с Револьвером и Катаной!" },
			{ "msg_wildhunt_start", "Дикая охота" },
			{ "msg_wildhunt_end", "Дикая охота уходит в рассветный туман..." },
			{ "msg_wildhunt_victory", "Олень в пальто повержен... до следующей ночи!" }
		});
		string text2 = "English";
		localization.AddTranslation(ref text2, new Dictionary<string, string>
		{
			{ "enemy_wildhunt_deerboss", "Олень в пальто с Револьвером и Катаной!" },
			{ "msg_wildhunt_start", "Дикая охота" },
			{ "msg_wildhunt_end", "Дикая охота уходит в рассветный туман..." },
			{ "msg_wildhunt_victory", "Олень в пальто повержен... до следующей ночи!" }
		});
	}
}
public static class MainMenuAndLoadingPatches
{
	private static readonly FieldInfo s_fsMainMenuField = AccessTools.Field(typeof(FejdStartup), "m_mainMenu");

	private static readonly FieldInfo s_fsCharSelectField = AccessTools.Field(typeof(FejdStartup), "m_characterSelectScreen");

	private static readonly FieldInfo s_fsCreditsField = AccessTools.Field(typeof(FejdStartup), "m_creditsPanel");

	private static readonly FieldInfo s_hudLoadingImgField = AccessTools.Field(typeof(Hud), "m_loadingImage");

	private static readonly FieldInfo s_hudLoadingScreenField = AccessTools.Field(typeof(Hud), "m_loadingScreen");

	internal static void ApplyToFejdStartup(FejdStartup fs)
	{
		if ((Object)(object)fs == (Object)null || !BangBangPlugin.EnableCustomMenuCover.Value)
		{
			return;
		}
		WildHuntAssets.EnsureCoverSpriteLoaded();
		if ((Object)(object)WildHuntAssets.CoverSprite == (Object)null)
		{
			return;
		}
		GameObject val = (GameObject)((s_fsMainMenuField != null) ? /*isinst with value type is only supported in some contexts*/: null);
		if (!((Object)(object)val == (Object)null))
		{
			WildHuntMenuController wildHuntMenuController = ((Component)fs).gameObject.GetComponent<WildHuntMenuController>();
			if ((Object)(object)wildHuntMenuController == (Object)null)
			{
				wildHuntMenuController = ((Component)fs).gameObject.AddComponent<WildHuntMenuController>();
			}
			wildHuntMenuController.Initialize(fs, val);
		}
	}

	internal static void ApplyToHudLoadingScreen(Hud hud)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)hud == (Object)null || !BangBangPlugin.EnableCustomMenuCover.Value)
		{
			return;
		}
		WildHuntAssets.EnsureCoverSpriteLoaded();
		if ((Object)(object)WildHuntAssets.CoverSprite == (Object)null)
		{
			return;
		}
		try
		{
			Image val = (Image)((s_hudLoadingImgField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val != (Object)null)
			{
				val.sprite = WildHuntAssets.CoverSprite;
				((Graphic)val).color = Color.white;
				val.preserveAspect = false;
			}
			CanvasGroup val2 = (CanvasGroup)((s_hudLoadingScreenField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return;
			}
			Image[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Image>(true);
			foreach (Image val3 in componentsInChildren)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					string text = ((Object)((Component)val3).gameObject).name.ToLowerInvariant();
					if (text.Contains("bkg") || text.Contains("background") || text.Contains("loadingimage"))
					{
						val3.sprite = WildHuntAssets.CoverSprite;
						((Graphic)val3).color = Color.white;
						val3.preserveAspect = false;
					}
				}
			}
		}
		catch (Exception ex)
		{
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogWarning((object)("[WildHuntMenu] Loading screen patch warning: " + ex.Message));
			}
		}
	}

	public static bool IsCharacterOrCreditsScreenOpen(FejdStartup fs)
	{
		if ((Object)(object)fs == (Object)null)
		{
			return false;
		}
		GameObject val = (GameObject)((s_fsCharSelectField != null) ? /*isinst with value type is only supported in some contexts*/: null);
		if ((Object)(object)val != (Object)null && val.activeInHierarchy)
		{
			return true;
		}
		GameObject val2 = (GameObject)((s_fsCreditsField != null) ? /*isinst with value type is only supported in some contexts*/: null);
		if ((Object)(object)val2 != (Object)null && val2.activeInHierarchy)
		{
			return true;
		}
		return false;
	}
}
public class WildHuntMenuController : MonoBehaviour
{
	private FejdStartup m_fs;

	private GameObject m_mainMenuRoot;

	private GameObject m_coverRoot;

	private GameObject m_subtitleObj;

	private bool m_subtitleReplaced;

	public void Initialize(FejdStartup fs, GameObject mainMenuGo)
	{
		m_fs = fs;
		m_mainMenuRoot = mainMenuGo;
		BuildFullScreenCoverBackground(mainMenuGo);
		ReplaceExpansionTitleWithWildHunt(mainMenuGo);
	}

	private void BuildFullScreenCoverBackground(GameObject mainMenuGo)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_00b3: 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_00d0: Expected O, but got Unknown
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: 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_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)m_coverRoot != (Object)null) && !((Object)(object)WildHuntAssets.CoverSprite == (Object)null))
		{
			Canvas componentInParent = mainMenuGo.GetComponentInParent<Canvas>();
			Transform val = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).transform : mainMenuGo.transform);
			m_coverRoot = new GameObject("WildHunt_FullScreenCover");
			RectTransform val2 = m_coverRoot.AddComponent<RectTransform>();
			((Transform)val2).SetParent(val, false);
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			((Transform)val2).SetSiblingIndex(0);
			Image val3 = m_coverRoot.AddComponent<Image>();
			((Graphic)val3).color = new Color(0.04f, 0.04f, 0.06f, 1f);
			((Graphic)val3).raycastTarget = false;
			GameObject val4 = new GameObject("WildHunt_Photo");
			RectTransform val5 = val4.AddComponent<RectTransform>();
			((Transform)val5).SetParent((Transform)(object)val2, false);
			val5.anchorMin = Vector2.zero;
			val5.anchorMax = Vector2.one;
			val5.offsetMin = Vector2.zero;
			val5.offsetMax = Vector2.zero;
			Image val6 = val4.AddComponent<Image>();
			val6.sprite = WildHuntAssets.CoverSprite;
			((Graphic)val6).color = Color.white;
			((Graphic)val6).raycastTarget = false;
			AspectRatioFitter val7 = val4.AddComponent<AspectRatioFitter>();
			val7.aspectMode = (AspectMode)4;
			if ((Object)(object)WildHuntAssets.CoverTexture != (Object)null && ((Texture)WildHuntAssets.CoverTexture).height > 0)
			{
				val7.aspectRatio = (float)((Texture)WildHuntAssets.CoverTexture).width / (float)((Texture)WildHuntAssets.CoverTexture).height;
			}
			else
			{
				val7.aspectRatio = 1.5f;
			}
			GameObject val8 = new GameObject("WildHunt_MenuReadabilityShade");
			RectTransform val9 = val8.AddComponent<RectTransform>();
			((Transform)val9).SetParent((Transform)(object)val2, false);
			val9.anchorMin = Vector2.zero;
			val9.anchorMax = new Vector2(0.38f, 1f);
			val9.offsetMin = Vector2.zero;
			val9.offsetMax = Vector2.zero;
			Image val10 = val8.AddComponent<Image>();
			val10.sprite = BuildHorizontalGradientSprite();
			((Graphic)val10).color = new Color(0f, 0f, 0f, 0.58f);
			((Graphic)val10).raycastTarget = false;
		}
	}

	private static Sprite BuildHorizontalGradientSprite()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		int num = 64;
		int num2 = 4;
		Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		Color[] array = (Color[])(object)new Color[num * num2];
		for (int i = 0; i < num; i++)
		{
			float num3 = (float)i / (float)(num - 1);
			float num4 = Mathf.Pow(1f - num3, 1.6f);
			for (int j = 0; j < num2; j++)
			{
				ref Color reference = ref array[j * num + i];
				reference = new Color(1f, 1f, 1f, num4);
			}
		}
		val.SetPixels(array);
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num2), new Vector2(0.5f, 0.5f));
	}

	private void ReplaceExpansionTitleWithWildHunt(GameObject mainMenuGo)
	{
		//IL_0518: Unknown result type (might be due to invalid IL or missing references)
		//IL_0522: Expected O, but got Unknown
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_059d: 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_05c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fe: Expected O, but got Unknown
		//IL_0613: Unknown result type (might be due to invalid IL or missing references)
		//IL_061f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0635: Unknown result type (might be due to invalid IL or missing references)
		//IL_064b: Unknown result type (might be due to invalid IL or missing references)
		//IL_055b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0569: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: 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_06bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_06de: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e5: Expected O, but got Unknown
		//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0706: Unknown result type (might be due to invalid IL or missing references)
		//IL_0712: Unknown result type (might be due to invalid IL or missing references)
		//IL_071e: Unknown result type (might be due to invalid IL or missing references)
		//IL_079a: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0435: Unknown result type (might be due to invalid IL or missing references)
		if (m_subtitleReplaced)
		{
			return;
		}
		Canvas componentInParent = mainMenuGo.GetComponentInParent<Canvas>();
		Transform val = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).transform : mainMenuGo.transform);
		Transform val2 = null;
		Transform val3 = null;
		TMP_FontAsset val4 = null;
		TMP_Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<TMP_Text>(true);
		foreach (TMP_Text val5 in componentsInChildren)
		{
			if (!((Object)(object)val5 == (Object)null))
			{
				if ((Object)(object)val4 == (Object)null && (Object)(object)val5.font != (Object)null)
				{
					val4 = val5.font;
				}
				string text = (val5.text ?? "").ToLowerInvariant();
				string text2 = ((Object)((Component)val5).gameObject).name.ToLowerInvariant();
				if (text.Contains("deep north") || text.Contains("ashlands") || text.Contains("mistlands") || text.Contains("hearth") || text.Contains("дальний север") || text.Contains("пепельные") || text2.Contains("deepnorth") || text2.Contains("ashlands") || text2.Contains("sublogo") || text2.Contains("expansion"))
				{
					val5.text = "ДИКАЯ ОХОТА";
					val3 = val5.transform;
				}
			}
		}
		Transform[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Transform>(true);
		foreach (Transform val6 in componentsInChildren2)
		{
			if ((Object)(object)val6 == (Object)null)
			{
				continue;
			}
			switch (((Object)val6).name.ToLowerInvariant())
			{
			case "logo":
			case "valheimlogo":
			case "mainlogo":
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = val6;
				}
				break;
			}
		}
		Image[] componentsInChildren3 = ((Component)val).GetComponentsInChildren<Image>(true);
		foreach (Image val7 in componentsInChildren3)
		{
			if ((Object)(object)val7 == (Object)null || (Object)(object)((Component)val7).gameObject == (Object)(object)m_coverRoot || ((Object)(object)m_coverRoot != (Object)null && ((Component)val7).transform.IsChildOf(m_coverRoot.transform)))
			{
				continue;
			}
			string text3 = ((Object)((Component)val7).gameObject).name.ToLowerInvariant();
			string text4 = (((Object)(object)val7.sprite != (Object)null) ? ((Object)val7.sprite).name : "").ToLowerInvariant();
			if ((text3 == "logo" || text4 == "valheim_logo" || text4 == "logo") && !text3.Contains("deep") && !text3.Contains("north") && !text3.Contains("ash") && !text3.Contains("mist") && !text3.Contains("sub") && (Object)(object)val2 == (Object)null)
			{
				val2 = ((Component)val7).transform;
			}
			bool flag = text3.Contains("deepnorth") || text3.Contains("deep_north") || text3.Contains("north") || text3.Contains("ashland") || text3.Contains("mistland") || text3.Contains("hearth") || text3.Contains("sublogo") || text3.Contains("update_logo") || text3.Contains("expansion") || text4.Contains("deepnorth") || text4.Contains("deep_north") || text4.Contains("ashland") || text4.Contains("mistland") || text4.Contains("sublogo");
			if (!flag && (Object)(object)val2 != (Object)null && (Object)(object)((Component)val7).transform != (Object)(object)val2 && ((Component)val7).transform.IsChildOf(val2))
			{
				RectTransform rectTransform = ((Graphic)val7).rectTransform;
				if ((Object)(object)rectTransform != (Object)null && (text3.Contains("logo") || text3.Contains("text") || text3.Contains("title") || rectTransform.anchoredPosition.y < -10f) && !text3.Contains("glow") && !text3.Contains("spark") && !text3.Contains("smoke"))
				{
					flag = true;
				}
			}
			if (flag)
			{
				val3 = ((Component)val7).transform;
				((Behaviour)val7).enabled = false;
			}
		}
		Transform val8 = null;
		Vector2 anchoredPosition = default(Vector2);
		((Vector2)(ref anchoredPosition))..ctor(0f, -72f);
		if ((Object)(object)val3 != (Object)null)
		{
			val8 = val3.parent;
			RectTransform val9 = (RectTransform)(object)((val3 is RectTransform) ? val3 : null);
			if ((Object)(object)val9 != (Object)null)
			{
				anchoredPosition = val9.anchoredPosition;
			}
		}
		else if ((Object)(object)val2 != (Object)null)
		{
			val8 = val2;
			((Vector2)(ref anchoredPosition))..ctor(0f, -78f);
		}
		else
		{
			val8 = mainMenuGo.transform;
			((Vector2)(ref anchoredPosition))..ctor(0f, 230f);
		}
		m_subtitleObj = new GameObject("WildHunt_TitleBanner");
		RectTransform val10 = m_subtitleObj.AddComponent<RectTransform>();
		((Transform)val10).SetParent(val8, false);
		if ((Object)(object)val3 != (Object)null)
		{
			RectTransform val11 = (RectTransform)(object)((val3 is RectTransform) ? val3 : null);
			if ((Object)(object)val11 != (Object)null)
			{
				val10.anchorMin = val11.anchorMin;
				val10.anchorMax = val11.anchorMax;
				val10.pivot = val11.pivot;
				val10.anchoredPosition = val11.anchoredPosition;
			}
		}
		else
		{
			val10.anchorMin = new Vector2(0.5f, 0.5f);
			val10.anchorMax = new Vector2(0.5f, 0.5f);
			val10.pivot = new Vector2(0.5f, 0.5f);
			val10.anchoredPosition = anchoredPosition;
		}
		val10.sizeDelta = new Vector2(720f, 84f);
		GameObject val12 = new GameObject("WildHunt_TitleShadow");
		RectTransform val13 = val12.AddComponent<RectTransform>();
		((Transform)val13).SetParent((Transform)(object)val10, false);
		val13.anchorMin = Vector2.zero;
		val13.anchorMax = Vector2.one;
		val13.offsetMin = new Vector2(3f, -3f);
		val13.offsetMax = new Vector2(3f, -3f);
		TextMeshProUGUI val14 = val12.AddComponent<TextMeshProUGUI>();
		if ((Object)(object)val4 != (Object)null)
		{
			((TMP_Text)val14).font = val4;
		}
		((TMP_Text)val14).text = "ДИКАЯ ОХОТА";
		((TMP_Text)val14).fontSize = 42f;
		((TMP_Text)val14).fontStyle = (FontStyles)1;
		((TMP_Text)val14).characterSpacing = 10f;
		((TMP_Text)val14).alignment = (TextAlignmentOptions)514;
		((Graphic)val14).color = new Color(0.03f, 0.01f, 0.01f, 0.92f);
		((TMP_Text)val14).textWrappingMode = (TextWrappingModes)0;
		((Graphic)val14).raycastTarget = false;
		GameObject val15 = new GameObject("WildHunt_TitleText");
		RectTransform val16 = val15.AddComponent<RectTransform>();
		((Transform)val16).SetParent((Transform)(object)val10, false);
		val16.anchorMin = Vector2.zero;
		val16.anchorMax = Vector2.one;
		val16.offsetMin = Vector2.zero;
		val16.offsetMax = Vector2.zero;
		TextMeshProUGUI val17 = val15.AddComponent<TextMeshProUGUI>();
		if ((Object)(object)val4 != (Object)null)
		{
			((TMP_Text)val17).font = val4;
		}
		((TMP_Text)val17).text = "ДИКАЯ ОХОТА";
		((TMP_Text)val17).fontSize = 42f;
		((TMP_Text)val17).fontStyle = (FontStyles)1;
		((TMP_Text)val17).characterSpacing = 10f;
		((TMP_Text)val17).alignment = (TextAlignmentOptions)514;
		((TMP_Text)val17).enableVertexGradient = true;
		((TMP_Text)val17).colorGradient = new VertexGradient(new Color(1f, 0.9f, 0.55f, 1f), new Color(1f, 0.9f, 0.55f, 1f), new Color(0.92f, 0.32f, 0.14f, 1f), new Color(0.92f, 0.32f, 0.14f, 1f));
		((TMP_Text)val17).textWrappingMode = (TextWrappingModes)0;
		((Graphic)val17).raycastTarget = false;
		m_subtitleReplaced = true;
		if (BangBangPlugin.ModLogger != null)
		{
			BangBangPlugin.ModLogger.LogInfo((object)"[WildHuntMenu] Applied custom 'ДИКАЯ ОХОТА' cover & title on Main Menu!");
		}
	}

	private void LateUpdate()
	{
		if (!((Object)(object)m_coverRoot == (Object)null) && !((Object)(object)m_fs == (Object)null))
		{
			bool flag = MainMenuAndLoadingPatches.IsCharacterOrCreditsScreenOpen(m_fs);
			if (m_coverRoot.activeSelf == flag)
			{
				m_coverRoot.SetActive(!flag);
			}
			if (m_coverRoot.transform.GetSiblingIndex() != 0)
			{
				m_coverRoot.transform.SetSiblingIndex(0);
			}
		}
	}
}
[HarmonyPatch(typeof(FejdStartup), "Start")]
public static class FejdStartup_Start_WildHuntCover_Patch
{
	private static void Postfix(FejdStartup __instance)
	{
		MainMenuAndLoadingPatches.ApplyToFejdStartup(__instance);
		WildHuntAssets.StartLoadingBossMusic((MonoBehaviour)(object)__instance);
	}
}
[HarmonyPatch(typeof(FejdStartup), "SetupGui")]
public static class FejdStartup_SetupGui_WildHuntCover_Patch
{
	private static void Postfix(FejdStartup __instance)
	{
		MainMenuAndLoadingPatches.ApplyToFejdStartup(__instance);
	}
}
[HarmonyPatch(typeof(Hud), "Awake")]
public static class Hud_Awake_WildHuntLoadingCover_Patch
{
	private static void Postfix(Hud __instance)
	{
		MainMenuAndLoadingPatches.ApplyToHudLoadingScreen(__instance);
	}
}
[HarmonyPatch(typeof(SceneLoader), "Start")]
public static class SceneLoader_Start_WildHuntIntroCover_Patch
{
	private static void Postfix(SceneLoader __instance)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)__instance == (Object)null || !BangBangPlugin.EnableCustomMenuCover.Value)
		{
			return;
		}
		WildHuntAssets.EnsureCoverSpriteLoaded();
		if ((Object)(object)WildHuntAssets.CoverSprite == (Object)null)
		{
			return;
		}
		try
		{
			Canvas componentInChildren = ((Component)__instance).GetComponentInChildren<Canvas>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				GameObject val = new GameObject("WildHunt_BootSplashBg");
				RectTransform val2 = val.AddComponent<RectTransform>();
				((Transform)val2).SetParent(((Component)componentInChildren).transform, false);
				val2.anchorMin = Vector2.zero;
				val2.anchorMax = Vector2.one;
				val2.offsetMin = Vector2.zero;
				val2.offsetMax = Vector2.zero;
				((Transform)val2).SetSiblingIndex(0);
				Image val3 = val.AddComponent<Image>();
				val3.sprite = WildHuntAssets.CoverSprite;
				((Graphic)val3).color = new Color(1f, 1f, 1f, 0.55f);
				val3.preserveAspect = false;
				((Graphic)val3).raycastTarget = false;
			}
		}
		catch
		{
		}
	}
}
public static class WildHuntAssets
{
	public static Mesh DeerHeadMesh;

	public static Mesh TrenchTorsoMesh;

	public static Mesh TrenchSkirtMesh;

	public static Mesh TrenchSleeveMesh;

	public static Mesh BlackGloveMesh;

	public static Mesh DarkBootMesh;

	public static Mesh ChromeRevolverMesh;

	public static Mesh SamuraiKatanaMesh;

	public static Material BossPbrMaterial;

	public static Material AdditiveBulletFxMaterial;

	public static Texture2D CoverTexture;

	public static Sprite CoverSprite;

	public static AudioClip RevolverBangClip;

	public static AudioClip KatanaSlashClip;

	public static AudioClip VordtBossMusicClip;

	private static bool s_meshesLoaded;

	private static bool s_musicLoadingStarted;

	public static void EnsureCoverSpriteLoaded()
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)CoverSprite != (Object)null)
		{
			return;
		}
		try
		{
			byte[] array = null;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (!string.IsNullOrEmpty(directoryName))
			{
				string path = Path.Combine(directoryName, "WildHuntCover.png");
				string path2 = Path.Combine(directoryName, "WildHuntCover.jpg");
				if (File.Exists(path))
				{
					array = File.ReadAllBytes(path);
				}
				else if (File.Exists(path2))
				{
					array = File.ReadAllBytes(path2);
				}
			}
			if (array == null)
			{
				array = ReadEmbeddedBytes("WildHuntCover.jpg");
			}
			if (array != null && array.Length > 0)
			{
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false, false);
				if (ImageConversion.LoadImage(val, array))
				{
					((Object)val).name = "WildHuntCoverTex";
					((Texture)val).filterMode = (FilterMode)1;
					((Texture)val).wrapMode = (TextureWrapMode)1;
					CoverTexture = val;
					CoverSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
					((Object)CoverSprite).name = "WildHuntCoverSprite";
				}
			}
		}
		catch (Exception ex)
		{
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogError((object)("[WildHuntAssets] Failed to load WildHuntCover: " + ex));
			}
		}
	}

	public static void Ensure3DAssetsLoaded(Shader valheimStandardShader)
	{
		if (!s_meshesLoaded || !((Object)(object)BossPbrMaterial != (Object)null))
		{
			DeerHeadMesh = LoadEmbeddedMesh("DeerHead.bin.gz", "Mesh_DeerHead");
			TrenchTorsoMesh = LoadEmbeddedMesh("TrenchCoatTorso.bin.gz", "Mesh_TrenchCoatTorso");
			TrenchSkirtMesh = LoadEmbeddedMesh("TrenchCoatSkirt.bin.gz", "Mesh_TrenchCoatSkirt");
			TrenchSleeveMesh = LoadEmbeddedMesh("TrenchSleeve.bin.gz", "Mesh_TrenchSleeve");
			BlackGloveMesh = LoadEmbeddedMesh("BlackGlove.bin.gz", "Mesh_BlackGlove");
			DarkBootMesh = LoadEmbeddedMesh("DarkBoot.bin.gz", "Mesh_DarkBoot");
			ChromeRevolverMesh = LoadEmbeddedMesh("ChromeRevolver.bin.gz", "Mesh_ChromeRevolver");
			SamuraiKatanaMesh = LoadEmbeddedMesh("SamuraiKatana.bin.gz", "Mesh_SamuraiKatana");
			Shader val = valheimStandardShader;
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Custom/Creature");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Custom/Piece");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Standard");
			}
			BossPbrMaterial = BuildValheimMaterial(val, "Mat_WildHuntBoss", "WildHunt_Albedo.png", "WildHunt_Roughness.png", "WildHunt_Normal.png", 0.35f);
			RevolverBangClip = SynthesizeRevolverShotClip();
			KatanaSlashClip = SynthesizeKatanaWhooshClip();
			s_meshesLoaded = true;
		}
	}

	public static Material GetAdditiveFxMaterial()
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		if ((Object)(object)AdditiveBulletFxMaterial != (Object)null)
		{
			return AdditiveBulletFxMaterial;
		}
		string[] array = new string[4] { "Particles/Standard Unlit", "Legacy Shaders/Particles/Additive", "Sprites/Default", "Unlit/Color" };
		Shader val = null;
		for (int i = 0; i < array.Length; i++)
		{
			val = Shader.Find(array[i]);
			if ((Object)(object)val != (Object)null)
			{
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Standard");
		}
		Material val2 = new Material(val);
		((Object)val2).name = "Mat_WildHuntBulletFx";
		if (val2.HasProperty("_Mode"))
		{
			val2.SetFloat("_Mode", 2f);
		}
		if (val2.HasProperty("_SrcBlend"))
		{
			val2.SetInt("_SrcBlend", 5);
		}
		if (val2.HasProperty("_DstBlend"))
		{
			val2.SetInt("_DstBlend", 1);
		}
		if (val2.HasProperty("_ZWrite"))
		{
			val2.SetInt("_ZWrite", 0);
		}
		val2.renderQueue = 3000;
		AdditiveBulletFxMaterial = val2;
		return val2;
	}

	public static void StartLoadingBossMusic(MonoBehaviour coroutineHost)
	{
		if (!s_musicLoadingStarted && !((Object)(object)coroutineHost == (Object)null))
		{
			s_musicLoadingStarted = true;
			coroutineHost.StartCoroutine(LoadBossMusicCoroutine());
		}
	}

	private static IEnumerator LoadBossMusicCoroutine()
	{
		string chosenPath = null;
		try
		{
			string text = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (string.IsNullOrEmpty(text))
			{
				text = Paths.PluginPath;
			}
			string text2 = Path.Combine(text, "Music");
			if (!Directory.Exists(text2))
			{
				Directory.CreateDirectory(text2);
			}
			string text3 = ((BangBangPlugin.CustomMusicFileName != null) ? BangBangPlugin.CustomMusicFileName.Value.Trim() : "");
			if (!string.IsNullOrEmpty(text3))
			{
				string text4 = (Path.IsPathRooted(text3) ? text3 : Path.Combine(text2, text3));
				if (File.Exists(text4))
				{
					chosenPath = text4;
				}
			}
			if (chosenPath == null)
			{
				string[] files = Directory.GetFiles(text2);
				string text5 = null;
				for (int i = 0; i < files.Length; i++)
				{
					switch (Path.GetExtension(files[i]).ToLowerInvariant())
					{
					case ".mp3":
					case ".ogg":
					case ".wav":
						if (Path.GetFileName(files[i]).Equals("VordtBossTheme.mp3", StringComparison.OrdinalIgnoreCase))
						{
							text5 = files[i];
							continue;
						}
						break;
					default:
						continue;
					}
					chosenPath = files[i];
					break;
				}
				if (chosenPath == null && text5 != null)
				{
					chosenPath = text5;
				}
			}
			if (chosenPath == null)
			{
				string text6 = Path.Combine(text2, "VordtBossTheme.mp3");
				byte[] array = ReadEmbeddedBytes("VordtBossTheme.mp3");
				if (array != null && array.Length > 1024)
				{
					File.WriteAllBytes(text6, array);
					chosenPath = text6;
				}
			}
		}
		catch (Exception ex)
		{
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogWarning((object)("[WildHuntMusic] Music folder check warning: " + ex.Message));
			}
		}
		if (string.IsNullOrEmpty(chosenPath) || !File.Exists(chosenPath))
		{
			try
			{
				string text7 = Path.Combine(Path.GetTempPath(), "BangBang_VordtBossTheme.mp3");
				if (!File.Exists(text7))
				{
					byte[] array2 = ReadEmbeddedBytes("VordtBossTheme.mp3");
					if (array2 != null && array2.Length > 1024)
					{
						File.WriteAllBytes(text7, array2);
					}
				}
				if (File.Exists(text7))
				{
					chosenPath = text7;
				}
			}
			catch
			{
			}
		}
		if (string.IsNullOrEmpty(chosenPath) || !File.Exists(chosenPath))
		{
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogWarning((object)"[WildHuntMusic] Could not locate VordtBossTheme.mp3; generating procedural Dark Souls choir fallback.");
			}
			VordtBossMusicClip = SynthesizeFallbackBossMusic();
			WildHuntMusicController.RegisterBossMusicInMusicMan();
			yield break;
		}
		string extLower = Path.GetExtension(chosenPath).ToLowerInvariant();
		AudioType chosenType = ((extLower == ".ogg") ? ((AudioType)14) : ((!(extLower == ".wav")) ? ((AudioType)13) : ((AudioType)20)));
		string uri = new Uri(chosenPath).AbsoluteUri;
		UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(uri, chosenType);
		try
		{
			yield return uwr.SendWebRequest();
			if ((int)uwr.result == 1)
			{
				AudioClip content = DownloadHandlerAudioClip.GetContent(uwr);
				if ((Object)(object)content != (Object)null && content.length > 1f)
				{
					((Object)content).name = "Music_WildHunt_Vordt";
					VordtBossMusicClip = content;
					WildHuntMusicController.RegisterBossMusicInMusicMan();
					if (BangBangPlugin.ModLogger != null)
					{
						BangBangPlugin.ModLogger.LogInfo((object)$"[WildHuntMusic] Loaded Dark Souls boss soundtrack '{Path.GetFileName(chosenPath)}' ({content.length:F1} sec)!");
					}
					yield break;
				}
			}
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogWarning((object)("[WildHuntMusic] UnityWebRequest audio load error (" + uwr.error + "), using procedural fallback."));
			}
		}
		finally
		{
			((IDisposable)uwr)?.Dispose();
		}
		VordtBossMusicClip = SynthesizeFallbackBossMusic();
		WildHuntMusicController.RegisterBossMusicInMusicMan();
	}

	private static AudioClip SynthesizeRevolverShotClip()
	{
		int num = 44100;
		float num2 = 0.68f;
		int num3 = (int)((float)num * num2);
		float[] array = new float[num3];
		Random random = new Random(357);
		float num4 = 0f;
		for (int i = 0; i < num3; i++)
		{
			float num5 = (float)i / (float)num;
			float num6 = Mathf.Exp((0f - num5) * 28f);
			float num7 = 42f + 115f * Mathf.Exp((0f - num5) * 35f);
			float num8 = Mathf.Sin((float)Math.PI * 2f * num7 * num5) * num6 * 1.15f;
			float num9 = (float)(random.NextDouble() * 2.0 - 1.0);
			float num10 = Mathf.Exp((0f - num5) * 140f);
			float num11 = num9 * num10 * 1.35f;
			float num12 = Mathf.Clamp01(0.32f * Mathf.Exp((0f - num5) * 4.5f) + 0.04f);
			num4 += num12 * (num9 - num4);
			float num13 = Mathf.Exp((0f - num5) * 5.8f);
			float num14 = num4 * num13 * 1.45f;
			float num15 = Mathf.Exp((0f - num5) * 55f);
			float num16 = Mathf.Sin((float)Math.PI * 4760f * num5) * num15 * 0.14f;
			float num17 = num8 + num11 + num14 + num16;
			array[i] = (float)Math.Tanh(num17 * 1.35f) * 0.92f;
		}
		AudioClip val = AudioClip.Create("SFX_WildHunt_RevolverBang", num3, 1, num, false);
		val.SetData(array, 0);
		return val;
	}

	private static AudioClip SynthesizeKatanaWhooshClip()
	{
		int num = 44100;
		float num2 = 0.36f;
		int num3 = (int)((float)num * num2);
		float[] array = new float[num3];
		Random random = new Random(1080);
		float num4 = 0f;
		for (int i = 0; i < num3; i++)
		{
			float num5 = (float)i / (float)num;
			float num6 = Mathf.Sin(Mathf.Clamp01(num5 / 0.28f) * (float)Math.PI);
			num6 *= num6;
			float num7 = (float)(random.NextDouble() * 2.0 - 1.0);
			num4 += 0.25f * (num7 - num4);
			float num8 = Mathf.Exp((0f - num5) * 12f);
			float num9 = (Mathf.Sin((float)Math.PI * 3360f * num5) + 0.5f * Mathf.Sin((float)Math.PI * 6240f * num5)) * num8 * 0.18f;
			array[i] = Mathf.Clamp(num4 * num6 * 0.85f + num9, -0.95f, 0.95f);
		}
		AudioClip val = AudioClip.Create("SFX_WildHunt_KatanaSlash", num3, 1, num, false);
		val.SetData(array, 0);
		return val;
	}

	private static AudioClip SynthesizeFallbackBossMusic()
	{
		int num = 22050;
		int num2 = 16;
		int num3 = num * num2;
		float[] array = new float[num3];
		float[] array2 = new float[8] { 73.42f, 73.42f, 87.31f, 82.41f, 69.3f, 73.42f, 110f, 116.54f };
		for (int i = 0; i < num3; i++)
		{
			float num4 = (float)i / (float)num;
			int num5 = (int)(num4 * 2f) % array2.Length;
			float num6 = num4 * 2f - Mathf.Floor(num4 * 2f);
			float num7 = array2[num5];
			float num8 = 0.35f * Mathf.Sin((float)Math.PI * 2f * num7 * num4) + 0.22f * Mathf.Sin((float)Math.PI * 4f * num7 * num4) + 0.12f * Mathf.Sin((float)Math.PI * 6f * num7 * num4);
			float num9 = Mathf.Sin((float)Math.PI * 2f * (58f + 40f * Mathf.Exp((0f - num6) * 18f)) * num6) * Mathf.Exp((0f - num6) * 7f) * 0.45f;
			array[i] = Mathf.Clamp(num8 * (0.65f + 0.35f * Mathf.Exp((0f - num6) * 3f)) + num9, -0.9f, 0.9f);
		}
		AudioClip val = AudioClip.Create("Music_WildHunt_Fallback", num3, 1, num, false);
		val.SetData(array, 0);
		return val;
	}

	private static Material BuildValheimMaterial(Shader shader, string matName, string albedoRes, string roughRes, string normalRes, float baseMetallic)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		Material val = new Material(shader);
		((Object)val).name = matName;
		Texture2D val2 = LoadEmbeddedTexture(albedoRes, linear: false, (FilterMode)1);
		Texture2D rough = LoadEmbeddedTexture(roughRes, linear: true, (FilterMode)1);
		Texture2D val3 = LoadEmbeddedTexture(normalRes, linear: true, (FilterMode)1);
		Texture2D val4 = BuildMetallicGlossMap(rough, 0.9f);
		if ((Object)(object)val2 != (Object)null)
		{
			if (val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", (Texture)(object)val2);
			}
			if (val.HasProperty("_BaseColorMap"))
			{
				val.SetTexture("_BaseColorMap", (Texture)(object)val2);
			}
		}
		if (val.HasProperty("_Color"))
		{
			val.SetColor("_Color", Color.white);
		}
		if ((Object)(object)val4 != (Object)null && val.HasProperty("_MetallicGlossMap"))
		{
			val.SetTexture("_MetallicGlossMap", (Texture)(object)val4);
			val.EnableKeyword("_METALLICGLOSSMAP");
		}
		if (val.HasProperty("_Metallic"))
		{
			val.SetFloat("_Metallic", baseMetallic);
		}
		if (val.HasProperty("_Glossiness"))
		{
			val.SetFloat("_Glossiness", 0.5f);
		}
		if ((Object)(object)val3 != (Object)null && val.HasProperty("_BumpMap"))
		{
			val.SetTexture("_BumpMap", (Texture)(object)val3);
			if (val.HasProperty("_BumpScale"))
			{
				val.SetFloat("_BumpScale", 0.85f);
			}
			val.EnableKeyword("_NORMALMAP");
		}
		if (val.HasProperty("_UseGlossmap"))
		{
			val.SetFloat("_UseGlossmap", 1f);
		}
		if (val.HasProperty("_TwoSidedNormals"))
		{
			val.SetFloat("_TwoSidedNormals", 1f);
		}
		if (val.HasProperty("_Cull"))
		{
			val.SetInt("_Cull", 0);
		}
		return val;
	}

	private static Texture2D BuildMetallicGlossMap(Texture2D rough, float metalPeak)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		if ((Object)(object)rough == (Object)null)
		{
			return null;
		}
		int width = ((Texture)rough).width;
		int height = ((Texture)rough).height;
		Color[] pixels = rough.GetPixels();
		Color[] array = (Color[])(object)new Color[pixels.Length];
		for (int i = 0; i < pixels.Length; i++)
		{
			float num = Mathf.Clamp01(pixels[i].r);
			float num2 = Mathf.Clamp01(1f - num);
			float num3 = Mathf.Clamp01((0.35f - num) / 0.18f);
			float num4 = metalPeak * num3;
			ref Color reference = ref array[i];
			reference = new Color(num4, num4, num4, num2);
		}
		Texture2D val = new Texture2D(width, height, (TextureFormat)4, false, true);
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		val.SetPixels(array);
		val.Apply();
		return val;
	}

	public static Texture2D LoadEmbeddedTexture(string resName, bool linear, FilterMode filter)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			byte[] array = ReadEmbeddedBytes(resName);
			if (array == null)
			{
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false, linear);
			if (ImageConversion.LoadImage(val, array))
			{
				((Object)val).name = resName;
				((Texture)val).filterMode = filter;
				((Texture)val).wrapMode = (TextureWrapMode)1;
				return val;
			}
		}
		catch (Exception ex)
		{
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogWarning((object)("Failed to load texture " + resName + ": " + ex.Message));
			}
		}
		return null;
	}

	public static Mesh LoadEmbeddedMesh(string resName, string meshName)
	{
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: 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)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: 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_0183: Expected O, but got Unknown
		byte[] array = ReadEmbeddedBytes(resName);
		if (array == null)
		{
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogError((object)("Missing embedded mesh resource: " + resName));
			}
			return null;
		}
		using MemoryStream stream = new MemoryStream(array);
		using GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress);
		using MemoryStream memoryStream = new MemoryStream();
		byte[] array2 = new byte[16384];
		int count;
		while ((count = gZipStream.Read(array2, 0, array2.Length)) > 0)
		{
			memoryStream.Write(array2, 0, count);
		}
		memoryStream.Position = 0L;
		using BinaryReader binaryReader = new BinaryReader(memoryStream);
		uint num = binaryReader.ReadUInt32();
		uint num2 = binaryReader.ReadUInt32();
		Vector3[] array3 = (Vector3[])(object)new Vector3[num];
		Vector3[] array4 = (Vector3[])(object)new Vector3[num];
		Vector2[] array5 = (Vector2[])(object)new Vector2[num];
		int[] array6 = new int[num2];
		for (int i = 0; i < num; i++)
		{
			ref Vector3 reference = ref array3[i];
			reference = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
		}
		for (int j = 0; j < num; j++)
		{
			ref Vector3 reference2 = ref array4[j];
			reference2 = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
		}
		for (int k = 0; k < num; k++)
		{
			ref Vector2 reference3 = ref array5[k];
			reference3 = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
		}
		for (int l = 0; l < num2; l++)
		{
			array6[l] = (int)binaryReader.ReadUInt32();
		}
		Mesh val = new Mesh();
		((Object)val).name = meshName;
		if (num > 65000)
		{
			val.indexFormat = (IndexFormat)1;
		}
		val.vertices = array3;
		val.normals = array4;
		val.uv = array5;
		val.triangles = array6;
		val.RecalculateBounds();
		val.RecalculateTangents();
		return val;
	}

	public static Mesh BakeTransformedMesh(Mesh src, Vector3 posOffset, Quaternion rot, float uniformScale)
	{
		//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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		if ((Object)(object)src == (Object)null)
		{
			return null;
		}
		Vector3[] vertices = src.vertices;
		Vector3[] normals = src.normals;
		Vector2[] uv = src.uv;
		int[] triangles = src.triangles;
		Vector3[] array = (Vector3[])(object)new Vector3[vertices.Length];
		Vector3[] array2 = (Vector3[])(object)new Vector3[normals.Length];
		for (int i = 0; i < vertices.Length; i++)
		{
			ref Vector3 reference = ref array[i];
			reference = rot * (vertices[i] * uniformScale) + posOffset;
		}
		for (int j = 0; j < normals.Length; j++)
		{
			ref Vector3 reference2 = ref array2[j];
			Vector3 val = rot * normals[j];
			reference2 = ((Vector3)(ref val)).normalized;
		}
		Mesh val2 = new Mesh();
		((Object)val2).name = ((Object)src).name + "_Baked";
		if (vertices.Length > 65000)
		{
			val2.indexFormat = (IndexFormat)1;
		}
		val2.vertices = array;
		val2.normals = array2;
		val2.uv = uv;
		val2.triangles = triangles;
		val2.RecalculateBounds();
		val2.RecalculateTangents();
		return val2;
	}

	public static byte[] ReadEmbeddedBytes(string resourceName)
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(resourceName);
		if (manifestResourceStream == null)
		{
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			for (int i = 0; i < manifestResourceNames.Length; i++)
			{
				if (manifestResourceNames[i].EndsWith(resourceName, StringComparison.OrdinalIgnoreCase))
				{
					manifestResourceStream = executingAssembly.GetManifestResourceStream(manifestResourceNames[i]);
					break;
				}
			}
		}
		if (manifestResourceStream == null)
		{
			return null;
		}
		using (manifestResourceStream)
		{
			using MemoryStream memoryStream = new MemoryStream();
			byte[] array = new byte[16384];
			int count;
			while ((count = manifestResourceStream.Read(array, 0, array.Length)) > 0)
			{
				memoryStream.Write(array, 0, count);
			}
			return memoryStream.ToArray();
		}
	}
}
public static class WildHuntBossModule
{
	public const string BossPrefabName = "WildHuntDeerBoss";

	public const string KatanaWeaponPrefabName = "WildHuntBossKatana_NPC";

	private static bool s_registered;

	public static EffectList VanillaHitEffects;

	public static EffectList VanillaSmokeDespawnEffects;

	public static void RegisterBossAndWeapons()
	{
		if (s_registered)
		{
			return;
		}
		try
		{
			Shader valheimStandardShader = FindVanillaShader();
			WildHuntAssets.Ensure3DAssetsLoaded(valheimStandardShader);
			CacheVanillaEffects();
			GameObject katanaWeapon = BuildNpcKatanaWeapon();
			BuildAndRegisterDeerBoss(katanaWeapon);
			s_registered = true;
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogInfo((object)"[WildHuntBoss] Registered Boss 'WildHuntDeerBoss' and NPC arsenal!");
			}
		}
		catch (Exception ex)
		{
			if (BangBangPlugin.ModLogger != null)
			{
				BangBangPlugin.ModLogger.LogError((object)("[WildHuntBoss] Failed to register boss: " + ex));
			}
		}
	}

	private static Shader FindVanillaShader()
	{
		string[] array = new string[3] { "SwordIron", "AxeIron", "ArmorLeatherChest" };
		for (int i = 0; i < array.Length; i++)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(array[i]);
			if (!((Object)(object)prefab == (Object)null))
			{
				MeshRenderer componentInChildren = prefab.GetComponentInChildren<MeshRenderer>(true);
				if ((Object)(object)componentInChildren != (Object)null && (Object)(object)((Renderer)componentInChildren).sharedMaterial != (Object)null && (Object)(object)((Renderer)componentInChildren).sharedMaterial.shader != (Object)null)
				{
					return ((Renderer)componentInChildren).sharedMaterial.shader;
				}
			}
		}
		return Shader.Find("Standard");
	}

	private static void CacheVanillaEffects()
	{
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Expected O, but got Unknown
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Expected O, but got Unknown
		GameObject prefab = PrefabManager.Instance.GetPrefab("SwordBlackmetal");
		if ((Object)(object)prefab == (Object)null)
		{
			prefab = PrefabManager.Instance.GetPrefab("SwordIron");
		}
		if ((Object)(object)prefab != (Object)null)
		{
			ItemDrop component = prefab.GetComponent<ItemDrop>();
			if ((Object)(object)component != (Object)null && component.m_itemData != null && component.m_itemData.m_shared != null)
			{
				VanillaHitEffects = component.m_itemData.m_shared.m_hitEffect;
			}
		}
		string[] array = new string[4] { "vfx_odin_despawn", "sfx_odin_despawn", "vfx_spawn_large", "vfx_spawn" };
		List<EffectData> list = new List<EffectData>();
		for (int i = 0; i < array.Length; i++)
		{
			GameObject prefab2 = PrefabManager.Instance.GetPrefab(array[i]);
			if ((Object)(object)prefab2 != (Object)null)
			{
				EffectData val = new EffectData();
				val.m_prefab = prefab2;
				val.m_enabled = true;
				list.Add(val);
			}
		}
		if (list.Count > 0)
		{
			VanillaSmokeDespawnEffects = new EffectList();
			VanillaSmokeDespawnEffects.m_effectPrefabs = list.ToArray();
		}
	}

	private static GameObject BuildNpcKatanaWeapon()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		string text = "SwordBlackmetal";
		if ((Object)(object)PrefabManager.Instance.GetPrefab(text) == (Object)null)
		{
			text = "SwordIron";
		}
		GameObject val = PrefabManager.Instance.CreateClonedPrefab("WildHuntBossKatana_NPC", text);
		val.transform.localScale = Vector3.one;
		Transform val2 = val.transform.Find("attach");
		if ((Object)(object)val2 != (Object)null)
		{
			Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					componentsInChildren[i].enabled = false;
				}
			}
			ParticleSystem[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<ParticleSystem>(true);
			for (int j = 0; j < componentsInChildren2.Length; j++)
			{
				if ((Object)(object)componentsInChildren2[j] != (Object)null)
				{
					((Component)componentsInChildren2[j]).gameObject.SetActive(false);
				}
			}
		}
		ItemDrop component = val.GetComponent<ItemDrop>();
		if ((Object)(object)component != (Object)null && component.m_itemData != null && component.m_itemData.m_shared != null)
		{
			component.m_itemData.m_dropPrefab = val;
			SharedData shared = component.m_itemData.m_shared;
			shared.m_name = "Samurai Katana";
			shared.m_useDurability = false;
			shared.m_aiAttackRange = 3.2f;
			shared.m_aiAttackRangeMin = 0f;
			shared.m_aiAttackInterval = 1.65f;
			shared.m_aiAttackMaxAngle = 35f;
			shared.m_aiPrioritized = true;
			shared.m_damages = new DamageTypes
			{
				m_slash = BangBangPlugin.BaseKatanaSlashDamage.Value,
				m_pierce = BangBangPlugin.BaseKatanaSlashDamage.Value * 0.25f
			};
			shared.m_attackForce = 45f;
			if (shared.m_attack != null)
			{
				shared.m_attack = shared.m_attack.Clone();
				shared.m_attack.m_attackRange = 3.1f;
				shared.m_attack.m_attackAngle = 110f;
				shared.m_attack.m_speedFactor = 0.45f;
			}
		}
		PrefabManager.Instance.AddPrefab(val);
		return val;
	}

	private static void BuildAndRegisterDeerBoss(GameObject katanaWeapon)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Expected O, but got Unknown
		string text = "Skeleton";
		if ((Object)(object)PrefabManager.Instance.GetPrefab(text) == (Object)null)
		{
			text = "Draugr";
		}
		GameObject val = PrefabManager.Instance.CreateClonedPrefab("WildHuntDeerBoss", text);
		val.transform.localScale = Vector3.one * 1.18f;
		Humanoid component = val.GetComponent<Humanoid>();
		if ((Object)(object)component != (Object)null)
		{
			((Character)component).m_name = "$enemy_wildhunt_deerboss";
			((Character)component).m_boss = true;
			((Character)component).m_bossEvent = "wild_hunt";
			((Character)component).m_faction = (Faction)8;
			((Character)component).m_group = "WildHunt";
			((Character)component).m_health = BangBangPlugin.BaseBossHealth.Value;
			((Character)component).m_walkSpeed = 2.6f;
			((Character)component).m_runSpeed = 6.8f;
			((Character)component).m_turnSpeed = 320f;
			((Character)component).m_runTurnSpeed = 280f;
			((Character)component).m_acceleration = 1.2f;
			((Character)component).m_staggerWhenBlocked = false;
			((Character)component).m_staggerDamageFactor = 0f;
			((Character)component).m_damageModifiers.m_pierce = (DamageModifier)1;
			((Character)component).m_damageModifiers.m_chop = (DamageModifier)4;
			((Character)component).m_damageModifiers.m_pickaxe = (DamageModifier)4;
			GameObject prefab = PrefabManager.Instance.GetPrefab("Deer");
			if ((Object)(object)prefab != (Object)null)
			{
				Character component2 = prefab.GetComponent<Character>();
				BaseAI component3 = prefab.GetComponent<BaseAI>();
				BaseAI component4 = val.GetComponent<BaseAI>();
				if ((Object)(object)component2 != (Object)null)
				{
					if (component2.m_hitEffects != null && component2.m_hitEffects.m_effectPrefabs != null && component2.m_hitEffects.m_effectPrefabs.Length > 0)
					{
						((Character)component).m_hitEffects = component2.m_hitEffects;
					}
					if (component2.m_deathEffects != null && component2.m_deathEffects.m_effectPrefabs != null && component2.m_deathEffects.m_effectPrefabs.Length > 0)
					{
						((Character)component).m_deathEffects = component2.m_deathEffects;
					}
				}
				if ((Object)(object)component3 != (Object)null && (Object)(object)component4 != (Object)null)
				{
					component4.m_idleSound = component3.m_idleSound;
					component4.m_idleSoundInterval = 6f;
					component4.m_idleSoundChance = 0.65f;
					component4.m_alertedEffects = component3.m_alertedEffects;
				}
			}
			component.m_defaultItems = (GameObject[])(object)new GameObject[1] { katanaWeapon };
			component.m_randomWeapon = (GameObject[])(object)new GameObject[0];
			component.m_randomArmor = (GameObject[])(object)new GameObject[0];
			component.m_randomShield = (GameObject[])(object)new GameObject[0];
			component.m_randomSets = (ItemSet[])(object)new ItemSet[0];
		}
		MonsterAI component5 = val.GetComponent<MonsterAI>();
		if ((Object)(object)component5 != (Object)null)
		{
			((BaseAI)component5).m_viewRange = 65f;
			((BaseAI)component5).m_viewAngle = 160f;
			((BaseAI)component5).m_hearRange = 80f;
			component5.m_alertRange = 55f;
			((BaseAI)component5).m_mistVision = true;
			component5.m_enableHuntPlayer = true;
			component5.m_attackPlayerObjects = true;
			component5.m_fleeIfHurtWhenTargetCantBeReached = false;
			component5.m_fleeIfLowHealth = 0f;
			component5.m_fleeIfNotAlerted = false;
			((BaseAI)component5).m_afraidOfFire = false;
			((BaseAI)component5).m_avoidFire = false;
			((BaseAI)component5).m_avoidWater = true;
			component5.m_minAttackInterval = 0.95f;
			component5.m_circleTargetInterval = 8f;
			component5.m_circleTargetDuration = 2.4f;
			component5.m_circleTargetDistance = 9f;
			FieldInfo fieldInfo = AccessTools.Field(typeof(MonsterAI), "m_despawnInDay");
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(component5, false);
			}
		}
		CharacterDrop val2 = val.GetComponent<CharacterDrop>();
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = val.AddComponent<CharacterDrop>();
		}
		val2.m_drops = new List<Drop>();
		AddLootDrop(val2.m_drops, "DeerHide", 2, 5, 1f);
		AddLootDrop(val2.m_drops, "DeerMeat", 2, 4, 1f);
		AddLootDrop(val2.m_drops, "Coins", 5, 25, 1f);
		val.AddComponent<WildHuntBossComponent>();
		CreatureManager.Instance.AddCreature(new CustomCreature(val, false));
	}

	private static void AddLootDrop(List<Drop> list, string itemName, int minAmt, int maxAmt, float chance)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		GameObject prefab = PrefabManager.Instance.GetPrefab(itemName);
		if (!((Object)(object)prefab == (Object)null))
		{
			Drop val = new Drop();
			val.m_prefab = prefab;
			val.m_amountMin = minAmt;
			val.m_amountMax = maxAmt;
			val.m_chance = chance;
			val.m_onePerPlayer = false;
			val.m_levelMultiplier = false;
			list.Add(val);
		}
	}
}
public class WildHuntBossComponent : MonoBehaviour
{
	public static readonly List<WildHuntBossComponent> ActiveInstances = new List<WildHuntBossComponent>();

	private Humanoid m_humanoid;

	private MonsterAI m_ai;

	private ZNetView m_nview;

	private bool m_visualsAttached;

	private bool m_statsScaled;

	private float m_damageMultiplier = 1f;

	private int m_bossTier = 1;

	private Transform m_hipsBone;

	private Transform m_spineBone;

	private Transform m_rUpperArmBone;

	private Transform m_rForeArmBone;

	private Transform m_rHandBone;

	private Transform m_lForeArmBone;

	private Transform m_lHandBone;

	private Transform m_revolverTransform;

	private Transform m_katanaTransform;

	private Transform m_waistBridgeTransform;

	private float m_revolverFireTimer = 1.6f;

	private int m_shotCounter;

	private float m_aimPoseHoldTimer;

	private Vector3 m_aimTargetWorldPos;

	private float m_dashCooldownTimer = 6f;

	private float m_dawnCheckTimer = 1.5f;

	public bool IsAliveAndActive
	{
		get
		{
			if ((Object)(object)m_humanoid != (Object)null && !((Character)m_humanoid).IsDead())
			{
				return ((Component)this).gameObject.activeInHierarchy;
			}
			return false;
		}
	}

	public float CurrentDamageMultiplier => m_damageMultiplier;

	private void Awake()
	{
		m_humanoid = ((Component)this).GetComponent<Humanoid>();
		m_ai = ((Component)this).GetComponent<MonsterAI>();
		m_nview = ((Component)this).GetComponent<ZNetView>();
		if (!ActiveInstances.Contains(this))
		{
			ActiveInstances.Add(this);
		}
		if ((Object)(object)m_nview != (Object)null && m_nview.IsValid())
		{
			m_nview.Register<Vector3, Vector3>("RPC_WildHuntFireBullet", (Action<long, Vector3, Vector3>)RPC_WildHuntFireBullet);
		}
	}

	private void Start()
	{
		AttachFull3DCostumeRig();
		ApplyBossProgressionScaling();
		if ((Object)(object)m_ai != (Object)null)
		{
			m_ai.SetDespawnInDay(false);
			((BaseAI)m_ai).SetHuntPlayer(true);
		}
	}

	private void OnDestroy()
	{
		ActiveInstances.Remove(this);
	}

	private void AttachFull3DCostumeRig()
	{
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: 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_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0590: Unknown result type (might be due to invalid IL or missing references)
		//IL_0595: Unknown result type (might be due to invalid IL or missing references)
		//IL_061e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0625: Expected O, but got Unknown
		//IL_063b: Unknown result type (might be due to invalid IL or missing references)
		//IL_066c: 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_05e7: Unknown result type (might be due to invalid IL or missing references)
		if (m_visualsAttached)
		{
			return;
		}
		m_visualsAttached = true;
		WildHuntAssets.Ensure3DAssetsLoaded(null);
		Material bossPbrMaterial = WildHuntAssets.BossPbrMaterial;
		if ((Object)(object)bossPbrMaterial == (Object)null)
		{
			return;
		}
		SkinnedMeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if ((Object)(object)componentsInChildren[i] != (Object)null)
			{
				((Renderer)componentsInChildren[i]).enabled = false;
			}
		}
		ParticleSystem[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
		for (int j = 0; j < componentsInChildren2.Length; j++)
		{
			if ((Object)(object)componentsInChildren2[j] != (Object)null)
			{
				((Component)componentsInChildren2[j]).gameObject.SetActive(false);
			}
		}
		Animator componentInChildren = ((Component)this).GetComponentInChildren<Animator>(true);
		Transform val = FindRigBone(componentInChildren, (HumanBodyBones)0, new string[3] { "Hips", "Pelvis", "root" });
		Transform val2 = FindRigBone(componentInChildren, (HumanBodyBones)7, new string[4] { "Spine1", "Spine", "Spine2", "Chest" });
		Transform val3 = FindRigBone(componentInChildren, (HumanBodyBones)10, new string[2] { "Head", "head" });
		Transform startBone = FindRigBone(componentInChildren, (HumanBodyBones)13, new string[3] { "LeftArm", "L_UpperArm", "LeftUpperArm" });
		Transform val4 = FindRigBone(componentInChildren, (HumanBodyBones)15, new string[3] { "LeftForeArm", "L_ForeArm", "LeftLowerArm" });
		Transform val5 = FindRigBone(componentInChildren, (HumanBodyBones)17, new string[2] { "LeftHand", "L_Hand" });
		Transform val6 = FindRigBone(componentInChildren, (HumanBodyBones)14, new string[3] { "RightArm", "R_UpperArm", "RightUpperArm" });
		Transform val7 = FindRigBone(componentInChildren, (HumanBodyBones)16, new string[3] { "RightForeArm", "R_ForeArm", "RightLowerArm" });
		Transform val8 = FindRigBone(componentInChildren, (HumanBodyBones)18, new string[2] { "RightHand", "R_Hand" });
		Transform val9 = FindRigBone(componentInChildren, (HumanBodyBones)3, new string[3] { "LeftLeg", "L_Calf", "LeftLowerLeg" });
		Transform val10 = FindRigBone(componentInChildren, (HumanBodyBones)4, new string[3] { "RightLeg", "R_Calf", "RightLowerLeg" });
		m_hipsBone = val;
		m_spineBone = val2;
		m_rUpperArmBone = val6;
		m_rForeArmBone = val7;
		m_rHandBone = val8;
		m_lForeArmBone = val4;
		m_lHandBone = val5;
		if ((Object)(object)val != (Object)null && (Object)(object)WildHuntAssets.TrenchSkirtMesh != (Object)null)
		{
			AttachWorldSizedPart(val, "WildHunt_CoatSkirt", WildHuntAssets.TrenchSkirtMesh, bossPbrMaterial, new Vector3(0f, 0.14f, 0f), Quaternion.identity, 1.2f);
			GameObject val11 = AttachWorldSizedPart(val, "WildHunt_WaistUnderBridge", WildHuntAssets.TrenchSleeveMesh, bossPbrMaterial, new Vector3(0f, 0.05f, 0f), Quaternion.identity, 1f);
			if ((Object)(object)val11 != (Object)null)
			{
				m_waistBridgeTransform = val11.transform;
			}
		}
		if ((Object)(object)val2 != (Object)null && (Object)(object)WildHuntAssets.TrenchTorsoMesh != (Object)null)
		{
			float num = -0.06f;
			if ((Object)(object)val != (Object)null && (Object)(object)val3 != (Object)null)
			{
				float num2 = Mathf.Lerp(val.position.y, val3.position.y, 0.56f);
				num = num2 - val2.position.y;
			}
			AttachWorldSizedPart(val2, "WildHunt_CoatTorso", WildHuntAssets.TrenchTorsoMesh, bossPbrMaterial, new Vector3(0f, num, 0f), Quaternion.identity, 1.22f);
		}
		if ((Object)(object)val3 != (Object)null && (Object)(object)WildHuntAssets.DeerHeadMesh != (Object)null)
		{
			AttachWorldSizedPart(val3, "WildHunt_DeerHead", WildHuntAssets.DeerHeadMesh, bossPbrMaterial, new Vector3(0f, -0.05f, 0.02f), Quaternion.identity, 1.24f);
		}
		AttachLimbSegment(startBone, val4, "WildHunt_Sleeve_LU", WildHuntAssets.TrenchSleeveMesh, bossPbrMaterial, 1.18f);
		AttachLimbSegment(val4, val5, "WildHunt_Sleeve_LF", WildHuntAssets.TrenchSleeveMesh, bossPbrMaterial, 1.15f);
		AttachLimbSegment(val6, val7, "WildHunt_Sleeve_RU", WildHuntAssets.TrenchSleeveMesh, bossPbrMaterial, 1.18f);
		AttachLimbSegment(val7, val8, "WildHunt_Sleeve_RF", WildHuntAssets.TrenchSleeveMesh, bossPbrMaterial, 1.15f);
		if ((Object)(object)val5 != (Object)null && (Object)(object)WildHuntAssets.BlackGloveMesh != (Object)null)
		{
			AttachLimbSegment(val5, null, "WildHunt_LeftGlove", WildHuntAssets.BlackGloveMesh, bossPbrMaterial, 1.15f);
		}
		if ((Object)(object)val8 != (Object)null && (Object)(object)WildHuntAssets.BlackGloveMesh != (Object)null)
		{
			AttachLimbSegment(val8, null, "WildHunt_RightGlove", WildHuntAssets.BlackGloveMesh, bossPbrMaterial, 1.15f);
		}
		if ((Object)(object)val9 != (Object)null && (Object)(object)WildHuntAssets.DarkBootMesh != (Object)null)
		{
			AttachLimbSegment(val9, null, "WildHunt_LeftBoot", WildHuntAssets.DarkBootMesh, bossPbrMaterial, 1.15f);
		}
		if ((Object)(object)val10 != (Object)null && (Object)(object)WildHuntAssets.DarkBootMesh != (Object)null)
		{
			AttachLimbSegment(val10, null, "WildHunt_RightBoot", WildHuntAssets.DarkBootMesh, bossPbrMaterial, 1.15f);
		}
		if ((Object)(object)val8 != (Object)null && (Object)(object)WildHuntAssets.ChromeRevolverMesh != (Object)null)
		{
			GameObject val12 = AttachWorldSizedPart(val8, "WildHunt_RightHandRevolver", WildHuntAssets.ChromeRevolverMesh, bossPbrMaterial, Vector3.zero, Quaternion.identity, 1.26f);
			if ((Object)(object)val12 != (Object)null)
			{
				m_revolverTransform = val12.transform;
			}
		}
		if ((Object)(object)val5 != (Object)null && (Object)(object)WildHuntAssets.SamuraiKatanaMesh != (Object)null)
		{
			GameObject val13 = AttachWorldSizedPart(val5, "WildHunt_LeftHandKatana", WildHuntAssets.SamuraiKatanaMesh, bossPbrMaterial, Vector3.zero, Quaternion.identity, 1.18f);
			if ((Object)(object)val13 != (Object)null)
			{
				m_katanaTransform = val13.transform;
			}
		}
		if ((Object)(object)val2 != (Object)null)
		{
			GameObject val14 = new GameObject("WildHunt_NightAuraLight");
			val14.transform.SetParent(val2, false);
			val14.transform.localPosition = Vector3.zero;
			Light val15 = val14.AddComponent<Light>();
			val15.type = (LightType)2;
			val15.color = new Color(1f, 0.55f, 0.28f, 1f);
			val15.range = 4.5f;
			val15.intensity = 0.75f;
			val15.shadows = (LightShadows)0;
		}
	}

	private Transform FindRigBone(Animator anim, HumanBodyBones humanBone, string[] nameFallbacks)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)anim != (Object)null && anim.isHuman)
		{
			Transform boneTransform = anim.GetBoneTransform(humanBone);
			if ((Object)(object)boneTransform != (Object)null)
			{
				return boneTransform;
			}
		}
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
		for (int i = 0; i < nameFallbacks.Length; i++)
		{
			string text = nameFallbacks[i].ToLowerInvariant();
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				if ((Object)(object)componentsInChildren[j] != (Object)null && ((Object)componentsInChildren[j]).name.ToLowerInvariant() == text)
				{
					return componentsInChildren[j];
				}
			}
		}
		for (int k = 0; k < nameFallbacks.Length; k++)
		{
			string value = nameFallbacks[k].ToLowerInvariant();
			for (int l = 0; l < componentsInChildren.Length; l++)
			{
				if ((Object)(object)componentsInChildren[l] != (Object)null && ((Object)componentsInChildren[l]).name.ToLowerInvariant().Contains(value))
				{
					return componentsInChildren[l];
				}
			}
		}
		return null;
	}

	private GameObject AttachWorldSizedPart(Transform bone, string partName, Mesh mesh, Material mat, Vector3 worldMeterOffset, Quaternion rotInCharacterSpace, float worldMeterScale)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)bone == (Object)null || (Object)(object)mesh == (Object)null)
		{
			return null;
		}
		GameObject val = new GameObject(partName);
		val.layer = ((Component)this).gameObject.layer;
		val.transform.SetParent(bone, false);
		val.transform.rotation = ((Component)this).transform.rotation * rotInCharacterSpace;
		val.transform.position = bone.position + ((Component)this).transform.rotation * worldMeterOffset;
		Vector3 lossyScale = bone.lossyScale;
		float num = ((Vector3)(ref lossyScale)).magnitude / 1.7320508f;
		if (num < 1E-05f)
		{
			num = 1f;
		}
		val.transform.localScale = Vector3.one * (worldMeterScale / num);
		MeshFilter val2 = val.AddComponent<MeshFilter>();
		val2.sharedMesh = mesh;
		MeshRenderer val3 = val.AddComponent<MeshRenderer>();
		((Renderer)val3).sharedMaterials = (Material[])(object)new Material[1] { mat };
		((Renderer)val3).shadowCastingMode = (ShadowCastingMode)1;
		((Renderer)val3).receiveShadows = true;
		return val;
	}

	private void AttachLimbSegment(Transform startBone, Transform endBone, string partName, Mesh mesh, Material mat, float worldMeterScale)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)startBone == (Object)null || (Object)(object)mesh == (Object)null)
		{
			return;
		}
		GameObject val = new GameObject(partName);
		val.layer = ((Component)this).gameObject.layer;
		val.transform.SetParent(startBone, false);
		val.transform.position = startBone.position;
		if ((Object)(object)endBone != (Object)null)
		{
			Vector3 val2 = endBone.position - startBone.position;
			if (((Vector3)(ref val2)).sqrMagnitude > 0.0004f)
			{
				Vector3 val3 = endBone.position - startBone.position;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				val.transform.rotation = Quaternion.FromToRotation(Vector3.up, normalized);
				goto IL_00cc;
			}
		}
		val.transform.rotation = Quaternion.FromToRotation(Vector3.up, -((Component)this).transform.up);
		goto IL_00cc;
		IL_00cc:
		Vector3 lossyScale = startBone.lossyScale;
		float num = ((Vector3)(ref lossyScale)).magnitude / 1.7320508f;
		if (num < 1E-05f)
		{
			num = 1f;
		}
		val.transform.localScale = Vector3.one * (worldMeterScale / num);
		MeshFilter val4 = val.AddComponent<MeshFilter>();
		val4.sharedMesh = mesh;
		MeshRenderer val5 = val.AddComponent<MeshRenderer>();
		((Renderer)val5).sharedMaterials = (Material[])(object)new Material[1] { mat };
		((Renderer)val5).shadowCastingMode = (ShadowCastingMode)1;
	}

	public static void CalculateProgressionTier(out int tierIndex, out float hpTarget, out float dmgMult)
	{
		tierIndex = 1;
		if ((Object)(object)ZoneSystem.instance != (Object)null)
		{
			if (ZoneSystem.instance.GetGlobalKey("defeated_fader"))
			{
				tierIndex = 7;
			}
			else if (ZoneSystem.instance.GetGlobalKey("defeated_queen"))
			{
				tierIndex = 6;
			}
			else if (ZoneSystem.instance.GetGlobalKey("defeated_goblinking"))
			{
				tierIndex = 5;
			}
			else if (ZoneSystem.instance.GetGlobalKey("defeated_dragon"))
			{
				tierIndex = 4;
			}
			else if (ZoneSystem.instance.GetGlobalKey("defeated_bonemass"))
			{
				tierIndex = 3;
			}
			else if (ZoneSystem.instance.GetGlobalKey("defeated_gdking"))
			{
				tierIndex = 2;
			}
			else
			{
				tierIndex = 1;
			}
		}
		float value = BangBangPlugin.BaseBossHealth.Value;
		float[] array = new float[8] { 1f, 1f, 2f, 3.35f, 5.1f, 7.5f, 10.5f, 14.5f };
		float[] array2 = new float[8] { 1f, 1f, 1.55f, 2.15f, 2.85f, 3.65f, 4.6f, 5.75f };
		int num = Mathf.Clamp(tierIndex, 1, 7);
		hpTarget = value * array[num] * BangBangPlugin.ProgressionMultiplierScale.Value;
		dmgMult = array2[num] * BangBangPlugin.ProgressionMultiplierScale.Value;
	}

	private void ApplyBossProgressionScaling()
	{
		if (m_statsScaled || (Object)(object)m_humanoid == (Object)null)
		{
			return;
		}
		m_statsScaled = true;
		CalculateProgressionTier(out var tierIndex, out var hpTarget, out var dmgMult);
		m_bossTier = tierIndex;
		m_damageMultiplier = Mathf.Max(0.5f, dmgMult);
		if ((Object)(object)m_nview != (Object)null && m_nview.IsValid())
		{
			ZDO zDO = m_nview.GetZDO();
			if (zDO != null)
			{
				float num = zDO.GetFloat("WildHunt_ScaledMaxHP", 0f);
				float num2 = zDO.GetFloat("WildHunt_DmgMult", 0f);
				if (num > 1f)
				{
					m_damageMultiplier = ((num2 > 0.1f) ? num2 : m_damageMultiplier);
					((Character)m_humanoid).SetMaxHealth(num);
					return;
				}
				if (m_nview.IsOwner())
				{
					zDO.Set("WildHunt_ScaledMaxHP", hpTarget);
					zDO.Set("WildHunt_DmgMult", m_damageMultiplier);
					((Character)m_humanoid).SetMaxHealth(hpTarget);
					((Character)m_humanoid).SetHealth(hpTarget);
				}
			}
		}
		else
		{
			((Character)m_humanoid).SetMaxHealth(hpTarget);
			((Character)m_humanoid).SetHealth(hpTarget);
		}
		if (BangBangPlugin.ModLogger != null)
		{
			BangBangPlugin.ModLogger.LogInfo((object)$"[WildHuntBoss] Spawned Tier {m_bossTier} Boss: MaxHP={hpTarget:F0}, DamageMult={m_damageMultiplier:F2}x");
		}
	}

	private void Update()
	{
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)m_humanoid == (Object)null || ((Character)m_humanoid).IsDead())
		{
			return;
		}
		float deltaTime = Time.deltaTime;
		if (m_aimPoseHoldTimer > 0f)
		{
			m_aimPoseHoldTimer -= deltaTime;
		}
		if ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && !m_nview.IsOwner())
		{
			return;
		}
		m_dawnCheckTimer -= deltaTime;
		if (m_dawnCheckTimer <= 0f)
		{
			m_dawnCheckTimer = 1.5f;
			if ((!((Object)(object)m_nview != (Object)null) || !m_nview.IsValid() || !m_nview.GetZDO().GetBool("WildHunt_IgnoreDaylight", false)) && (Object)(object)EnvMan.instance != (Object)null && EnvMan.IsDaylight())
			{
				VanishIntoMorningMist();
				return;
			}
		}
		if ((Object)(object)m_ai == (Object)null)
		{
			return;
		}
		Character targetCreature = ((BaseAI)m_ai).GetTargetCreature();
		if ((Object)(object)targetCreature == (Object)null || targetCreature.IsDead())
		{
			return;
		}
		float num = Vector3.Distance(((Component)this).transform.position, ((Component)targetCreature).transform.position);
		m_revolverFireTimer -= deltaTime;
		if (m_revolverFireTimer <= 0f && num >= 3.4f && num <= 36f)
		{
			m_shotCounter++;
			bool flag = m_shotCounter % 3 == 0;
			m_revolverFireTimer = (flag ? 3.2f : 2.1f);
			if (flag)
			{
				((MonoBehaviour)this).StartCoroutine(FireRevolverBurstCoroutine(targetCreature, 3, 0.22f));
			}
			else
			{
				FireSingleRevolverRoundAt(targetCreature, 1f);
			}
		}
		m_dashCooldownTimer -= deltaTime;
		if (m_dashCooldownTimer <= 0f && num >= 5f && num <= 11.5f && m_aimPoseHoldTimer <= 0.1f)
		{
			m_dashCooldownTimer = 8f;
			PerformKatanaIaidoDash(targetCreature);
		}
	}

	private IEnumerator FireRevolverBurstCoroutine(Character target, int count, float interval)
	{
		for (int i = 0; i < count; i++)
		{
			if ((Object)(object)m_humanoid == (Object)null)
			{
				break;
			}
			if (((Character)m_humanoid).IsDead())
			{
				break;
			}
			if ((Object)(object)target == (Object)null)
			{
				break;
			}
			if (target.IsDead())
			{
				break;
			}
			FireSingleRevolverRoundAt(target, 0.8f);
			if (i + 1 < count)
			{
				yield return (object)new WaitForSeconds(interval);
			}
		}
	}

	private void FireSingleRevolverRoundAt(Character target, float burstDmgScale)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: 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_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: 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_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01e1: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)target == (Object)null))
		{
			Vector3 val = ((Component)target).transform.position - ((Component)this).transform.position;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude > 0.04f)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
			}
			m_aimTargetWorldPos = target.GetCenterPoint();
			m_aimPoseHoldTimer = 0.65f;
			Vector3 val2 = (((Object)(object)m_revolverTransform != (Object)null) ? m_revolverTransform.TransformPoint(new Vector3(0f, 0.068f, 0.35f)) : ((!((Object)(object)m_rHandBone != (Object)null)) ? (((Component)this).transform.position + Vector3.up * 1.45f + ((Component)this).transform.forward * 0.65f) : (m_rHandBone.position + ((Component)this).transform.forward * 0.45f + Vector3.up * 0.1f)));
			Vector3 val3 = m_aimTargetWorldPos - val2;
			if (((Vector3)(ref val3)).sqrMagnitude < 0.05f)
			{
				val3 = ((Component)this).transform.forward;
			}
			((Vector3)(ref val3)).Normalize();
			Quaternion val4 = Quaternion.Euler(Random.Range(-1.5f, 1.5f), Random.Range(-1.8f, 1.8f), 0f);
			Vector3 val5 = val4 * val3;
			if ((Object)(object)m_nview != (Object)null && m_nview.IsValid())
			{
				m_nview.InvokeRPC(ZNetView.Everybody, "RPC_WildHuntFireBullet", new object[2]
				{
					val2,
					val5 * burstDmgScale
				});
			}
			else
			{
				SpawnBulletAndGunshotLocal(val2, val5, burstDmgScale);
			}
		}
	}

	private void RPC_WildHuntFireBullet(long sender, Vector3 muzzlePos, Vector3 dirScaled)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		float num = ((Vector3)(ref dirScaled)).magnitude;
		if (num < 0.05f)
		{
			num = 1f;
		}
		Vector3 normalized = ((Vector3)(ref dirScaled)).normalized;
		m_aimTargetWorldPos = muzzlePos + normalized * 12f;
		m_aimPoseHoldTimer = 0.65f;
		SpawnBulletAndGunshotLocal(muzzlePos, normalized, num);
	}

	private void SpawnBulletAndGunshotLocal(Vector3 muzzlePos, Vector3 dir, float burstDmgScale)
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: 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_0100: Expected O, but got Unknown
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)WildHuntAssets.RevolverBangClip != (Object)null)
		{
			GameObject val = new GameObject("WildHunt_GunshotSFX");
			val.transform.position = muzzlePos;
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.clip = WildHuntAssets.RevolverBangClip;
			val2.spatialBlend = 0.3f;
			val2.minDistance = 18f;
			val2.maxDistance = 120f;
			val2.volume = 1f;
			val2.pitch = Random.Range(0.95f, 1.06f);
			val2.Play();
			Object.Destroy((Object)(object)val, 1.1f);
		}
		GameObject val3 = new GameObject("WildHunt_MuzzleFlash");
		val3.transform.position = muzzlePos;
		Light val4 = val3.AddComponent<Light>();
		val4.type = (LightType)2;
		val4.color = new Color(1f, 0.78f, 0.32f, 1f);
		val4.range = 9.5f;
		val4.intensity = 5f;
		val4.shadows = (LightShadows)0;
		Object.Destroy((Object)(object)val3, 0.09f);
		GameObject val5 = new GameObject("WildHunt_LiveBullet");
		val5.transform.position = muzzlePos;
		val5.transform.rotation = Quaternion.LookRotation(dir, Vector3.up);
		float pierceDamage = BangBangPlugin.BaseRevolverDamage.Value * burstDmgScale * m_damageMultiplier;
		bool authoritativeDamage = (Object)(object)m_nview == (Object)null || !m_nview.IsValid() || m_nview.IsOwner();
		RevolverBulletProjectile revolverBulletProjectile = val5.AddComponent<RevolverBulletProjectile>();
		revolverBulletProjectile.LaunchDirect((Character)(object)m_humanoid, dir * 64f, pierceDamage, authoritativeDamage);
	}

	private void LateUpdate()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0412: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		//IL_0431: Unknown result type (might be due to invalid IL or missing references)
		//IL_0436: Unknown result type (might be due to invalid IL or missing references)
		//IL_0441: Unknown result type (might be due to invalid IL or missing references)
		//IL_044b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0450: Unknown result type (might be due to invalid IL or missing references)
		//IL_0455: Unknown result type (might be due to invalid IL or missing references)
		//IL_0459: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: 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_0296: 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_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_056d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0572: Unknown result type (might be due to invalid IL or missing references)
		//IL_0574: 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_057a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0581: Unknown result type (might be due to invalid IL or missing references)
		//IL_0586: Unknown result type (might be due to invalid IL or missing references)
		//IL_058b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0477: Unknown result type (might be due to invalid IL or missing references)
		//IL_0482: Unknown result type (might be due to invalid IL or missing references)
		//IL_0487: Unknown result type (might be due to invalid IL or missing references)
		//IL_048c: 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_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: 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_02ac: 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)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: 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_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04be: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d2: 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_04dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0381: Unknown result type (might be due to invalid IL or missing references)
		//IL_0386: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Unknown re