Decompiled source of Random Character v1.0.4

RandomCharacter.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
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 AddWatermark;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cysharp.Threading.Tasks;
using HarmonyLib;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Units;
using LBoL.Presentation;
using LBoL.Presentation.UI.Panels;
using LBoLEntitySideloader;
using LBoLEntitySideloader.Attributes;
using LBoLEntitySideloader.Entities;
using LBoLEntitySideloader.Resource;
using LBoLEntitySideloader.Utils;
using RandomCharacter.PlayerUnits;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering;

[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: IgnoresAccessChecksTo("LBoL.Base")]
[assembly: IgnoresAccessChecksTo("LBoL.ConfigData")]
[assembly: IgnoresAccessChecksTo("LBoL.Core")]
[assembly: IgnoresAccessChecksTo("LBoL.EntityLib")]
[assembly: IgnoresAccessChecksTo("LBoL.Presentation")]
[assembly: IgnoresAccessChecksTo("Untitled.ConfigDataBuilder.Base")]
[assembly: AssemblyCompany("RandomCharacter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RandomCharacter")]
[assembly: AssemblyTitle("RandomCharacter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RandomCharacter
{
	[BepInPlugin("intoxicatedkid.randomcharacter", "Random Character", "1.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LBoL.exe")]
	public class BepinexPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(MainMenuPanel), "Awake")]
		private class MainMenuPanel_Awake_Patch
		{
			private static void Postfix(MainMenuPanel __instance)
			{
				string text = string.Empty;
				bool flag = false;
				foreach (PlayerUnitConfig item in from config in PlayerUnitConfig.AllConfig()
					where config.IsSelectable && config.Id != PlayerUnitConfig.FromId("RandomCharacterPlayerUnit").Id
					select config)
				{
					text += item.Id;
					if (item != PlayerUnitConfig.AllConfig().Last((PlayerUnitConfig p) => p.IsSelectable && p.Id != PlayerUnitConfig.FromId("RandomCharacterPlayerUnit").Id))
					{
						text += ",";
					}
					if (!Blacklist.Value.Contains(item.Id))
					{
						flag = true;
					}
				}
				ListofCharacters.Value = text;
				if (!flag)
				{
					Debug.LogWarning((object)"All characters have been blacklisted. Random Character is locked.");
					PlayerUnitConfig.FromId("RandomCharacterPlayerUnit").UnlockLevel = null;
				}
			}
		}

		[HarmonyPatch(typeof(StartGamePanel), "OnShowing")]
		private class StartGamePanel_OnShowing_Patch
		{
			[CompilerGenerated]
			private sealed class <coroutine>d__1 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public StartGamePanel startGamePanel;

				private int <i>5__1;

				private int <j>5__2;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <coroutine>d__1(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>2__current = (object)new WaitForSecondsRealtime(0.15f);
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						<i>5__1 = 0;
						while (<i>5__1 < 99)
						{
							<j>5__2 = Random.Range(0, startGamePanel._players.Count);
							if (!startGamePanel._players[<j>5__2].Config.IsSelectable || !startGamePanel._players[<j>5__2].Config.UnlockLevel.HasValue || Blacklist.Value.Contains(startGamePanel._players[<j>5__2].Config.Id) || startGamePanel._players[<j>5__2] is RandomCharacterPlayerUnitDef.RandomCharacterPlayerUnit)
							{
								<i>5__1--;
								<i>5__1++;
								continue;
							}
							startGamePanel.SelectPlayer(<j>5__2, true);
							startGamePanel.SelectType(Random.Range(0, 2));
							return false;
						}
						Debug.LogWarning((object)"Random Character couldn't select a character, selecting default.");
						startGamePanel.SelectPlayer(0, true);
						startGamePanel.SelectType(0);
						return false;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			private static void Postfix(StartGamePanel __instance, ref StartGameData data)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Expected O, but got Unknown
				((UnityEvent)__instance.characterConfirmButton.onClick).AddListener((UnityAction)delegate
				{
					if (__instance._player is RandomCharacterPlayerUnitDef.RandomCharacterPlayerUnit)
					{
						((MonoBehaviour)Singleton<GameMaster>.Instance).StartCoroutine(coroutine(__instance));
					}
				});
			}

			[IteratorStateMachine(typeof(<coroutine>d__1))]
			private static IEnumerator coroutine(StartGamePanel startGamePanel)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <coroutine>d__1(0)
				{
					startGamePanel = startGamePanel
				};
			}
		}

		[HarmonyPatch(typeof(MuseumPanel), "Awake")]
		private class MuseumPanel_Awake_Patch
		{
			private static void Prefix(MuseumPanel __instance)
			{
				PlayerUnitConfig.FromId("RandomCharacterPlayerUnit").IsSelectable = false;
			}

			private static void Postfix(MuseumPanel __instance)
			{
				PlayerUnitConfig.FromId("RandomCharacterPlayerUnit").IsSelectable = true;
			}
		}

		private static readonly Harmony harmony = PluginInfo.harmony;

		internal static ManualLogSource log;

		internal static TemplateSequenceTable sequenceTable = new TemplateSequenceTable(0);

		internal static IResourceSource embeddedSource = (IResourceSource)new EmbeddedSource(Assembly.GetExecutingAssembly());

		internal static DirectorySource directorySource = new DirectorySource("intoxicatedkid.randomcharacter", "");

		internal static BatchLocalization playerUnitLoc = new BatchLocalization((IResourceSource)(object)directorySource, typeof(PlayerUnitTemplate), false);

		internal static BatchLocalization unitModelLoc = new BatchLocalization((IResourceSource)(object)directorySource, typeof(UnitModelTemplate), false);

		public static ConfigEntry<string> ListofCharacters;

		public static ConfigEntry<string> Blacklist;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			ListofCharacters = ((BaseUnityPlugin)this).Config.Bind<string>("Random Character Config", "List of Characters", "", "This config is refreshed everytime you launch a game with all available characters.");
			Blacklist = ((BaseUnityPlugin)this).Config.Bind<string>("Random Character Config", "Blacklist", "", "You can add a character from above config to prevent them from randomly selected. Seperated by comma.\nE.g. Reimu,Marisa,Sakuya");
			EntityManager.RegisterSelf();
			harmony.PatchAll();
			if (Chainloader.PluginInfos.ContainsKey("neo.lbol.tools.watermark"))
			{
				WatermarkWrapper.ActivateWatermark();
			}
			playerUnitLoc.DiscoverAndLoadLocFiles("PlayerUnit");
			unitModelLoc.DiscoverAndLoadLocFiles("UnitModel");
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class PluginInfo
	{
		public const string GUID = "intoxicatedkid.randomcharacter";

		public const string Name = "Random Character";

		public const string version = "1.0.4";

		public static readonly Harmony harmony = new Harmony("intoxicatedkid.randomcharacter");
	}
	internal class WatermarkWrapper
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void ActivateWatermark()
		{
			API.ActivateWatermark();
		}
	}
}
namespace RandomCharacter.PlayerUnits
{
	public sealed class RandomCharacterPlayerUnitDef : PlayerUnitTemplate
	{
		[EntityLogic(typeof(RandomCharacterPlayerUnitDef))]
		public sealed class RandomCharacterPlayerUnit : PlayerUnit
		{
		}

		public static DirectorySource dir = new DirectorySource("intoxicatedkid.randomcharacter", "");

		public static string name = "RandomCharacterPlayerUnit";

		public override IdContainer GetId()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit("RandomCharacterPlayerUnit");
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)BepinexPlugin.playerUnitLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override PlayerImages LoadPlayerImages()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			PlayerImages val = new PlayerImages();
			val.AutoLoad("RandomCharacter", (Func<string, Sprite>)((string s) => ResourceLoader.LoadSprite(s, (IResourceSource)(object)dir, (Rect?)null, 1, (Vector2?)null)), (Func<string, UniTask<Sprite>>)((string s) => ResourceLoader.LoadSpriteAsync(s, dir, 100, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://")), (UseSame)2, ".png", "");
			return val;
		}

		public override PlayerUnitConfig MakeConfig()
		{
			//IL_0026: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			int? num = 0;
			ManaGroup val = default(ManaGroup);
			((ManaGroup)(ref val)).Any = 0;
			return new PlayerUnitConfig("", false, "", 0, int.MaxValue, num, true, (int?)null, (ManaColor)6, (ManaColor)6, val, "#ffffff", 0, 0, 0, "MarisaUltR", "MarisaUltR", "KongZhanpinhe", "KongZhanpinhe", (IReadOnlyList<string>)new string[0], (IReadOnlyList<string>)new string[0], 0, 0);
		}
	}
	public sealed class RandomCharacterPlayerUnitUnitModelDef : UnitModelTemplate
	{
		public override IdContainer GetId()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return ((EntityDefinition)new RandomCharacterPlayerUnitDef()).UniqueId;
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)BepinexPlugin.unitModelLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override ModelOption LoadModelOptions()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return new ModelOption(ResourcesHelper.LoadSpineUnitAsync("Reimu"));
		}

		public override UniTask<Sprite> LoadSpellSprite()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			return ResourceLoader.LoadSpriteAsync("RandomCharacter.png", RandomCharacterPlayerUnitDef.dir, 100, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://");
		}

		public override UnitModelConfig MakeConfig()
		{
			return ObjectExtensions.Copy<UnitModelConfig>(UnitModelConfig.FromName("Reimu"));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}