using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using InLobbyConfig;
using InLobbyConfig.Fields;
using On.RoR2.UI;
using RoR2;
using RoR2.UI;
using RoR2.UI.SkinControllers;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RandomCharacterSelection;
public static class AssetBundleHelper
{
public static AssetBundle MainAssetBundle { get; private set; }
internal static void LoadAssetBundle()
{
MainAssetBundle = AssetBundle.LoadFromFile(GetBundlePath("kingenderbrine_randomcharacterselection"));
}
private static string GetBundlePath(string bundleName)
{
return Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)RandomCharacterSelectionPlugin.Instance).Info.Location), bundleName);
}
}
public static class ConfigHelper
{
public static ConfigEntry<bool> CanSelectSameCharacter { get; private set; }
public static void InitConfig(ConfigFile config)
{
CanSelectSameCharacter = config.Bind<bool>("Main", "CanSelectSameCharacter", false, (ConfigDescription)null);
if (RandomCharacterSelectionPlugin.InLobbyConfigLoaded)
{
InitInLobbyConfig(config);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitInLobbyConfig(ConfigFile config)
{
ModConfigCatalog.Add(ConfigFieldUtilities.CreateFromBepInExConfigFile(config, "Random Character Selection"));
}
}
public class DelayedInputHGGamepadInputEvent : HGGamepadInputEvent
{
public void Update()
{
bool flag = ((HGGamepadInputEvent)this).CanAcceptInput();
if (base.couldAcceptInput != flag)
{
GameObject[] enabledObjectsIfActive = base.enabledObjectsIfActive;
for (int i = 0; i < enabledObjectsIfActive.Length; i++)
{
enabledObjectsIfActive[i].SetActive(flag);
}
}
if (base.couldAcceptInput && flag && ((HGGamepadInputEvent)this).eventSystem.player.GetButtonDown(base.actionName))
{
base.actionEvent.Invoke();
}
base.couldAcceptInput = flag;
}
}
public class EventHolder : MonoBehaviour
{
public string customName;
public UnityEvent unityEvent;
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.KingEnderBrine.RandomCharacterSelection", "Random Character Selection", "1.5.0")]
public class RandomCharacterSelectionPlugin : BaseUnityPlugin
{
internal static RandomCharacterSelectionPlugin Instance { get; private set; }
internal static ManualLogSource InstanceLogger
{
get
{
RandomCharacterSelectionPlugin instance = Instance;
if (instance == null)
{
return null;
}
return ((BaseUnityPlugin)instance).Logger;
}
}
internal static bool InLobbyConfigLoaded { get; private set; }
private void Start()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
Instance = this;
InLobbyConfigLoaded = Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.InLobbyConfig");
AssetBundleHelper.LoadAssetBundle();
ConfigHelper.InitConfig(((BaseUnityPlugin)this).Config);
CharacterSelectController.Awake += new hook_Awake(RandomizePanelController.CharacterSelectControllerAwake);
}
}
public class RandomizePanelController : MonoBehaviour
{
public GameObject randomizeCharacterButton;
public GameObject randomizeLoadoutButton;
private CharacterSelectController characterSelectController;
private CharacterSelectBarController characterSelectBarController;
public static GameObject CachedPrefab { get; private set; }
private bool isEclipseRun
{
get
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)PreGameController.instance))
{
return PreGameController.instance.gameModeIndex == GameModeCatalog.FindGameModeIndex("EclipseRun");
}
return false;
}
}
public void Start()
{
characterSelectController = ((Component)this).GetComponentInParent<CharacterSelectController>();
characterSelectBarController = ((Component)characterSelectController).GetComponentInChildren<CharacterSelectBarController>();
}
public void RandomizeCharacter()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)PreGameController.instance) && PreGameController.instance.IsCharacterSwitchingCurrentlyAllowed() && Object.op_Implicit((Object)(object)characterSelectController))
{
LocalUser localUser = ((MPEventSystem)EventSystem.current).localUser;
SurvivorDef currentSurvivor = characterSelectController.currentSurvivorDef;
bool canSelectSameCharacter = ConfigHelper.CanSelectSameCharacter.Value;
IEnumerable<SurvivorDef> source = SurvivorCatalog.orderedSurvivorDefs.Where((SurvivorDef survivorDef) => (canSelectSameCharacter || (Object)(object)currentSurvivor != (Object)(object)survivorDef) && !survivorDef.hidden && SurvivorCatalog.SurvivorIsUnlockedOnThisClient(survivorDef.survivorIndex) && survivorDef.CheckRequiredExpansionEnabled((NetworkUser)null) && survivorDef.CheckUserHasRequiredEntitlement(localUser));
SurvivorDef val = source.ElementAt(Random.Range(0, source.Count()));
if (Object.op_Implicit((Object)(object)characterSelectController))
{
characterSelectBarController.PickIconBySurvivorDef(val);
characterSelectController.SetSurvivorInfoPanelActive(true);
}
}
}
public void RandomizeLoadout()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//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)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: 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_0055: Expected O, but got Unknown
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)PreGameController.instance) || !Object.op_Implicit((Object)(object)characterSelectController))
{
return;
}
BodyIndex bodyIndexFromSurvivorIndex = SurvivorCatalog.GetBodyIndexFromSurvivorIndex(characterSelectController.currentSurvivorDef.survivorIndex);
GenericSkill[] bodyPrefabSkillSlots = BodyCatalog.GetBodyPrefabSkillSlots(bodyIndexFromSurvivorIndex);
SkinDef[] bodySkins = BodyCatalog.GetBodySkins(bodyIndexFromSurvivorIndex);
LocalUser localUser = ((MPEventSystem)EventSystem.current).localUser;
Loadout val = new Loadout();
localUser.userProfile.CopyLoadout(val);
for (int i = 0; i < bodyPrefabSkillSlots.Length; i++)
{
GenericSkill val2 = bodyPrefabSkillSlots[i];
List<uint> list = new List<uint>();
for (uint num = 0u; num < val2.skillFamily.variants.Length; num++)
{
if (localUser.userProfile.HasUnlockable(val2.skillFamily.variants[num].unlockableDef))
{
list.Add(num);
}
}
val.bodyLoadoutManager.SetSkillVariant(bodyIndexFromSurvivorIndex, i, list[Random.Range(0, list.Count)]);
}
List<uint> list2 = new List<uint>();
for (uint num2 = 0u; num2 < bodySkins.Length; num2++)
{
if (localUser.userProfile.HasUnlockable(bodySkins[num2].unlockableDef))
{
list2.Add(num2);
}
}
val.bodyLoadoutManager.SetSkinIndex(bodyIndexFromSurvivorIndex, list2[Random.Range(0, list2.Count)]);
localUser.userProfile.SetLoadout(val);
}
internal static void CharacterSelectControllerAwake(orig_Awake orig, CharacterSelectController self)
{
orig.Invoke(self);
((MonoBehaviour)self).StartCoroutine(RandomizePanel(self));
}
private static IEnumerator RandomizePanel(CharacterSelectController self)
{
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
Transform val = ((Component)self).transform.Find("SafeArea/LeftHandPanel (Layer: Main)");
if (!Object.op_Implicit((Object)(object)CachedPrefab))
{
CachePrefabFromSurvivorGrid(val, "SurvivorChoiceGrid, Panel");
}
GameObject val2 = Object.Instantiate<GameObject>(CachedPrefab, ((Component)self).transform.Find("SafeArea"), false);
HGGamepadInputEvent[] components = ((Component)self).GetComponents<HGGamepadInputEvent>();
HGGamepadInputEvent val3;
HGGamepadInputEvent val4;
if (RandomCharacterSelectionPlugin.InLobbyConfigLoaded)
{
IEnumerable<HGGamepadInputEvent> source = components.Where((HGGamepadInputEvent el) => el.actionName == "UIPageRight");
val3 = source.ElementAt(0);
val4 = source.ElementAt(1);
}
else
{
val3 = components.First((HGGamepadInputEvent el) => el.actionName == "UIPageRight");
val3.requiredTopLayer = ((Component)val).GetComponent<UILayerKey>();
val4 = ((Component)self).gameObject.AddComponent<HGGamepadInputEvent>();
val4.actionName = val3.actionName;
val4.actionEvent = val3.actionEvent;
val4.requiredTopLayer = ((Component)val.Find("SurvivorInfoPanel, Active (Layer: Secondary)")).GetComponent<UILayerKey>();
val4.enabledObjectsIfActive = Array.Empty<GameObject>();
}
HGGamepadInputEvent val5 = val2.GetComponents<HGGamepadInputEvent>().First((HGGamepadInputEvent input) => input.actionName == "UIPageRight");
DelayedInputHGGamepadInputEvent delayedInputHGGamepadInputEvent = ((Component)self).gameObject.AddComponent<DelayedInputHGGamepadInputEvent>();
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent).actionName = "UIPageLeft";
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent).actionEvent = val2.GetComponent<EventHolder>().unityEvent;
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent).requiredTopLayer = val3.requiredTopLayer;
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent).enabledObjectsIfActive = Array.Empty<GameObject>();
DelayedInputHGGamepadInputEvent delayedInputHGGamepadInputEvent2 = ((Component)self).gameObject.AddComponent<DelayedInputHGGamepadInputEvent>();
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent2).actionName = ((HGGamepadInputEvent)delayedInputHGGamepadInputEvent).actionName;
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent2).actionEvent = ((HGGamepadInputEvent)delayedInputHGGamepadInputEvent).actionEvent;
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent2).requiredTopLayer = val4.requiredTopLayer;
((HGGamepadInputEvent)delayedInputHGGamepadInputEvent2).enabledObjectsIfActive = Array.Empty<GameObject>();
HGGamepadInputEvent obj = val2.AddComponent<HGGamepadInputEvent>();
obj.actionName = "UICancel";
obj.actionEvent = val5.actionEvent;
obj.requiredTopLayer = val5.requiredTopLayer;
obj.enabledObjectsIfActive = val5.enabledObjectsIfActive;
}
private static void CachePrefabFromSurvivorGrid(Transform panel, string survivorGridName)
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)CachedPrefab))
{
Transform obj = panel.Find(survivorGridName);
CachedPrefab = AssetBundleHelper.MainAssetBundle.LoadAsset<GameObject>("Assets/Resources/RandomizePanel.prefab");
CachedPrefab.GetComponent<Image>().sprite = ((Component)panel.Find("BorderImage")).GetComponent<Image>().sprite;
Sprite sprite = ((Component)obj.Find("SurvivorIconPrefab/BaseOutline")).GetComponent<Image>().sprite;
Sprite sprite2 = ((Component)obj.Find("SurvivorIconPrefab/HoverOutline")).GetComponent<Image>().sprite;
UISkinData val = Object.Instantiate<UISkinData>(((BaseSkinController)((Component)obj.Find("WIPClassButtonPrefab")).GetComponent<ButtonSkinController>()).skinData);
((ColorBlock)(ref val.buttonStyle.colors)).normalColor = Color.white;
HGButton[] componentsInChildren = CachedPrefab.GetComponentsInChildren<HGButton>();
foreach (HGButton obj2 in componentsInChildren)
{
((BaseSkinController)((Component)obj2).GetComponent<ButtonSkinController>()).skinData = val;
((Component)((Component)obj2).transform.Find("BaseOutline")).GetComponent<Image>().sprite = sprite;
((Component)((Component)obj2).transform.Find("HoverOutline")).GetComponent<Image>().sprite = sprite2;
}
}
}
}