Decompiled source of RandomStartWK v0.0.2

RandomStartWK.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RandomStartWK")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("RandomStartWK Description")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+99b52f50818a91cbfe0b7eab0b4650a046a411ae")]
[assembly: AssemblyProduct("RandomStartWK")]
[assembly: AssemblyTitle("RandomStartWK")]
[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 RandomStartWK
{
	[BepInPlugin("Slayer6409.RandomStartWK", "RandomStartWK", "0.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		private readonly Harmony harmony = new Harmony("Slayer6409.RandomStartWK");

		public static ConfigFile BepInExConfig;

		public static ConfigEntry<int> minTrinketsGiven;

		public static ConfigEntry<int> maxTrinketsGiven;

		public static ConfigEntry<bool> trinketAsJustPerk;

		public static ConfigEntry<bool> perksOutnumberBindings;

		public static ConfigEntry<int> minBindingsGiven;

		public static ConfigEntry<int> maxBindingsGiven;

		public static Dictionary<Perk, ConfigEntry<bool>> enabledTrinkets = new Dictionary<Perk, ConfigEntry<bool>>();

		public static Dictionary<Perk, ConfigEntry<bool>> enabledBindings = new Dictionary<Perk, ConfigEntry<bool>>();

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			BepInExConfig = ((BaseUnityPlugin)this).Config;
			doNormalConfig();
			harmony.PatchAll();
			Log.LogInfo((object)"Plugin RandomStartWK is loaded!");
		}

		public void doNormalConfig()
		{
			minTrinketsGiven = BepInExConfig.Bind<int>("Trinkets", "MinTrinkets", 0, "The minimum amount of trinkets");
			maxTrinketsGiven = BepInExConfig.Bind<int>("Trinkets", "MaxTrinkets", 3, "The maximum amount of trinkets");
			trinketAsJustPerk = BepInExConfig.Bind<bool>("Trinkets", "JustPerk", false, "Makes the trinkets it gives you just the perk and not the item");
			perksOutnumberBindings = BepInExConfig.Bind<bool>("Trinkets", "Trinket binding Rule", true, "Limits random trinkets using the normal starting rule: 1 trinket is free, and each binding allows 1 additional trinket.");
			minBindingsGiven = BepInExConfig.Bind<int>("Bindings", "MinBindings", 0, "The minimum amount of Bindings");
			maxBindingsGiven = BepInExConfig.Bind<int>("Bindings", "MaxBindings", 3, "The maximum amount of Bindings");
		}
	}
	public class RandomStartGamemode : GamemodeSetting
	{
		public RandomStartGamemode()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			base.id = "RandomStart";
			base.title = "Random Start";
			base.description = "Randmizes perks and bindings";
			base.color = Color.magenta;
			base.exclusiveSettings = new List<string> { "competetive" };
			base.nameAppend = "";
			base.leaderboardAppendID = "";
			base.allowDownstream = false;
			base.downstreamId = "";
		}

		public void Initialize()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			base.id = "RandomStart";
			base.title = "Random Start";
			base.description = "Randomizes perks and bindings";
			base.color = Color.magenta;
			base.exclusiveSettings = new List<string> { "competetive" };
			base.nameAppend = "";
			base.leaderboardAppendID = "";
			base.allowDownstream = false;
			base.downstreamId = "";
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RandomStartWK";

		public const string PLUGIN_NAME = "RandomStartWK";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace RandomStartWK.Patches
{
	[HarmonyPatch(typeof(CL_GameManager), "Start")]
	internal static class GameManagerStartPatch
	{
		private static bool configSetup;

		private static void Postfix(CL_GameManager __instance)
		{
			M_Gamemode baseGamemode = CL_GameManager.GetBaseGamemode();
			doConfigStuff();
			if (!((Object)(object)baseGamemode == (Object)null) && baseGamemode.HasActiveSetting("RandomStart") && !CL_SaveManager.IsInSavedRun())
			{
				doStartStuff();
			}
		}

		public static void doConfigStuff()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_004b: Invalid comparison between Unknown and I4
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Invalid comparison between Unknown and I4
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Invalid comparison between Unknown and I4
			if (configSetup)
			{
				return;
			}
			foreach (Perk perkAsset in CL_AssetManager.GetFullCombinedAssetDatabase().perkAssets)
			{
				if ((Object)(object)perkAsset == (Object)null)
				{
					continue;
				}
				PerkType perkType = perkAsset.perkType;
				if (perkType - 8 <= 1)
				{
					ConfigEntry<bool> value = Plugin.BepInExConfig.Bind<bool>(((int)perkAsset.perkType == 9) ? "Bindings" : "Trinkets", perkAsset.id, true, $"If the {perkAsset.perkType}: {perkAsset.title} should be in the random pool");
					if ((int)perkAsset.perkType == 8)
					{
						Plugin.enabledTrinkets.Add(perkAsset, value);
					}
					else
					{
						Plugin.enabledBindings.Add(perkAsset, value);
					}
				}
			}
			configSetup = true;
			Plugin.BepInExConfig.Save();
		}

		private static void doStartStuff()
		{
			ENT_Player player = ENT_Player.GetPlayer();
			Inventory inventory = ENT_Player.GetInventory();
			if (!((Object)(object)inventory == (Object)null) && !((Object)(object)player == (Object)null))
			{
				int num = Random.Range(Plugin.minTrinketsGiven.Value, Plugin.maxTrinketsGiven.Value + 1);
				int num2 = Random.Range(Plugin.minBindingsGiven.Value, Plugin.maxBindingsGiven.Value + 1);
				if (Plugin.perksOutnumberBindings.Value)
				{
					int num3 = num2 + 1;
					num = Mathf.Min(num, num3);
				}
				for (int i = 0; i < num; i++)
				{
					giveRandomTrinket(inventory, player);
				}
				for (int j = 0; j < num2; j++)
				{
					giveRandomBinding(player);
				}
			}
		}

		public static void giveRandomTrinket(Inventory inv, ENT_Player player)
		{
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			List<Perk> list = (from x in Plugin.enabledTrinkets
				where x.Value.Value
				select x.Key).ToList();
			Perk perk = list[Random.Range(0, list.Count)];
			if (Plugin.trinketAsJustPerk.Value)
			{
				player.AddPerk(perk, 1, true);
			}
			else
			{
				Item_Object val = null;
				WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
				foreach (GameObject itemPrefab in fullCombinedAssetDatabase.itemPrefabs)
				{
					if ((Object)(object)itemPrefab == (Object)null)
					{
						continue;
					}
					Item_Object component = itemPrefab.GetComponent<Item_Object>();
					if ((Object)(object)component == (Object)null || component.itemData == null || component.itemData.executionModules == null)
					{
						continue;
					}
					foreach (ItemExecutionModule executionModule in component.itemData.executionModules)
					{
						ItemExecutionModule_PerkAdder val2 = (ItemExecutionModule_PerkAdder)(object)((executionModule is ItemExecutionModule_PerkAdder) ? executionModule : null);
						if (val2 != null && val2.GetPerks != null && val2.GetPerks.Any((Perk p) => (Object)(object)p != (Object)null && p.id == perk.id))
						{
							val = component;
						}
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				inv.AddItemToInventoryScreen(Vector3.zero, val.itemData.GetClone((Item)null, false), false, false, true);
			}
			Plugin.Log.LogInfo((object)("Giving trinket: " + perk.title));
		}

		public static void giveRandomBinding(ENT_Player player)
		{
			List<Perk> list = (from x in Plugin.enabledBindings
				where x.Value.Value
				select x.Key).ToList();
			Perk val = list[Random.Range(0, list.Count)];
			player.AddPerk(val, 1, true);
			Plugin.Log.LogInfo((object)("Giving trinket: " + val.title));
		}
	}
	[HarmonyPatch(typeof(UI_GamemodeScreen_Panel), "FillSettings")]
	public class FillSettings
	{
		private static RandomStartGamemode randomizeSetting;

		private static void Prefix(UI_GamemodeScreen_Panel __instance)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)randomizeSetting == (Object)null)
			{
				randomizeSetting = ScriptableObject.CreateInstance<RandomStartGamemode>();
				((GamemodeSetting)randomizeSetting).id = "RandomStart";
				((GamemodeSetting)randomizeSetting).title = "Random Start";
				((GamemodeSetting)randomizeSetting).description = "Randomizes perks and bindings";
				((GamemodeSetting)randomizeSetting).color = Color.magenta;
				((GamemodeSetting)randomizeSetting).exclusiveSettings = new List<string> { "competetive" };
				((GamemodeSetting)randomizeSetting).nameAppend = "";
				((GamemodeSetting)randomizeSetting).leaderboardAppendID = "";
				((GamemodeSetting)randomizeSetting).allowDownstream = false;
				((GamemodeSetting)randomizeSetting).downstreamId = "";
				((GamemodeSetting)randomizeSetting).unlock = ScriptableObject.CreateInstance<ProgressionUnlock>();
				((GamemodeSetting)randomizeSetting).unlock.unlockRequirements = new List<UnlockRequirement>();
			}
			if ((Object)(object)randomizeSetting == (Object)null)
			{
				throw new Exception("Failed to create Random Start setting");
			}
			M_Gamemode gamemode = __instance.GetGamemode();
			if (!((Object)(object)gamemode == (Object)null) && !gamemode.gamemodeSettings.Contains((GamemodeSetting)(object)randomizeSetting))
			{
				gamemode.gamemodeSettings.Add((GamemodeSetting)(object)randomizeSetting);
			}
		}
	}
	[HarmonyPatch(typeof(UI_TrinketPicker), "PopulateTrinkets")]
	internal static class RandomStartDisablePickerPatch
	{
		private static bool Prefix(UI_TrinketPicker __instance, List<Trinket> trinketsToPopulate, Transform root, bool allowInIronKnuckle)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			M_Gamemode val = (((Object)(object)__instance.parentPanel != (Object)null) ? __instance.parentPanel.GetGamemode() : CL_GameManager.GetBaseGamemode());
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			if (!val.HasActiveSetting("RandomStart"))
			{
				return true;
			}
			foreach (Transform item in root)
			{
				Transform val2 = item;
				Object.Destroy((Object)(object)((Component)val2).gameObject);
			}
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}