Decompiled source of ValheimCheats v1.0.0

ValheimCheats.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using ValheimCheats.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ValheimCheats")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ValheimCheats")]
[assembly: AssemblyTitle("ValheimCheats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ValheimCheats
{
	public static class CheatsManager
	{
		private static readonly FieldRef<Player, bool> DebugFlyRef = AccessTools.FieldRefAccess<Player, bool>("m_debugFly");

		private static readonly FieldRef<Player, bool> GodModeRef = AccessTools.FieldRefAccess<Player, bool>("m_godMode");

		private static readonly FieldRef<Player, bool> NoPlacementCostRef = AccessTools.FieldRefAccess<Player, bool>("m_noPlacementCost");

		private static readonly FieldRef<Player, float> StaminaRef = AccessTools.FieldRefAccess<Player, float>("m_stamina");

		private static readonly FieldRef<Character, ZNetView> NviewRef = AccessTools.FieldRefAccess<Character, ZNetView>("m_nview");

		private static GameObject _nightVisionLightObj;

		private static Light _nightVisionLight;

		public static void ToggleGodMode()
		{
			ModConfig.GodModeEnabled = !ModConfig.GodModeEnabled;
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				Player.m_localPlayer.SetGodMode(ModConfig.GodModeEnabled);
				if (ModConfig.GodModeEnabled)
				{
					((Character)Player.m_localPlayer).SetHealth(((Character)Player.m_localPlayer).GetMaxHealth());
				}
			}
			Notify("Бессмертие (God Mode)", ModConfig.GodModeEnabled);
		}

		public static void ToggleStamina()
		{
			ModConfig.InfiniteStaminaEnabled = !ModConfig.InfiniteStaminaEnabled;
			if (ModConfig.InfiniteStaminaEnabled && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				StaminaRef.Invoke(Player.m_localPlayer) = ((Character)Player.m_localPlayer).GetMaxStamina();
			}
			Notify("Бесконечная выносливость", ModConfig.InfiniteStaminaEnabled);
		}

		public static void ToggleFreeBuild()
		{
			ModConfig.FreeBuildEnabled = !ModConfig.FreeBuildEnabled;
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				Player.m_localPlayer.SetNoPlacementCost(ModConfig.FreeBuildEnabled);
			}
			Notify("Бесплатное строительство", ModConfig.FreeBuildEnabled);
		}

		public static void ToggleFly()
		{
			ModConfig.FlyEnabled = !ModConfig.FlyEnabled;
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				DebugFlyRef.Invoke(Player.m_localPlayer) = ModConfig.FlyEnabled;
				Character.m_debugFlySpeed = (int)ModConfig.FlySpeed.Value;
				ZNetView val = NviewRef.Invoke((Character)(object)Player.m_localPlayer);
				if ((Object)(object)val != (Object)null && val.GetZDO() != null)
				{
					val.GetZDO().Set(ZDOVars.s_debugFly, ModConfig.FlyEnabled);
				}
			}
			Notify("Полёт (Fly Mode)", ModConfig.FlyEnabled);
		}

		public static void ToggleNightVision()
		{
			ModConfig.NightVisionEnabled = !ModConfig.NightVisionEnabled;
			ApplyNightVisionState(ModConfig.NightVisionEnabled);
			Notify("Ночное зрение (День ночью)", ModConfig.NightVisionEnabled);
		}

		public static void ToggleAll()
		{
			bool flag = (ModConfig.GodModeEnabled = !ModConfig.GodModeEnabled || !ModConfig.InfiniteStaminaEnabled || !ModConfig.FreeBuildEnabled || !ModConfig.FlyEnabled || !ModConfig.NightVisionEnabled);
			ModConfig.InfiniteStaminaEnabled = flag;
			ModConfig.FreeBuildEnabled = flag;
			ModConfig.FlyEnabled = flag;
			ModConfig.NightVisionEnabled = flag;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				localPlayer.SetGodMode(flag);
				if (flag)
				{
					((Character)localPlayer).SetHealth(((Character)localPlayer).GetMaxHealth());
					StaminaRef.Invoke(localPlayer) = ((Character)localPlayer).GetMaxStamina();
				}
				localPlayer.SetNoPlacementCost(flag);
				DebugFlyRef.Invoke(localPlayer) = flag;
				Character.m_debugFlySpeed = (int)ModConfig.FlySpeed.Value;
				ZNetView val = NviewRef.Invoke((Character)(object)localPlayer);
				if ((Object)(object)val != (Object)null && val.GetZDO() != null)
				{
					val.GetZDO().Set(ZDOVars.s_debugFly, flag);
				}
			}
			ApplyNightVisionState(flag);
			Notify("Все функции", flag);
		}

		public static void UpdatePerFrame()
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if (ModConfig.GodModeEnabled)
			{
				GodModeRef.Invoke(localPlayer) = true;
				if (((Character)localPlayer).GetHealth() < ((Character)localPlayer).GetMaxHealth())
				{
					((Character)localPlayer).SetHealth(((Character)localPlayer).GetMaxHealth());
				}
			}
			if (ModConfig.InfiniteStaminaEnabled)
			{
				StaminaRef.Invoke(localPlayer) = ((Character)localPlayer).GetMaxStamina();
			}
			if (ModConfig.FreeBuildEnabled && !NoPlacementCostRef.Invoke(localPlayer))
			{
				localPlayer.SetNoPlacementCost(true);
			}
			if (ModConfig.FlyEnabled)
			{
				if (!DebugFlyRef.Invoke(localPlayer))
				{
					DebugFlyRef.Invoke(localPlayer) = true;
				}
				Character.m_debugFlySpeed = (int)ModConfig.FlySpeed.Value;
			}
			if (ModConfig.NightVisionEnabled)
			{
				if ((Object)(object)EnvMan.instance != (Object)null)
				{
					EnvMan.instance.m_debugTimeOfDay = true;
					EnvMan.instance.m_debugTime = 0.5f;
				}
				Camera val = Camera.main ?? (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).GetComponent<Camera>() : null);
				if ((Object)(object)val != (Object)null && (Object)(object)_nightVisionLightObj != (Object)null && _nightVisionLightObj.activeSelf)
				{
					_nightVisionLightObj.transform.position = ((Component)val).transform.position + ((Component)val).transform.forward * 1.5f;
				}
			}
		}

		private static void ApplyNightVisionState(bool enabled)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)EnvMan.instance != (Object)null)
			{
				EnvMan.instance.m_debugTimeOfDay = enabled;
				if (enabled)
				{
					EnvMan.instance.m_debugTime = 0.5f;
				}
			}
			if (enabled)
			{
				if ((Object)(object)_nightVisionLightObj == (Object)null)
				{
					_nightVisionLightObj = new GameObject("ValheimCheats_NightVisionLight");
					_nightVisionLight = _nightVisionLightObj.AddComponent<Light>();
					_nightVisionLight.type = (LightType)2;
					_nightVisionLight.range = ModConfig.NightVisionLightRange.Value;
					_nightVisionLight.intensity = ModConfig.NightVisionLightIntensity.Value;
					_nightVisionLight.color = new Color(0.95f, 0.95f, 1f);
					_nightVisionLight.shadows = (LightShadows)0;
					Object.DontDestroyOnLoad((Object)(object)_nightVisionLightObj);
				}
				_nightVisionLightObj.SetActive(true);
			}
			else if ((Object)(object)_nightVisionLightObj != (Object)null)
			{
				_nightVisionLightObj.SetActive(false);
			}
		}

		public static void Notify(string cheatName, bool enabled)
		{
			if (ModConfig.ShowNotifications.Value)
			{
				string text = (enabled ? "<color=#00FF00>ВКЛЮЧЕНО</color>" : "<color=#FF4444>ВЫКЛЮЧЕНО</color>");
				string text2 = "[ValheimCheats] " + cheatName + ": " + text;
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					((Character)Player.m_localPlayer).Message((MessageType)1, text2, 0, (Sprite)null, false);
				}
				else
				{
					Plugin.Log.LogInfo((object)text2);
				}
			}
		}
	}
	public static class ModConfig
	{
		public static ConfigEntry<KeyCode> KeyToggleMenu { get; private set; }

		public static ConfigEntry<KeyCode> KeyToggleHud { get; private set; }

		public static ConfigEntry<KeyCode> KeyToggleGodMode { get; private set; }

		public static ConfigEntry<KeyCode> KeyToggleStamina { get; private set; }

		public static ConfigEntry<KeyCode> KeyToggleFreeBuild { get; private set; }

		public static ConfigEntry<KeyCode> KeyToggleFly { get; private set; }

		public static ConfigEntry<KeyCode> KeyToggleNightVision { get; private set; }

		public static ConfigEntry<KeyCode> KeyToggleAll { get; private set; }

		public static ConfigEntry<float> FlySpeed { get; private set; }

		public static ConfigEntry<float> FlyFastMultiplier { get; private set; }

		public static ConfigEntry<float> NightVisionLightIntensity { get; private set; }

		public static ConfigEntry<float> NightVisionLightRange { get; private set; }

		public static ConfigEntry<bool> ShowMenuOnStart { get; private set; }

		public static ConfigEntry<bool> ShowStatusOverlay { get; private set; }

		public static ConfigEntry<bool> ShowNotifications { get; private set; }

		public static bool GodModeEnabled { get; set; }

		public static bool InfiniteStaminaEnabled { get; set; }

		public static bool FreeBuildEnabled { get; set; }

		public static bool FlyEnabled { get; set; }

		public static bool NightVisionEnabled { get; set; }

		public static void Init(ConfigFile config)
		{
			KeyToggleMenu = config.Bind<KeyCode>("Hotkeys", "ToggleMenuKey", (KeyCode)286, "Клавиша открытия/закрытия графического меню чита");
			KeyToggleHud = config.Bind<KeyCode>("Hotkeys", "ToggleHudKey", (KeyCode)285, "Клавиша скрытия/отображения HUD оверлея статуса");
			KeyToggleGodMode = config.Bind<KeyCode>("Hotkeys", "ToggleGodModeKey", (KeyCode)287, "Клавиша включения/выключения Бессмертия (God Mode / ХП)");
			KeyToggleStamina = config.Bind<KeyCode>("Hotkeys", "ToggleStaminaKey", (KeyCode)288, "Клавиша включения/выключения Бесконечной стамины");
			KeyToggleFreeBuild = config.Bind<KeyCode>("Hotkeys", "ToggleFreeBuildKey", (KeyCode)289, "Клавиша включения/выключения Бесплатного строительства");
			KeyToggleFly = config.Bind<KeyCode>("Hotkeys", "ToggleFlyKey", (KeyCode)290, "Клавиша включения/выключения Полёта (Fly Mode)");
			KeyToggleNightVision = config.Bind<KeyCode>("Hotkeys", "ToggleNightVisionKey", (KeyCode)291, "Клавиша включения/выключения Ночного зрения (светло как днем)");
			KeyToggleAll = config.Bind<KeyCode>("Hotkeys", "ToggleAllKey", (KeyCode)292, "Клавиша переключения всех функций чита сразу");
			FlySpeed = config.Bind<float>("FlySettings", "FlySpeed", 20f, "Базовая скорость полёта");
			FlyFastMultiplier = config.Bind<float>("FlySettings", "FlyFastMultiplier", 2.5f, "Множитель скорости полёта при зажатом Shift");
			NightVisionLightIntensity = config.Bind<float>("NightVisionSettings", "LightIntensity", 1.3f, "Интенсивность дополнительного источника света ночного зрения");
			NightVisionLightRange = config.Bind<float>("NightVisionSettings", "LightRange", 80f, "Радиус освещения ночного зрения");
			ShowMenuOnStart = config.Bind<bool>("UI", "ShowMenuOnStart", false, "Показывать ли меню чита сразу при старте игры");
			ShowStatusOverlay = config.Bind<bool>("UI", "ShowStatusOverlay", true, "Отображать ли статус функций в левом верхнем углу экрана");
			ShowNotifications = config.Bind<bool>("UI", "ShowNotifications", true, "Показывать ли текстовые уведомления в игре при переключении функций");
		}
	}
	[BepInPlugin("com.maxim.valheimcheats", "ValheimCheats", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.maxim.valheimcheats";

		public const string ModName = "ValheimCheats";

		public const string ModVersion = "1.0.0";

		private Harmony _harmony;

		public static ManualLogSource Log { get; private set; }

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("com.maxim.valheimcheats");
			_harmony.PatchAll();
			((Component)this).gameObject.AddComponent<CheatMenuUI>();
			Log.LogInfo((object)"ValheimCheats v1.0.0 успешно загружен! Работает на клиенте и любых серверах.");
		}

		private void Update()
		{
			//IL_0005: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0089: 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)
			if (Input.GetKeyDown(ModConfig.KeyToggleHud.Value))
			{
				CheatMenuUI.ToggleHud();
			}
			if (Input.GetKeyDown(ModConfig.KeyToggleMenu.Value))
			{
				CheatMenuUI.ToggleMenu();
			}
			if (Input.GetKeyDown(ModConfig.KeyToggleGodMode.Value))
			{
				CheatsManager.ToggleGodMode();
			}
			if (Input.GetKeyDown(ModConfig.KeyToggleStamina.Value))
			{
				CheatsManager.ToggleStamina();
			}
			if (Input.GetKeyDown(ModConfig.KeyToggleFreeBuild.Value))
			{
				CheatsManager.ToggleFreeBuild();
			}
			if (Input.GetKeyDown(ModConfig.KeyToggleFly.Value))
			{
				CheatsManager.ToggleFly();
			}
			if (Input.GetKeyDown(ModConfig.KeyToggleNightVision.Value))
			{
				CheatsManager.ToggleNightVision();
			}
			if (Input.GetKeyDown(ModConfig.KeyToggleAll.Value))
			{
				CheatsManager.ToggleAll();
			}
			CheatsManager.UpdatePerFrame();
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace ValheimCheats.UI
{
	public class CheatMenuUI : MonoBehaviour
	{
		private static bool _showMenu = false;

		private static Rect _windowRect = new Rect(40f, 60f, 360f, 520f);

		private static GUIStyle _headerStyle;

		private static GUIStyle _buttonActiveStyle;

		private static GUIStyle _buttonInactiveStyle;

		private static GUIStyle _overlayLabelStyle;

		private static Texture2D _activeBgTexture;

		private static Texture2D _inactiveBgTexture;

		public static void ToggleMenu()
		{
			_showMenu = !_showMenu;
		}

		public static void ToggleHud()
		{
			ModConfig.ShowStatusOverlay.Value = !ModConfig.ShowStatusOverlay.Value;
			if ((Object)(object)Player.m_localPlayer != (Object)null && ModConfig.ShowNotifications.Value)
			{
				string text = (ModConfig.ShowStatusOverlay.Value ? "<color=#00FF00>ОТОБРАЖАЕТСЯ</color>" : "<color=#FF4444>СКРЫТ</color>");
				((Character)Player.m_localPlayer).Message((MessageType)1, "[ValheimCheats] HUD статуса: " + text, 0, (Sprite)null, false);
			}
		}

		private void Awake()
		{
			_showMenu = ModConfig.ShowMenuOnStart.Value;
		}

		private void OnGUI()
		{
			//IL_0024: 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_003f: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			InitStyles();
			if (ModConfig.ShowStatusOverlay.Value)
			{
				DrawStatusOverlay();
			}
			if (_showMenu)
			{
				_windowRect = GUI.Window(987654, _windowRect, new WindowFunction(DrawWindow), "⚔\ufe0f Valheim Cheats [Клиентский Мод] ⚔\ufe0f");
			}
		}

		private void DrawStatusOverlay()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			float num = 15f;
			float num2 = 310f;
			float num3 = 155f;
			GUI.Box(new Rect(15f - 5f, num - 5f, num2 + 10f, num3), GUIContent.none);
			GUILayout.BeginArea(new Rect(15f, num, num2, num3));
			GUILayout.Label($"<b>Valheim Cheats</b> <size=11>({ModConfig.KeyToggleHud.Value} - Скрыть | {ModConfig.KeyToggleMenu.Value} - Меню)</size>", _overlayLabelStyle, Array.Empty<GUILayoutOption>());
			DrawOverlayRow($"[{ModConfig.KeyToggleGodMode.Value}] Бессмертие (HP)", ModConfig.GodModeEnabled);
			DrawOverlayRow($"[{ModConfig.KeyToggleStamina.Value}] Выносливость", ModConfig.InfiniteStaminaEnabled);
			DrawOverlayRow($"[{ModConfig.KeyToggleFreeBuild.Value}] Бесплатная стройка", ModConfig.FreeBuildEnabled);
			DrawOverlayRow($"[{ModConfig.KeyToggleFly.Value}] Полёт (Fly)", ModConfig.FlyEnabled);
			DrawOverlayRow($"[{ModConfig.KeyToggleNightVision.Value}] Ночное зрение", ModConfig.NightVisionEnabled);
			GUILayout.EndArea();
		}

		private void DrawOverlayRow(string title, bool active)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(title, _overlayLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(220f) });
			GUILayout.Label(active ? "<color=#00FF66>● ВКЛ</color>" : "<color=#FF4444>○ ВЫКЛ</color>", _overlayLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
		}

		private void DrawWindow(int windowId)
		{
			//IL_003d: 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_0093: 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_00e9: 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)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.Label("Управление функциями (Горячие клавиши):", _headerStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			if (DrawCheatButton($"[{ModConfig.KeyToggleGodMode.Value}] Бессмертие (God Mode)", ModConfig.GodModeEnabled))
			{
				CheatsManager.ToggleGodMode();
			}
			if (DrawCheatButton($"[{ModConfig.KeyToggleStamina.Value}] Бесконечная стамина", ModConfig.InfiniteStaminaEnabled))
			{
				CheatsManager.ToggleStamina();
			}
			if (DrawCheatButton($"[{ModConfig.KeyToggleFreeBuild.Value}] Бесплатное строительство", ModConfig.FreeBuildEnabled))
			{
				CheatsManager.ToggleFreeBuild();
			}
			if (DrawCheatButton($"[{ModConfig.KeyToggleFly.Value}] Режим полёта (Fly Mode)", ModConfig.FlyEnabled))
			{
				CheatsManager.ToggleFly();
			}
			if (DrawCheatButton($"[{ModConfig.KeyToggleNightVision.Value}] Ночное зрение (День ночью)", ModConfig.NightVisionEnabled))
			{
				CheatsManager.ToggleNightVision();
			}
			GUILayout.Space(5f);
			if (GUILayout.Button($"[{ModConfig.KeyToggleAll.Value}] ⚡ ПЕРЕКЛЮЧИТЬ ВСЁ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				CheatsManager.ToggleAll();
			}
			GUILayout.Space(5f);
			if (GUILayout.Button(ModConfig.ShowStatusOverlay.Value ? $"\ud83d\udc41\ufe0f HUD в углу экрана: [ВКЛЮЧЁН] (нажмите {ModConfig.KeyToggleHud.Value} чтобы скрыть)" : $"\ud83d\udc41\ufe0f HUD в углу экрана: [СКРЫТ] (нажмите {ModConfig.KeyToggleHud.Value} чтобы показать)", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				ToggleHud();
			}
			GUILayout.Space(8f);
			GUILayout.Label($"Скорость полёта: {ModConfig.FlySpeed.Value:F0}", _headerStyle, Array.Empty<GUILayoutOption>());
			ModConfig.FlySpeed.Value = GUILayout.HorizontalSlider(ModConfig.FlySpeed.Value, 5f, 100f, Array.Empty<GUILayoutOption>());
			if (Character.m_debugFlySpeed > 0 && ModConfig.FlyEnabled)
			{
				Character.m_debugFlySpeed = (int)ModConfig.FlySpeed.Value;
			}
			GUILayout.Space(8f);
			GUILayout.Label("<size=11>Управление полётом:\n • Пробел — вверх\n • LCtrl — вниз\n • Shift — ускорение в 2.5x\nРаботает на любых серверах!</size>", _overlayLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Закрыть меню (F5)", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
			{
				_showMenu = false;
			}
			GUILayout.EndVertical();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 25f));
		}

		private bool DrawCheatButton(string label, bool active)
		{
			GUIStyle val = (active ? _buttonActiveStyle : _buttonInactiveStyle);
			return GUILayout.Button(active ? ("✔ " + label + " [ВКЛ]") : ("✖ " + label + " [ВЫКЛ]"), val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
		}

		private void InitStyles()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			if (_headerStyle == null)
			{
				_headerStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 12,
					fontStyle = (FontStyle)1
				};
				_headerStyle.normal.textColor = Color.yellow;
				_overlayLabelStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 12,
					richText = true
				};
				_overlayLabelStyle.normal.textColor = Color.white;
				_activeBgTexture = MakeSolidTexture(2, 2, new Color(0.1f, 0.45f, 0.15f, 0.9f));
				_inactiveBgTexture = MakeSolidTexture(2, 2, new Color(0.25f, 0.25f, 0.25f, 0.9f));
				_buttonActiveStyle = new GUIStyle(GUI.skin.button)
				{
					fontSize = 12,
					fontStyle = (FontStyle)1
				};
				_buttonActiveStyle.normal.background = _activeBgTexture;
				_buttonActiveStyle.normal.textColor = Color.green;
				_buttonInactiveStyle = new GUIStyle(GUI.skin.button)
				{
					fontSize = 12
				};
				_buttonInactiveStyle.normal.background = _inactiveBgTexture;
				_buttonInactiveStyle.normal.textColor = new Color(0.85f, 0.85f, 0.85f);
			}
		}

		private Texture2D MakeSolidTexture(int width, int height, Color col)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = col;
			}
			Texture2D val = new Texture2D(width, height);
			val.SetPixels(array);
			val.Apply();
			return val;
		}
	}
}
namespace ValheimCheats.Patches
{
	[HarmonyPatch]
	public static class FlyPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "IsDebugFlying")]
		public static bool Player_IsDebugFlying_Prefix(Player __instance, ref bool __result)
		{
			if (ModConfig.FlyEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "IsDebugFlying")]
		public static bool Character_IsDebugFlying_Prefix(Character __instance, ref bool __result)
		{
			if (ModConfig.FlyEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "InDebugFlyMode")]
		public static bool Player_InDebugFlyMode_Prefix(Player __instance, ref bool __result)
		{
			if (ModConfig.FlyEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	public static class FreeBuildPatches
	{
		private static readonly FieldRef<Player, PlacementStatus> PlacementStatusRef = AccessTools.FieldRefAccess<Player, PlacementStatus>("m_placementStatus");

		private static readonly FieldRef<Player, GameObject> PlacementGhostRef = AccessTools.FieldRefAccess<Player, GameObject>("m_placementGhost");

		private static readonly MethodInfo SetPlacementGhostValidMethod = AccessTools.Method(typeof(Player), "SetPlacementGhostValid", new Type[1] { typeof(bool) }, (Type[])null);

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "ConsumeResources")]
		public static bool Player_ConsumeResources_Prefix(Player __instance, Requirement[] requirements, int qualityLevel, int itemQuality, int multiplier)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
		{
			typeof(Piece),
			typeof(RequirementMode)
		})]
		public static bool Player_HaveRequirements_Piece_Prefix(Player __instance, Piece piece, RequirementMode mode, ref bool __result)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
		{
			typeof(Recipe),
			typeof(bool),
			typeof(int),
			typeof(int)
		})]
		public static bool Player_HaveRequirements_Recipe_Prefix(Player __instance, Recipe recipe, bool discover, int qualityLevel, int amount, ref bool __result)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "HaveRequirementItems")]
		public static bool Player_HaveRequirementItems_Prefix(Player __instance, Recipe piece, bool discover, int qualityLevel, int amount, ref bool __result)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "CheckCanRemovePiece")]
		public static bool Player_CheckCanRemovePiece_Prefix(Player __instance, Piece piece, ref bool __result)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "NoCostCheat")]
		public static bool Player_NoCostCheat_Prefix(Player __instance, ref bool __result)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
		public static void Player_UpdatePlacementGhost_Postfix(Player __instance, bool flashGuardStone)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer && (Object)(object)PlacementGhostRef.Invoke(__instance) != (Object)null)
			{
				PlacementStatusRef.Invoke(__instance) = (PlacementStatus)0;
				try
				{
					SetPlacementGhostValidMethod?.Invoke(__instance, new object[1] { true });
				}
				catch (Exception)
				{
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "TryPlacePiece")]
		public static void Player_TryPlacePiece_Prefix(Player __instance, Piece piece)
		{
			if (ModConfig.FreeBuildEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				PlacementStatusRef.Invoke(__instance) = (PlacementStatus)0;
			}
		}
	}
	[HarmonyPatch]
	public static class GodModePatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "ApplyDamage")]
		public static bool Character_ApplyDamage_Prefix(Character __instance, HitData hit)
		{
			if (ModConfig.GodModeEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "Damage")]
		public static bool Character_Damage_Prefix(Character __instance, HitData hit)
		{
			if (ModConfig.GodModeEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "RPC_Damage")]
		public static bool Character_RPC_Damage_Prefix(Character __instance, long sender, HitData hit)
		{
			if (ModConfig.GodModeEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "OnDamaged")]
		public static bool Player_OnDamaged_Prefix(Player __instance, HitData hit)
		{
			if (ModConfig.GodModeEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "DamageArmorDurability")]
		public static bool Character_DamageArmorDurability_Prefix(Character __instance, HitData hit)
		{
			if (ModConfig.GodModeEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "InGodMode")]
		public static bool Character_InGodMode_Prefix(Character __instance, ref bool __result)
		{
			if (ModConfig.GodModeEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "InGodMode")]
		public static bool Player_InGodMode_Prefix(Player __instance, ref bool __result)
		{
			if (ModConfig.GodModeEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	public static class NightVisionPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(EnvMan), "IsNight")]
		public static bool EnvMan_IsNight_Prefix(ref bool __result)
		{
			if (ModConfig.NightVisionEnabled)
			{
				__result = false;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(EnvMan), "IsDay")]
		public static bool EnvMan_IsDay_Prefix(ref bool __result)
		{
			if (ModConfig.NightVisionEnabled)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(EnvMan), "IsDaylight")]
		public static bool EnvMan_IsDaylight_Prefix(ref bool __result)
		{
			if (ModConfig.NightVisionEnabled)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	public static class StaminaPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "UseStamina")]
		public static bool Player_UseStamina_Prefix(Player __instance, float v)
		{
			if (ModConfig.InfiniteStaminaEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "UseStamina")]
		public static bool Character_UseStamina_Prefix(Character __instance, float stamina)
		{
			if (ModConfig.InfiniteStaminaEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "HaveStamina")]
		public static bool Player_HaveStamina_Prefix(Player __instance, float amount, ref bool __result)
		{
			if (ModConfig.InfiniteStaminaEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "HaveStamina")]
		public static bool Character_HaveStamina_Prefix(Character __instance, float amount, ref bool __result)
		{
			if (ModConfig.InfiniteStaminaEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "GetDodgeStaminaUse")]
		public static bool Player_GetDodgeStaminaUse_Prefix(Player __instance, ref float __result)
		{
			if (ModConfig.InfiniteStaminaEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = 0f;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "GetBuildStamina")]
		public static bool Player_GetBuildStamina_Prefix(Player __instance, ref float __result)
		{
			if (ModConfig.InfiniteStaminaEnabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = 0f;
				return false;
			}
			return true;
		}
	}
}