Decompiled source of PEAKChoice v1.0.0

off_grid.PEAKChoice.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("off_grid.PEAKChoice")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PEAKChoice")]
[assembly: AssemblyTitle("off_grid.PEAKChoice")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 PEAKChoice
{
	[BepInPlugin("off_grid.PEAKChoice", "PEAKChoice", "1.0.0")]
	public class PEAKChoice : BaseUnityPlugin
	{
		private static Random rng = new Random();

		internal static Harmony Harmony = new Harmony("off_grid.PEAKChoice");

		public ConfigFile config;

		internal static ConfigEntry<string> ForceMap = null;

		internal static ConfigEntry<int> AlpineChance = null;

		internal static ConfigEntry<int> MesaChance = null;

		internal static string Forced = "Mesa";

		public static PEAKChoice Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		private static string GetTargetBiome()
		{
			switch (ForceMap.Value.ToLower())
			{
			case "mesa":
				return "Mesa";
			case "alpine":
				return "Alpine";
			case "any":
			{
				int num = rng.Next(0, 100);
				if (num < AlpineChance.Value)
				{
					return "Alpine";
				}
				return "Mesa";
			}
			default:
				return "Mesa";
			}
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Logger.LogWarning((object)"< PEAKChoice loading >");
			InitializeConfig();
			Forced = GetTargetBiome();
			Logger.LogWarning((object)("< Forced biome set to: " + Forced + " >"));
			Harmony.PatchAll();
			Logger.LogInfo((object)"off_grid.PEAKChoice v1.0.0 has fully loaded!");
		}

		private void InitializeConfig()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "DAa Mods/PEAKChoice");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string text2 = Path.Combine(text, "config.cfg");
			config = new ConfigFile(text2, true);
			string value = config.Bind<string>("Version", "Current Version", "", (ConfigDescription)null).Value;
			if (value != "1.0.0")
			{
				config.Clear();
				DefineConfig();
			}
			else
			{
				ForceMap = config.Bind<string>("MAP", "ForceMap", "Any", "Map that will be forced: Alpine | Mesa | Any");
				AlpineChance = config.Bind<int>("MAP", "AlpineChance", 50, "Chance for Alpine to appear on Any option.");
				MesaChance = config.Bind<int>("MAP", "MesaChance", 50, "Chance for Mesa to appear on Any option.");
			}
		}

		private void DefineConfig()
		{
			config.Bind<string>("Version", "Current Version", "1.0.0", "Autoupdates the config / lets the mod know what version of config it is.");
			ForceMap = config.Bind<string>("MAP", "ForceMap", "Any", "Map that will be forced: Alpine | Mesa | Any");
			AlpineChance = config.Bind<int>("MAP", "AlpineChance", 50, "Chance for Alpine to appear on Any option.");
			MesaChance = config.Bind<int>("MAP", "MesaChance", 50, "Chance for Mesa to appear on Any option.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "off_grid.PEAKChoice";

		public const string PLUGIN_NAME = "PEAKChoice";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace PEAKChoice.Patches
{
	[HarmonyPatch(typeof(MapHandler))]
	public static class MapHandlerPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("DetectBiomes")]
		private static bool DetectBiomes_Prefix(MapHandler __instance)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Invalid comparison between Unknown and I4
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Invalid comparison between Unknown and I4
			__instance.biomes.Clear();
			GameObject val = GameObject.Find("Map/Biome_3/Snow");
			GameObject val2 = GameObject.Find("Map/Biome_3/Desert");
			if (PEAKChoice.Forced == "Mesa")
			{
				if ((Object)(object)val != (Object)null)
				{
					val.SetActive(false);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetActive(true);
				}
				foreach (object item in val.transform)
				{
					((Component)(Transform)item).gameObject.SetActive(false);
				}
			}
			else if (PEAKChoice.Forced == "Alpine")
			{
				if ((Object)(object)val != (Object)null)
				{
					val.SetActive(true);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetActive(false);
				}
				foreach (object item2 in val2.transform)
				{
					((Component)(Transform)item2).gameObject.SetActive(false);
				}
			}
			Biome val3 = default(Biome);
			for (int i = 0; i < ((Component)__instance).transform.childCount; i++)
			{
				Transform child = ((Component)__instance).transform.GetChild(i);
				for (int j = 0; j < child.childCount; j++)
				{
					if (((Component)child.GetChild(j)).TryGetComponent<Biome>(ref val3))
					{
						if (PEAKChoice.Forced == "Mesa" && (int)val3.biomeType == 2)
						{
							__instance.biomes.Add((BiomeType)6);
							PEAKChoice.Logger.LogInfo((object)"Forced Mesa");
						}
						else if (PEAKChoice.Forced == "Alpine" && (int)val3.biomeType == 6)
						{
							__instance.biomes.Add((BiomeType)2);
							PEAKChoice.Logger.LogInfo((object)"Forced Alpine");
						}
						else
						{
							__instance.biomes.Add(val3.biomeType);
							PEAKChoice.Logger.LogInfo((object)("Added: " + ((Object)val3).name));
						}
					}
				}
			}
			PEAKChoice.Logger.LogWarning((object)"< Patched - DetectBiomes >");
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Awake_Postfix(MapHandler __instance)
		{
			typeof(MapHandler).GetMethod("DetectBiomes", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(__instance, null);
			PEAKChoice.Logger.LogInfo((object)"< Ran DetectBiomes() >");
			PEAKChoice.Logger.LogWarning((object)"< Patched - Awake >");
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static IEnumerator Start_Postfix(IEnumerator __result, MapHandler __instance)
		{
			yield return __result;
			for (int i = 1; i < __instance.segments.Length; i++)
			{
				MapSegment val = __instance.segments[i];
				if (PEAKChoice.Forced == "Mesa" && (int)val.biome == 2)
				{
					val.variantBiome = (BiomeType)6;
					val.hasVariant = false;
					PEAKChoice.Logger.LogInfo((object)$"Forced segment {i} variant to Mesa");
				}
				else if (PEAKChoice.Forced == "Alpine" && (int)val.biome == 6)
				{
					val.variantBiome = (BiomeType)2;
					val.hasVariant = false;
					PEAKChoice.Logger.LogInfo((object)$"Forced segment {i} variant to Alpine");
				}
			}
			PEAKChoice.Logger.LogWarning((object)"< Patched - Start >");
		}
	}
}
namespace CWMissing.Features.Global
{
	public interface IWrapper<T>
	{
		T Base { get; }
	}
	public interface IWorldSpace
	{
		Vector3 Position { get; }

		Quaternion Rotation { get; }
	}
	public interface IDeniableEvent
	{
		bool IsAllowed { get; set; }
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}