Decompiled source of SuperRandom v1.0.1

plugins/SuperRandom/SuperRandom.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameplayEntities;
using HarmonyLib;
using LLBML.GameEvents;
using LLBML.Messages;
using LLBML.Players;
using LLBML.Settings;
using LLBML.States;
using LLBML.Utils;
using LLBT;
using LLBT.Tweaks;
using LLGUI;
using LLHandlers;
using LLScreen;
using Microsoft.CodeAnalysis;
using Multiplayer;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("SuperRandom")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+fa62f9817422833339d1990655fe3513792c3f6e")]
[assembly: AssemblyProduct("SuperRandomLLB Mod")]
[assembly: AssemblyTitle("SuperRandom")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SuperRandom
{
	[HarmonyPatch]
	public static class AddPlayersToWorldPatch
	{
		private static void ResetHud(PlayerEntity __instance)
		{
			SuperRandom.Log.LogDebug((object)"Resetting Hud starting");
			GameHudPlayerInfo val = ScreenGameHud.instance.playerInfos[((AbilityEntity)__instance).playerIndex];
			for (int num = ((Component)val).transform.childCount - 1; num >= 0; num--)
			{
				Transform child = ((Component)val).transform.GetChild(num);
				if (((Object)child).name.Contains("Head"))
				{
					Object.Destroy((Object)(object)((Component)child).gameObject);
					break;
				}
			}
			val.SetPlayer(((AbilityEntity)__instance).player, 12);
		}

		public static PlayerEntity ResetNextCharacter(PlayerEntity currentEntity)
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Invalid comparison between Unknown and I4
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Invalid comparison between Unknown and I4
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: 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)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)currentEntity == (Object)null)
			{
				SuperRandom.Log.LogDebug((object)"ResetNextCharacter: currentEntity is null!");
				return null;
			}
			SuperRandom.Log.LogDebug((object)"ResetNextCharacter starting");
			Player val = Player.op_Implicit(((AbilityEntity)currentEntity).player);
			int nr = val.nr;
			SuperRandom.Log.LogDebug((object)$"Player {val.nr} has died");
			PlayerHandler playerHandler = World.instance.playerHandler;
			if (SuperRandomTweak.randomCharacters[val.nr] == null)
			{
				return currentEntity;
			}
			List<Character> list = SuperRandomTweak.randomCharacters[val.nr];
			SuperRandom.Log.LogDebug((object)$"current death count : {currentEntity.playerData.deaths}");
			if (list == null || list.Count == 0)
			{
				SuperRandom.Log.LogDebug((object)$"ResetNextCharacter: entityList for player {val.nr} is null or empty!");
				return currentEntity;
			}
			if ((int)val.Character == 11)
			{
				Object.Destroy((Object)(object)((VisualEntity)currentEntity).GetVisual("shadowVisual").gameObject);
			}
			if ((int)val.Character == 10)
			{
				Object.Destroy((Object)(object)((VisualEntity)currentEntity).GetVisual("pieceVisual").gameObject);
			}
			if (currentEntity.playerData.deaths >= SuperRandomTweak.numberOfStocks)
			{
				return currentEntity;
			}
			int stocks = World.instance.playerHandler.playerHandlerData.playerData[((AbilityEntity)val.playerEntity).playerIndex].stocks;
			Character val2 = (Character)101;
			val2 = ((!JOMBNFKIHIC.GIGAKBJGFDI.JFNLOKKDCEB() || currentEntity.playerData.deaths <= 12) ? list[currentEntity.playerData.deaths] : list[ControlledRandom.Get(0, 0, SuperRandomTweak.randomCharacters[val.nr].Count)]);
			val.Character = val2;
			PlayerEntity val3 = playerHandler.CreatePlayerEntity(Player.op_Implicit(val));
			val3.playerData.deaths = currentEntity.playerData.deaths;
			SuperRandom.Log.LogDebug((object)$"new death count : {val3.playerData.deaths}");
			val.Character = ((MovableEntity)val3).character;
			SuperRandom.Log.LogDebug((object)$"Setting {val.nr} to {val.Character}");
			((AbilityData)val3.playerData).specialAmount = 0;
			val3.playerData.stocks = stocks;
			((Entity)val3).entityID = ((Entity)val.playerEntity).entityID;
			PlayerHandler.instance.playerHandlerData.playerData[nr] = val3.playerData;
			World.instance.entityList[((Entity)val.playerEntity).entityID - 1] = (Entity)(object)val3;
			_ = ((Object)((Component)val.playerEntity).gameObject).name;
			Object.Destroy((Object)(object)((Component)val.playerEntity).gameObject);
			val.playerEntity = val3;
			ResetHud(currentEntity);
			return val3;
		}

		private static bool JetInList()
		{
			bool found = false;
			Player.ForAllInMatch((Action<Player>)delegate(Player player)
			{
				if (SuperRandomTweak.randomCharacters[player.nr] != null && SuperRandomTweak.randomCharacters[player.nr].Contains((Character)9))
				{
					found = true;
				}
			});
			return found;
		}

		private static bool CopDetectiveInList()
		{
			bool found = false;
			Player.ForAllInMatch((Action<Player>)delegate(Player player)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Invalid comparison between Unknown and I4
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Invalid comparison between Unknown and I4
				if (SuperRandomTweak.randomCharacters[player.nr] != null && SuperRandomTweak.randomCharacters[player.nr].Contains((Character)7) && ((int)player.variant == 9 || (int)player.variant == 10))
				{
					found = true;
				}
			});
			return found;
		}

		private static bool CopLuchaInList()
		{
			bool found = false;
			Player.ForAllInMatch((Action<Player>)delegate(Player player)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Invalid comparison between Unknown and I4
				if (SuperRandomTweak.randomCharacters[player.nr] != null && (int)EPCDKLCABNC.LEMKFOAAMKA((Character)7, player.variant) == 7)
				{
					found = true;
				}
			});
			return found;
		}

		[HarmonyPatch(typeof(BallEntity), "AddExtraBallVisuals")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AddExtraVisual_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator iL)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_0055: 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_00a3: 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_00f1: 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)
			CodeMatcher val = new CodeMatcher(instructions, iL);
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "skate"));
			val.Advance(-1).Set(OpCodes.Call, (object)AccessTools.Method(typeof(AddPlayersToWorldPatch), "JetInList", (Type[])null, (Type[])null));
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "cop_detective"));
			val.Advance(-1).Set(OpCodes.Call, (object)AccessTools.Method(typeof(AddPlayersToWorldPatch), "CopDetectiveInList", (Type[])null, (Type[])null));
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "candies"));
			val.Advance(-1).Set(OpCodes.Call, (object)AccessTools.Method(typeof(AddPlayersToWorldPatch), "AddCandyAnims", (Type[])null, (Type[])null));
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "cop_lucha"));
			val.Advance(-1).Set(OpCodes.Call, (object)AccessTools.Method(typeof(AddPlayersToWorldPatch), "CopLuchaInList", (Type[])null, (Type[])null));
			return val.InstructionEnumeration();
		}

		public static HashSet<CharacterVariant> AddCandyAnims()
		{
			HashSet<CharacterVariant> candies = new HashSet<CharacterVariant>();
			Player.ForAllInMatch((Action<Player>)delegate(Player player)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: 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)
				if (SuperRandomTweak.randomCharacters[player.nr] == null)
				{
					return;
				}
				CharacterVariant variant = player.variant;
				SuperRandom.Log.LogInfo((object)"AddingCandyAnims");
				foreach (Character item in SuperRandomTweak.randomCharacters[player.nr])
				{
					_ = item;
					candies.Add(variant);
				}
			});
			return candies;
		}
	}
	internal class CreateUI
	{
		[HarmonyPatch(typeof(PlayersSelection), "Init")]
		[HarmonyPostfix]
		private static void Init(int _playerNr)
		{
			SuperRandom.superRandomTweak.CreateUI();
			if (SuperRandomTweak.sRToggled)
			{
				SuperRandom.superRandomTweak.EnableSuperRandomMode();
			}
		}

		[HarmonyPatch(typeof(ScreenPlayers), "OnOpen")]
		[HarmonyPrefix]
		private static void Prefix_OnOpen(ScreenPlayers __instance)
		{
			SuperRandomTweak.sP = __instance;
		}
	}
	[HarmonyPatch]
	internal class LoadBundles
	{
		private class SimpleEnumerator : IEnumerable
		{
			public IEnumerator enumerator;

			public Action prefixAction;

			public Action postfixAction;

			IEnumerator IEnumerable.GetEnumerator()
			{
				return GetEnumerator();
			}

			public IEnumerator GetEnumerator()
			{
				prefixAction();
				while (enumerator.MoveNext())
				{
					yield return enumerator.Current;
				}
				yield return Characters(null);
				postfixAction();
			}
		}

		private static IEnumerator Characters(object item)
		{
			List<Character> charactersToLoad = new List<Character>();
			for (int i = 0; i < 4; i++)
			{
				List<Character> list = SuperRandomTweak.randomCharacters[i];
				if (list == null || list.Count == 0)
				{
					continue;
				}
				foreach (Character item2 in list)
				{
					if (!charactersToLoad.Contains(item2))
					{
						charactersToLoad.Add(item2);
						SuperRandom.Log.LogWarning((object)$"[{i}] PreLoad '{item2} Bundle");
						yield return BundleHandler.CLoadBundle(new Bundle((BundleType)8, item2), (BundleLoadType)1, (Action)null);
					}
				}
			}
		}

		[HarmonyPatch(typeof(OGONAGCFDPK), "DLIEBHKPBGP")]
		[HarmonyPostfix]
		private static void BundlePatcher(ref IEnumerator __result)
		{
			Action prefixAction = delegate
			{
				SuperRandom.Log.LogWarning((object)"--> beginning");
			};
			Action postfixAction = delegate
			{
				SuperRandom.Log.LogWarning((object)"--> ending");
			};
			SimpleEnumerator simpleEnumerator = new SimpleEnumerator
			{
				enumerator = __result,
				prefixAction = prefixAction,
				postfixAction = postfixAction
			};
			__result = simpleEnumerator.GetEnumerator();
		}
	}
	internal class Networking
	{
		private enum SuperRandomMessages
		{
			SENDCHARACTERLIST = 54321
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static Action<Message> <0>__RecieveCharacterList;

			public static OnStageSelectOpenHandler <1>__LobbyEvents_OnStageSelectOpen;
		}

		public static void Init()
		{
			//IL_0053: 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_005e: Expected O, but got Unknown
			MessageApi.RegisterCustomMessage(((BaseUnityPlugin)SuperRandom.Instance).Info, (ushort)54321, SuperRandomMessages.SENDCHARACTERLIST.ToString(), (Action<Message>)RecieveCharacterList);
			object obj = <>O.<1>__LobbyEvents_OnStageSelectOpen;
			if (obj == null)
			{
				OnStageSelectOpenHandler val = LobbyEvents_OnStageSelectOpen;
				<>O.<1>__LobbyEvents_OnStageSelectOpen = val;
				obj = (object)val;
			}
			LobbyEvents.OnStageSelectOpen += (OnStageSelectOpenHandler)obj;
		}

		private static void GetRandomList()
		{
			if (!SuperRandomTweak.sRToggled)
			{
				return;
			}
			SuperRandomTweak.SetNumberOfStocks();
			Player.ForAllInMatch((Action<Player>)delegate(Player player)
			{
				if (player.nr == -1)
				{
					player.nr = 0;
				}
				SuperRandomTweak.randomCharacters[player.nr] = SuperRandomTweak.GetRandomChars(player.nr);
			});
			SuperRandom.Log.LogInfo((object)"randomCharacters has been set");
			List<Character>[] randomCharacters = SuperRandomTweak.randomCharacters;
			foreach (List<Character> arg in randomCharacters)
			{
				SuperRandom.Log.LogInfo((object)$"{arg}");
			}
		}

		private static void LobbyEvents_OnStageSelectOpen(HDLIJDBFGKN source, OnStageSelectOpenArgs e)
		{
			GetRandomList();
			Player.ForAllInMatch((Action<Player>)delegate(Player player)
			{
				if (SuperRandomTweak.randomCharacters[player.nr] == null)
				{
					SuperRandom.Log.LogDebug((object)$"{player.nr} list is null");
				}
				else if (SuperRandomTweak.randomCharacters[player.nr].Count == 0)
				{
					SuperRandom.Log.LogDebug((object)$"{player.nr} list is empty");
				}
				else if (player.peer != null && player.IsLocalPeer)
				{
					SuperRandom.Log.LogDebug((object)$"{player.nr} getting ready to send");
					SendCharacterList(SuperRandomTweak.randomCharacters[player.nr]);
				}
			});
		}

		public static void SendCharacterList(List<Character> characterList)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			//IL_0036: Expected I4, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			SuperRandom.Log.LogDebug((object)"Sending CharacterList");
			byte[] array;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				using BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
				foreach (Character character in characterList)
				{
					binaryWriter.Write((int)character);
				}
				array = memoryStream.ToArray();
			}
			P2P.SendOthers(new Message((Msg)54321, ((Peer)P2P.localPeer).playerNr, -1, (object)array, -1));
		}

		public static void RecieveCharacterList(Message msg)
		{
			//IL_000f: 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_0079: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			SuperRandom.Log.LogDebug((object)"Retrieving CharacterList");
			byte[] buffer = (byte[])msg.ob;
			List<Character> list = new List<Character>();
			using (MemoryStream input = new MemoryStream(buffer))
			{
				using BinaryReader binaryReader = new BinaryReader(input);
				while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
				{
					list.Add((Character)binaryReader.ReadInt32());
				}
			}
			foreach (Character item in list)
			{
				SuperRandom.Log.LogDebug((object)$"{item} in {msg.playerNr} list");
			}
			SuperRandomTweak.randomCharacters[msg.playerNr] = list;
		}
	}
	[HarmonyPatch]
	internal class SpawnCorpsePatcher
	{
		[HarmonyTargetMethod]
		private static MethodInfo TargetMethod()
		{
			return typeof(ItemHandler).GetMethod("SpawnCorpse", BindingFlags.Instance | BindingFlags.Public);
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> SpawnCorpse_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_0));
			val.Insert((CodeInstruction[])(object)new CodeInstruction[3]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				Transpilers.EmitDelegate<Func<CorpseEntity, ItemHandler, int, CorpseEntity>>((Func<CorpseEntity, ItemHandler, int, CorpseEntity>)((CorpseEntity corpseEntity, ItemHandler itemHandler, int index) => InitializeCorpse(corpseEntity, itemHandler, index)))
			});
			return val.InstructionEnumeration();
		}

		private static CorpseEntity InitializeCorpse(CorpseEntity corpseEntity, ItemHandler itemHandler, int index)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			//IL_0067: 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)
			int entityID = ((Entity)corpseEntity).entityID;
			Object.Destroy((Object)(object)((Component)itemHandler.corpseItems[index]).gameObject);
			CorpseEntity val = new GameObject().AddComponent<CorpseEntity>();
			SuperRandom.Log.LogDebug((object)"Initializing new corpse");
			((Entity)val).Init((object)itemHandler.itemHandlerData.corpseItemsData[index]);
			PlayerEntity playerEntity = Player.GetPlayer(index).playerEntity;
			if ((Object)(object)playerEntity != (Object)null && (int)((MovableEntity)playerEntity).character != 101)
			{
				val.SetCharacter(((MovableEntity)playerEntity).character, ((MovableEntity)playerEntity).variant);
			}
			((Component)val).transform.parent = ((Handler)itemHandler).holder;
			((Entity)val).entityID = entityID;
			itemHandler.corpseItems[index] = val;
			((Handler)itemHandler).world.entityList[entityID - 1] = (Entity)(object)val;
			return val;
		}
	}
	[HarmonyPatch]
	internal class SpawnPlayerPatcher
	{
		[HarmonyTargetMethod]
		private static MethodInfo TargetMethod()
		{
			return typeof(OGONAGCFDPK).GetNestedType("BONHAFGBBNE", BindingFlags.NonPublic).GetMethod("JICJCNKMBBN", BindingFlags.Instance | BindingFlags.NonPublic);
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> SpawnPlayers_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Callvirt && (i.operand as MethodBase).Name == "Spawn"));
			val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<PlayerEntity, PlayerEntity>>((Func<PlayerEntity, PlayerEntity>)((PlayerEntity playerEntity) => AddPlayersToWorldPatch.ResetNextCharacter(playerEntity))) });
			return val.InstructionEnumeration();
		}
	}
	[BepInPlugin("us.Cubical.plugins.llb.SuperRandom", "SuperRandom", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LLBlaze.exe")]
	public class SuperRandom : BaseUnityPlugin
	{
		public static Harmony harmony = new Harmony("SuperRandom");

		public static SuperRandomTweak superRandomTweak;

		public ConfigEntry<bool> superRandomOn;

		public ConfigEntry<bool> useKarmicRandom;

		public ConfigEntry<bool> resetWeightButton;

		public ConfigEntry<KeyCode> SwapCharacterInTrainingKey;

		public ConfigEntry<KeyCode> ResetWeightsKey;

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


		public static ManualLogSource Log { get; private set; } = null;


		public void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll(typeof(CreateUI));
			superRandomTweak = new SuperRandomTweak();
			LLBTweaker.AddTweak((TweakBase)(object)superRandomTweak);
			Log.LogDebug((object)"Added SuperRandom Tweak");
			Networking.Init();
			superRandomOn = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "SuperRandomOn", true, (ConfigDescription)null);
			useKarmicRandom = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "UseKarmicRandom", true, (ConfigDescription)null);
			resetWeightButton = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "ResetKarmaWeights", false, (ConfigDescription)null);
			SwapCharacterInTrainingKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "swapCharacterInTrainingKey", (KeyCode)113, (ConfigDescription)null);
			ResetWeightsKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "resetWeightsKey", (KeyCode)119, (ConfigDescription)null);
		}
	}
	public class SuperRandomTweak : HarmonyTweak
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static OnDecisionsHandler <>9__10_0;

			internal void <Start>b__10_0(HDLIJDBFGKN source, OnDecisionsArgs args)
			{
				DebugUtils.DecisionsToString(args.decisions);
			}
		}

		public LLButton superRandomButton;

		public LLButton allowRepeatsButton;

		public static ScreenPlayers sP;

		public PlayersCharacterButton pCB;

		public static List<Character>[] randomCharacters = new List<Character>[4];

		public GameObject characterButton;

		public static List<PlayerEntity>[] playerEntities = new List<PlayerEntity>[4];

		public static bool sRToggled = false;

		public GameObject emptyParent;

		public static List<Character>[] addedCharacters = new List<Character>[4]
		{
			new List<Character>(),
			new List<Character>(),
			new List<Character>(),
			new List<Character>()
		};

		private Dictionary<Character, float> characterWeights = new Dictionary<Character, float>();

		private const float minWeight = 0.1f;

		private const float maxWeight = 5f;

		private const float decayFactor = 0.5f;

		public static bool allowRepeats;

		public static int numberOfStocks = 5;

		public SuperRandomTweak()
			: base("superRandom-tweak", "superRandom", (Harmony)null)
		{
			SuperRandom.Log.LogInfo((object)"SuperRandomTweak constructor started");
			((HarmonyTweak)this).AddPatchClass(typeof(AddPlayersToWorldPatch), false);
			((HarmonyTweak)this).AddPatchClass(typeof(LoadBundles), false);
			((HarmonyTweak)this).AddPatchClass(typeof(SpawnPlayerPatcher), false);
			((HarmonyTweak)this).AddPatchClass(typeof(SpawnCorpsePatcher), false);
			SuperRandom.Log.LogInfo((object)"SuperRandomTweak constructor completed");
		}

		public void Awake()
		{
		}

		private void LobbyEvents_OnLobbyEntered(object source, LobbyEventArgs e)
		{
		}

		public override void Start()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__10_0;
			if (obj == null)
			{
				OnDecisionsHandler val = delegate(HDLIJDBFGKN source, OnDecisionsArgs args)
				{
					DebugUtils.DecisionsToString(args.decisions);
				};
				<>c.<>9__10_0 = val;
				obj = (object)val;
			}
			LobbyEvents.OnDecisions += (OnDecisionsHandler)obj;
			SuperRandom.Log.LogInfo((object)"SuperRandom Started");
			ModDependenciesUtils.RegisterToModMenu(((BaseUnityPlugin)SuperRandom.Instance).Info, new List<string> { "<b>Testing</b>:", "", "0 : <b>None</b>", "1 : <b>1</b>", "2 : <b>2</b>", "3 : <b>3</b>" });
		}

		public override void FixedUpdate()
		{
		}

		protected override void DoPatch()
		{
			((HarmonyTweak)this).DoPatch();
		}

		protected override void DoUnpatch()
		{
			((HarmonyTweak)this).DoUnpatch();
		}

		public override void Update()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_00a0: 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)
			if (GameStates.IsInMatch() && (int)JOMBNFKIHIC.GIGAKBJGFDI.PNJOKAICMNN == 100)
			{
				Player player = Player.GetPlayer(0);
				if (randomCharacters != null && Input.GetKeyDown(SuperRandom.Instance.SwapCharacterInTrainingKey.Value))
				{
					PlayerData playerData = player.playerEntity.playerData;
					playerData.deaths++;
					if (player.playerEntity.playerData.deaths >= 4)
					{
						player.playerEntity.playerData.deaths = 0;
					}
					AddPlayersToWorldPatch.ResetNextCharacter(player.playerEntity);
					((AbilityEntity)player.playerEntity).Spawn();
				}
			}
			if (GameStates.IsInLobby() && Input.GetKeyDown(SuperRandom.Instance.ResetWeightsKey.Value))
			{
				ResetWeights();
			}
		}

		public void EnableSuperRandomMode()
		{
			//IL_0093: 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_0051: Expected O, but got Unknown
			if ((Object)(object)superRandomButton != (Object)null)
			{
				superRandomButton.SetText("Super Random !!!", -1, false);
			}
			if ((Object)(object)emptyParent == (Object)null)
			{
				emptyParent = new GameObject("SuperRandomParent", new Type[1] { typeof(RectTransform) });
			}
			Transform parent = ((Component)sP.btOptions).transform.parent;
			emptyParent.transform.SetParent(((Component)parent).transform);
			emptyParent.SetActive(true);
			emptyParent.transform.localScale = Vector3.one;
			int nr = Player.GetLocalPlayer().nr;
			OverlayButtonsON(nr);
			if (SuperRandom.Instance.resetWeightButton.Value)
			{
				ResetWeights();
				SuperRandom.Instance.resetWeightButton.Value = false;
			}
		}

		public void CreateUI()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)superRandomButton == (Object)null || !((Component)superRandomButton).gameObject.activeInHierarchy)
			{
				superRandomButton = Object.Instantiate<LLButton>(sP.btOptions, ((Component)sP.btOptions).transform.parent);
				((Object)superRandomButton).name = "btSR";
				superRandomButton.SetText("Super Random ???", -1, false);
				((LLClickable)superRandomButton).onClick = new ControlDelegate(HandleSuperRandomButtonClick);
				RectTransform component = ((Component)superRandomButton).GetComponent<RectTransform>();
				RectTransform component2 = ((Component)sP.btOptions).GetComponent<RectTransform>();
				component.anchoredPosition = component2.anchoredPosition + new Vector2(250f, 0f);
				allowRepeatsButton = Object.Instantiate<LLButton>(sP.btOptions, ((Component)sP.btOptions).transform.parent);
				((Object)allowRepeatsButton).name = "btAR";
				allowRepeatsButton.SetText("Allow Repeats: OFF", -1, false);
				((LLClickable)allowRepeatsButton).SetActive(false);
				((LLControl)allowRepeatsButton).visible = false;
				((LLClickable)allowRepeatsButton).onClick = new ControlDelegate(SetAllowRepeats);
				((Component)allowRepeatsButton).GetComponent<RectTransform>().anchoredPosition = component2.anchoredPosition + new Vector2(830f, 0f);
			}
		}

		public void HandleSuperRandomButtonClick(int playerNr)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			playerNr = Player.GetLocalPlayer().nr;
			if (playerNr == -1)
			{
				playerNr = 0;
			}
			sRToggled = !sRToggled;
			if (sRToggled)
			{
				if ((Object)(object)emptyParent == (Object)null)
				{
					emptyParent = new GameObject();
				}
				Transform parent = ((Component)sP.btOptions).transform.parent;
				emptyParent.transform.SetParent(((Component)parent).transform);
				emptyParent.SetActive(true);
				emptyParent.transform.localScale = Vector3.one;
				superRandomButton.SetText("Super Random !!!", -1, false);
				SuperRandom.Log.LogDebug((object)"Super Random is ON");
				OverlayButtonsON(playerNr);
				((LLClickable)allowRepeatsButton).SetActive(true);
				((LLControl)allowRepeatsButton).visible = true;
				GameStates.Send((Msg)50, playerNr, 102);
			}
			else
			{
				((LLClickable)allowRepeatsButton).SetActive(false);
				((LLControl)allowRepeatsButton).visible = false;
				emptyParent.SetActive(false);
				superRandomButton.SetText("Super Random ???", -1, false);
				SuperRandom.Log.LogDebug((object)"Super Random is OFF");
				OverlayButtonsOFF();
			}
		}

		public void OverlayButtonsON(int playerNr)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Invalid comparison between Unknown and I4
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: 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_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Expected O, but got Unknown
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			playerNr = Player.GetLocalPlayer().nr;
			if (playerNr == -1)
			{
				playerNr = 0;
			}
			Player.GetPlayer(playerNr);
			Character[] array = (Character[])(object)new Character[13]
			{
				(Character)10,
				(Character)8,
				(Character)5,
				(Character)4,
				(Character)3,
				(Character)1,
				(Character)100,
				default(Character),
				(Character)2,
				(Character)9,
				(Character)6,
				(Character)7,
				(Character)11
			};
			List<Character> list = new List<Character>
			{
				(Character)10,
				(Character)8,
				(Character)5,
				(Character)4,
				(Character)3,
				(Character)1,
				(Character)102,
				(Character)0,
				(Character)2,
				(Character)9,
				(Character)6,
				(Character)7,
				(Character)11
			};
			float num = 64f;
			float num2 = -384.5f;
			float num3 = 0f;
			_ = Vector3.one;
			switch (playerNr)
			{
			case 0:
				num2 = -384.5f;
				num3 = -255f;
				new Vector3(1f, 1f, 1f);
				break;
			case 1:
				num2 = -384.5f;
				num3 = -255f;
				new Vector3(1f, 1f, 1f);
				break;
			case 2:
				num2 = -384.5f;
				num3 = -255f;
				new Vector3(1f, 1f, 1f);
				break;
			default:
				num2 = -384.5f;
				num3 = -255f;
				new Vector3(1f, 1f, 1f);
				break;
			}
			for (int i = 0; i < array.Length; i++)
			{
				Character character = array[i];
				characterButton = Object.Instantiate<GameObject>(sP.pfCharacterButton, emptyParent.transform);
				characterButton.transform.localPosition = new Vector3((float)i * num + num2, num3, 0f);
				((Object)characterButton).name = "CharacterButton_" + ((object)(Character)(ref character)).ToString();
				PlayersCharacterButton component = characterButton.GetComponent<PlayersCharacterButton>();
				Image imCharacter = component.imCharacter;
				Image component2 = ((Component)((Component)component).gameObject.transform.GetChild(0).GetChild(0).GetChild(0)).GetComponent<Image>();
				if ((int)character == 100)
				{
					imCharacter.sprite = JPLELOFJOOH.CCGLCPJGPHJ((Character)102, false);
					((Graphic)component2).color = Color.blue;
					continue;
				}
				component.character = list[i];
				component.imCharacter.sprite = JPLELOFJOOH.CCGLCPJGPHJ(component.character, false);
				((Graphic)imCharacter).color = Color.Lerp(Color.white, Color.black, 0.75f);
				((Graphic)component2).color = Color.red;
				((LLClickable)component.btCharacter).onClick = (ControlDelegate)delegate
				{
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					HandleOverlay(playerNr, character, component);
				};
				if (addedCharacters[playerNr].Contains(character))
				{
					((Graphic)imCharacter).color = Color.white;
					((Graphic)component2).color = Color.green;
				}
			}
		}

		public void OverlayButtonsOFF()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			SuperRandom.Log.LogInfo((object)"Hiding all character buttons.");
			foreach (Transform item in ((Component)sP.btOptions).transform.parent)
			{
				Transform val = item;
				if (((Object)val).name.StartsWith("CharacterButton"))
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}

		public static void SetNumberOfStocks()
		{
			if (!JOMBNFKIHIC.GIGAKBJGFDI.JFNLOKKDCEB())
			{
				numberOfStocks = GameSettings.current.stocks;
			}
			else if (GameSettings.current.points >= 12)
			{
				numberOfStocks = 12;
			}
			else if (GameSettings.current.points <= 12)
			{
				numberOfStocks = GameSettings.current.points;
			}
		}

		public void SetAllowRepeats(int playerNr)
		{
			allowRepeats = !allowRepeats;
			if (allowRepeats)
			{
				allowRepeatsButton.SetText("Allow Repeats: ON", -1, false);
			}
			else
			{
				allowRepeatsButton.SetText("Allow Repeats: OFF", -1, false);
			}
		}

		public void SetUseKarmicRandom(bool value)
		{
			SuperRandom.Instance.useKarmicRandom.Value = value;
		}

		public void HandleOverlay(int playerNr, Character character, PlayersCharacterButton component)
		{
			//IL_0038: 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_00b6: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_0067: 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_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)
			if (playerNr == -1)
			{
				playerNr = 0;
			}
			Image imCharacter = component.imCharacter;
			Image component2 = ((Component)((Component)component).gameObject.transform.GetChild(0).GetChild(0).GetChild(0)).GetComponent<Image>();
			if (!addedCharacters[playerNr].Contains(character))
			{
				SuperRandom.Log.LogDebug((object)$"Added {character} character for {playerNr}");
				addedCharacters[playerNr].Add(character);
				characterWeights[character] = 1f;
				((Graphic)imCharacter).color = Color.white;
				((Graphic)component2).color = Color.green;
			}
			else
			{
				SuperRandom.Log.LogDebug((object)$"Removed {character}");
				addedCharacters[playerNr].Remove(character);
				characterWeights.Remove(character);
				((Graphic)imCharacter).color = Color.Lerp(Color.white, Color.black, 0.75f);
				((Graphic)component2).color = Color.red;
			}
		}

		public static List<Character> GetRandomChars(int playerNr)
		{
			return SuperRandom.superRandomTweak.GetRandomCharacters(playerNr);
		}

		public List<Character> GetRandomCharacters(int playerNr)
		{
			return GetRandomCharacters(numberOfStocks, allowRepeats, SuperRandom.Instance.useKarmicRandom.Value, playerNr);
		}

		public List<Character> GetRandomCharacters(int count, bool allowRepeats, bool useKarmicRandom, int playerNR)
		{
			//IL_00a9: 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_0053: 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)
			//IL_005f: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			bool flag = allowRepeats;
			if (addedCharacters[playerNR].Count == 0)
			{
				return new List<Character>();
			}
			if (!allowRepeats && addedCharacters[playerNR].Count < count)
			{
				allowRepeats = true;
			}
			List<Character> list = new List<Character>();
			if (useKarmicRandom)
			{
				Dictionary<Character, float> dictionary = new Dictionary<Character, float>(characterWeights);
				while (list.Count < count && dictionary.Count != 0)
				{
					Character val = WeightedRandomSelection(dictionary);
					list.Add(val);
					if (!allowRepeats)
					{
						dictionary.Remove(val);
					}
					if (allowRepeats)
					{
						ReduceWeight(val);
					}
				}
			}
			else
			{
				List<Character> list2 = new List<Character>(addedCharacters[playerNR]);
				while (list.Count < count && list2.Count != 0)
				{
					int index = Random.Range(0, list2.Count);
					list.Add(list2[index]);
					if (!allowRepeats)
					{
						list2.RemoveAt(index);
					}
				}
			}
			SuperRandom.Log.LogInfo((object)"Selected characters: ");
			foreach (Character item in list)
			{
				Character current = item;
				SuperRandom.Log.LogInfo((object)("Character: " + ((object)(Character)(ref current)).ToString()));
			}
			allowRepeats = flag;
			return list;
		}

		private Character WeightedRandomSelection(Dictionary<Character, float> availableCharacters)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			float num = availableCharacters.Values.Sum();
			float num2 = Random.Range(0f, num);
			float num3 = 0f;
			foreach (KeyValuePair<Character, float> availableCharacter in availableCharacters)
			{
				num3 += availableCharacter.Value;
				if (num2 <= num3)
				{
					return availableCharacter.Key;
				}
			}
			return availableCharacters.Keys.First();
		}

		private void ReduceWeight(Character character)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_005c: 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)
			if (characterWeights.ContainsKey(character))
			{
				characterWeights[character] *= 0.5f;
				SuperRandom.Log.LogInfo((object)$"Character {character} weight reduced to: {characterWeights[character]}");
				if (characterWeights[character] < 0.1f)
				{
					characterWeights[character] = 0.1f;
				}
			}
		}

		public void ResetWeights()
		{
			//IL_001a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			foreach (Character item in characterWeights.Keys.ToList())
			{
				characterWeights[item] = 1f;
			}
			SuperRandom.Log.LogInfo((object)"Character weights have been reset to 1.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SuperRandom";

		public const string PLUGIN_NAME = "SuperRandomLLB Mod";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}