Decompiled source of BiomeConqueror v1.0.1

BiomeConqueror.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BiomeConqueror")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BiomeConqueror")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("69445434-75c1-4c5a-ac41-b01dc8b00a95")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BiomeConqueror;

[BepInPlugin("Turbero.BiomeConqueror", "Biome Conqueror", "1.0.1")]
public class BiomeConqueror : BaseUnityPlugin
{
	public const string GUID = "Turbero.BiomeConqueror";

	public const string NAME = "Biome Conqueror";

	public const string VERSION = "1.0.1";

	private readonly Harmony harmony = new Harmony("Turbero.BiomeConqueror");

	private void Awake()
	{
		ConfigurationFile.LoadConfig((BaseUnityPlugin)(object)this);
		harmony.PatchAll();
	}

	private void onDestroy()
	{
		harmony.UnpatchSelf();
	}
}
[HarmonyPatch(typeof(Character), "OnDeath")]
public class CharacterDeathPatch
{
	private static void Postfix(Character __instance)
	{
		if (!ConfigurationFile.modEnabled.Value || !((Object)(object)__instance != (Object)null) || !__instance.IsBoss())
		{
			return;
		}
		if (__instance.m_name == "$enemy_bonemass")
		{
			((Humanoid)Player.m_localPlayer).AddUniqueKey("BonemassDefeated");
			Logger.Log("** Bonemass defeated");
		}
		else if (__instance.m_name == "$enemy_dragon")
		{
			((Humanoid)Player.m_localPlayer).AddUniqueKey("ModerDefeated");
			Logger.Log("** Moder defeated");
		}
		else if (__instance.m_name == "$enemy_seekerqueen")
		{
			((Humanoid)Player.m_localPlayer).AddUniqueKey("QueenDefeated");
			Logger.Log("** Queen defeated");
			ItemData val = ((IEnumerable<ItemData>)((Humanoid)Player.m_localPlayer).GetInventory().GetEquippedItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => ((Object)i.m_dropPrefab).name == "Demister"));
			if (val != null)
			{
				((Humanoid)Player.m_localPlayer).UnequipItem(val, true);
				((Humanoid)Player.m_localPlayer).EquipItem(val, true);
			}
		}
	}
}
public class BiomeConquerorUtils
{
	public static bool hasUniqueKey(string key, bool configValue)
	{
		return ConfigurationFile.modEnabled.Value && configValue && ((Humanoid)Player.m_localPlayer).HaveUniqueKey(key);
	}

	public static bool hasGlobalKey(string key)
	{
		return ConfigurationFile.modEnabled.Value && ConfigurationFile.worldProgression.Value && ZoneSystem.instance.GetGlobalKey(key);
	}
}
internal class ConfigurationFile
{
	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<bool> debug;

	public static ConfigEntry<bool> worldProgression;

	public static ConfigEntry<bool> bonemassBenefitEnabled;

	public static ConfigEntry<bool> moderBenefitEnabled;

	public static ConfigEntry<bool> queenBenefitEnabled;

	public static ConfigEntry<float> queenBenefitRange;

	private static ConfigFile config;

	internal static void LoadConfig(BaseUnityPlugin plugin)
	{
		config = plugin.Config;
		modEnabled = config.Bind<bool>("1 - General", "Enabled", true, "Enabling/Disabling the mod (default = true)");
		debug = config.Bind<bool>("1 - General", "DebugMode", false, "Enabling/Disabling the debugging in the console (default = false)");
		worldProgression = config.Bind<bool>("1 - General", "WorldProgression", false, "Enabling/Disabling the benefits with the world progression (default = false, which is by player personal battle wins)");
		bonemassBenefitEnabled = config.Bind<bool>("2 - Victories", "BonemassBenefitEnabled", true, "Stops getting wet by rain in all swamps after killing Bonemass (default = true)");
		moderBenefitEnabled = config.Bind<bool>("2 - Victories", "ModerBenefitEnabled", true, "Stops freezing without protection effects in all mountains after killing Moder (default = true)");
		queenBenefitEnabled = config.Bind<bool>("2 - Victories", "QueenBenefitEnabled", true, "Increases the wisp light range after killing The Seeker Queen (default = true)");
		queenBenefitRange = config.Bind<float>("2 - Victories", "QueenBenefitRange", 100f, "Establishes the new wisp light range after killing The Seeker Queen (default = true)");
		worldProgression.SettingChanged += QueenBenefitRange_SettingChanged;
		queenBenefitRange.SettingChanged += QueenBenefitRange_SettingChanged;
	}

	private static void QueenBenefitRange_SettingChanged(object sender, EventArgs e)
	{
		ItemData val = ((IEnumerable<ItemData>)((Humanoid)Player.m_localPlayer).GetInventory().GetEquippedItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => ((Object)i.m_dropPrefab).name == "Demister"));
		if (val != null)
		{
			((Humanoid)Player.m_localPlayer).UnequipItem(val, true);
			((Humanoid)Player.m_localPlayer).EquipItem(val, true);
		}
	}
}
public static class Logger
{
	internal static void Log(object s)
	{
		if (ConfigurationFile.debug.Value)
		{
			string text = "Biome Conqueror 1.0.1: " + ((s != null) ? s.ToString() : "null");
			Debug.Log((object)text);
		}
	}

	internal static void LogWarning(object s)
	{
		string text = "Biome Conqueror 1.0.1: " + ((s != null) ? s.ToString() : "null");
		Debug.LogWarning((object)text);
	}

	internal static void LogError(object s)
	{
		string text = "Biome Conqueror 1.0.1: " + ((s != null) ? s.ToString() : "null");
		Debug.LogError((object)text);
	}
}
[HarmonyPatch]
public class MistlandsPatch
{
	private static MethodBase TargetMethod()
	{
		return AccessTools.Method(typeof(Demister), "OnEnable", (Type[])null, (Type[])null);
	}

	private static void Postfix(ref Demister __instance)
	{
		if (!ConfigurationFile.modEnabled.Value)
		{
			return;
		}
		try
		{
			if (BiomeConquerorUtils.hasUniqueKey("QueenDefeated", ConfigurationFile.queenBenefitEnabled.Value) || BiomeConquerorUtils.hasGlobalKey("defeated_queen"))
			{
				ItemData val = ((IEnumerable<ItemData>)((Humanoid)Player.m_localPlayer).GetInventory().GetEquippedItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => ((Object)i.m_dropPrefab).name == "Demister"));
				if (((Behaviour)__instance).isActiveAndEnabled && val != null)
				{
					__instance.m_forceField.endRange = ConfigurationFile.queenBenefitRange.Value;
				}
			}
		}
		catch (Exception)
		{
		}
	}
}
[HarmonyPatch(typeof(EnvMan), "UpdateEnvironment")]
public class WeatherPatch
{
	private static void Prefix(EnvMan __instance)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Invalid comparison between Unknown and I4
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Invalid comparison between Unknown and I4
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer != (Object)null))
		{
			return;
		}
		if ((int)localPlayer.GetCurrentBiome() == 2)
		{
			if (BiomeConquerorUtils.hasUniqueKey("BonemassDefeated", ConfigurationFile.bonemassBenefitEnabled.Value) || BiomeConquerorUtils.hasGlobalKey("defeated_bonemass"))
			{
				__instance.GetCurrentEnvironment().m_isWet = false;
				if (((Character)Player.m_localPlayer).GetSEMan().HaveStatusEffect("Wet".GetHashCode()))
				{
					((Character)Player.m_localPlayer).GetSEMan().RemoveStatusEffect("Wet".GetHashCode(), false);
				}
			}
			else
			{
				__instance.GetCurrentEnvironment().m_isWet = true;
			}
		}
		else if ((int)localPlayer.GetCurrentBiome() == 4)
		{
			if (BiomeConquerorUtils.hasUniqueKey("ModerDefeated", ConfigurationFile.moderBenefitEnabled.Value) || BiomeConquerorUtils.hasGlobalKey("defeated_dragon"))
			{
				__instance.GetCurrentEnvironment().m_isFreezing = false;
				__instance.GetCurrentEnvironment().m_isFreezingAtNight = false;
			}
			else
			{
				__instance.GetCurrentEnvironment().m_isFreezing = true;
				__instance.GetCurrentEnvironment().m_isFreezingAtNight = true;
			}
		}
	}
}