Decompiled source of Random Character v1.0.2

RandomCharacter.dll

Decompiled 4 days 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.2")]
	[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;
				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 += ",";
					}
				}
				ListofCharacters.Value = text;
			}
		}

		[HarmonyPatch(typeof(StartGamePanel), "OnShowing")]
		private class StartGamePanel_OnShowing_Patch
		{
			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));
					}
				});
			}

			private static IEnumerator coroutine(StartGamePanel startGamePanel)
			{
				yield return (object)new WaitForSecondsRealtime(0.15f);
				for (int i = 0; i < 1; i++)
				{
					int j = Random.Range(0, startGamePanel._players.Length);
					if (!startGamePanel._players[j].Config.IsSelectable || !startGamePanel._players[j].Config.UnlockLevel.HasValue || Blacklist.Value.Contains(startGamePanel._players[j].Config.Id) || startGamePanel._players[j] is RandomCharacterPlayerUnitDef.RandomCharacterPlayerUnit)
					{
						i--;
						continue;
					}
					startGamePanel.SelectPlayer(j, true);
					startGamePanel.SelectType(Random.Range(0, 2));
				}
			}
		}

		[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.2";

		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_0020: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			int? num = 0;
			ManaGroup val = default(ManaGroup);
			((ManaGroup)(ref val)).Any = 0;
			return new PlayerUnitConfig("", int.MaxValue, 0, num, "", "#ffffff", true, 0, val, 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)
		{
		}
	}
}