Decompiled source of FTK MultiMax Reforged Lucario v1.1.7

FTK-MultiMax-Reforged-Lucario.dll

Decompiled 3 days ago
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.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using Google2u;
using GridEditor;
using HarmonyLib;
using Rewired;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FTK-MultiMax-Reforged-Lucario")]
[assembly: AssemblyDescription("Reforged continuation of FTK MultiMax Rework, incorporating V2 behavior and additional features")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Reforged by YFLucario; based on work by samupo, justedm, and PolarsBear")]
[assembly: AssemblyProduct("FTK-MultiMax-Reforged-Lucario")]
[assembly: AssemblyCopyright("Original work credited to samupo, justedm, and PolarsBear; Reforged continuation by YFLucario, 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("93679fb8-d7d5-4e0d-841d-239d6bd70317")]
[assembly: AssemblyFileVersion("2.1.4.11")]
[assembly: AssemblyVersion("2.1.4.11")]
namespace FTK_MultiMax_Rework;

[HarmonyPatch(typeof(CharacterDummy), "GetLeftDummy")]
public class CharacterDummy_GetLeftDummy_Patch
{
	[HarmonyPrefix]
	public static bool CharacterDummy_GetLeftDummy_Prefix(CharacterDummy __instance, ref CharacterDummy __result)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)__instance.m_CharacterOverworld))
		{
			int dioramaTargetIndex = __instance.m_DioramaTargetIndex;
			if (dioramaTargetIndex == 0)
			{
				__result = null;
				return false;
			}
			CharacterDummy playerDummyByDioramaTargetIndex = EncounterSession.Instance.GetPlayerDummyByDioramaTargetIndex(dioramaTargetIndex - 1);
			if (Object.op_Implicit((Object)(object)playerDummyByDioramaTargetIndex) && playerDummyByDioramaTargetIndex.m_IsAlive && playerDummyByDioramaTargetIndex.m_CharacterOverworld.m_CharacterStats.m_IsInCombat)
			{
				__result = playerDummyByDioramaTargetIndex;
				return false;
			}
		}
		else
		{
			_ = (EnemyDummy)__instance;
			switch (__instance.m_DioramaTargetIndex)
			{
			case 1:
				__result = null;
				return false;
			case 2:
			{
				CharacterDummy enemyDummyByDioramaTargetIndex2 = (CharacterDummy)(object)EncounterSession.Instance.GetEnemyDummyByDioramaTargetIndex(0);
				if (Object.op_Implicit((Object)(object)enemyDummyByDioramaTargetIndex2) && enemyDummyByDioramaTargetIndex2.m_IsAlive && !enemyDummyByDioramaTargetIndex2.m_DidFlee)
				{
					__result = enemyDummyByDioramaTargetIndex2;
					return false;
				}
				break;
			}
			case 0:
			{
				CharacterDummy enemyDummyByDioramaTargetIndex = (CharacterDummy)(object)EncounterSession.Instance.GetEnemyDummyByDioramaTargetIndex(1);
				if (Object.op_Implicit((Object)(object)enemyDummyByDioramaTargetIndex) && enemyDummyByDioramaTargetIndex.m_IsAlive && !enemyDummyByDioramaTargetIndex.m_DidFlee)
				{
					__result = enemyDummyByDioramaTargetIndex;
					return false;
				}
				break;
			}
			}
		}
		__result = null;
		return false;
	}
}
[HarmonyPatch(typeof(CharacterDummy), "GetRightDummy")]
public class CharacterDummy_GetRightDummy_Patch
{
	[HarmonyPrefix]
	public static bool CharacterDummy_GetRightDummy_Prefix(CharacterDummy __instance, ref CharacterDummy __result)
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)__instance.m_CharacterOverworld))
		{
			int dioramaTargetIndex = __instance.m_DioramaTargetIndex;
			int count = EncounterSession.Instance.m_PlayerDummies.Count;
			if (dioramaTargetIndex == count - 1)
			{
				__result = null;
				return false;
			}
			CharacterDummy playerDummyByDioramaTargetIndex = EncounterSession.Instance.GetPlayerDummyByDioramaTargetIndex(dioramaTargetIndex + 1);
			if (Object.op_Implicit((Object)(object)playerDummyByDioramaTargetIndex) && playerDummyByDioramaTargetIndex.m_CharacterOverworld.m_CharacterStats.m_IsInCombat && playerDummyByDioramaTargetIndex.m_IsAlive)
			{
				__result = playerDummyByDioramaTargetIndex;
				return false;
			}
		}
		else
		{
			_ = (EnemyDummy)__instance;
			switch (__instance.m_DioramaTargetIndex)
			{
			case 2:
				__result = null;
				return false;
			case 1:
			{
				CharacterDummy enemyDummyByDioramaTargetIndex2 = (CharacterDummy)(object)EncounterSession.Instance.GetEnemyDummyByDioramaTargetIndex(0);
				if (Object.op_Implicit((Object)(object)enemyDummyByDioramaTargetIndex2) && enemyDummyByDioramaTargetIndex2.m_IsAlive)
				{
					__result = enemyDummyByDioramaTargetIndex2;
					return false;
				}
				break;
			}
			case 0:
			{
				CharacterDummy enemyDummyByDioramaTargetIndex = (CharacterDummy)(object)EncounterSession.Instance.GetEnemyDummyByDioramaTargetIndex(2);
				if (Object.op_Implicit((Object)(object)enemyDummyByDioramaTargetIndex) && enemyDummyByDioramaTargetIndex.m_IsAlive)
				{
					__result = enemyDummyByDioramaTargetIndex;
					return false;
				}
				break;
			}
			}
		}
		__result = null;
		return false;
	}
}
[HarmonyPatch(typeof(CharacterDummy), "PlayAttackSequence")]
public class CharacterDummy_PlayAttackSequence_Patch
{
	[HarmonyPrefix]
	public static bool CharacterDummy_PlayAttackSequence_Prefix(CharacterDummy __instance, AttackAnim _attackAnim, CombatAnimTrigger _override, DummyDamageInfo _ddi, DummyDamageInfo _ddi1, DummyDamageInfo _ddi2)
	{
		//IL_0026: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Invalid comparison between Unknown and I4
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Invalid comparison between Unknown and I4
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Invalid comparison between Unknown and I4
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Invalid comparison between Unknown and I4
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Invalid comparison between Unknown and I4
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Invalid comparison between Unknown and I4
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Invalid comparison between Unknown and I4
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_0450: Expected I4, but got Unknown
		//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aad: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ab6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_066d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0725: Unknown result type (might be due to invalid IL or missing references)
		//IL_072e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0805: Unknown result type (might be due to invalid IL or missing references)
		//IL_080e: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_098f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0998: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a62: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)"PlayAttackSequence");
		if (__instance is EnemyDummy)
		{
			EncounterSession.Instance.m_HasEnemyAttacked = true;
		}
		CharacterDummy dummyByFID = EncounterSession.Instance.GetDummyByFID(_ddi.m_VictimID);
		string empty = string.Empty;
		empty = ((!(__instance is EnemyDummy)) ? ((object)Unsafe.As<ID, ID>(ref __instance.m_CharacterOverworld.m_WeaponID)/*cast due to .constrained prefix*/).ToString() : ((Object)((EnemyInfo)(EnemyDummy)__instance).m_EnemyCombat.m_WeaponAsset).name);
		string text = "[PlayAttackSequence] " + __instance.GameLogID + " attacking " + dummyByFID.GameLogID;
		string text2 = text;
		text = string.Concat(text2, " with ", empty, "(", _ddi.m_Prof, ")");
		text = text + ", expected result: " + ((object)Unsafe.As<AttackResponse, AttackResponse>(ref _ddi.m_AttackResponse)/*cast due to .constrained prefix*/).ToString();
		EncounterSession.Instance.AddCombatEventToActiveLogEntry(text, false);
		__instance.m_AttackInfo = _ddi;
		__instance.m_PostAttackHealthMod = _ddi.m_AttackerHealthMod;
		bool flag = false;
		if ((int)__instance.m_AttackInfo.m_Prof != -1)
		{
			if (FTK_proficiencyTableDB.Get(__instance.m_AttackInfo.m_Prof).m_Suicide)
			{
				if (__instance is EnemyDummy)
				{
					__instance.m_PostAttackHealthMod = ((EnemyInfo)(EnemyDummy)__instance).m_CurrentHealth;
				}
				else
				{
					__instance.m_PostAttackHealthMod = __instance.m_CharacterOverworld.m_CharacterStats.m_HealthCurrent;
				}
			}
			if (FTK_proficiencyTableDB.Get(__instance.m_AttackInfo.m_Prof).m_GunShot)
			{
				flag = true;
			}
		}
		__instance.m_ActionAnimationPlayed = true;
		if ((int)_ddi.m_WeaponType == 6)
		{
			bool flag2 = (bool)AccessTools.Method(typeof(CharacterDummy), "IsSuccessLuteAttack", (Type[])null, (Type[])null).Invoke(null, new object[1] { _ddi });
			bool flag3 = (bool)AccessTools.Method(typeof(CharacterDummy), "IsSuccessLuteAttack", (Type[])null, (Type[])null).Invoke(null, new object[1] { _ddi1 });
			bool flag4 = (bool)AccessTools.Method(typeof(CharacterDummy), "IsSuccessLuteAttack", (Type[])null, (Type[])null).Invoke(null, new object[1] { _ddi2 });
			bool luteHitMiss = flag2 || flag3 || flag4;
			__instance.m_EventListener.SetLuteHitMiss(luteHitMiss);
		}
		else if ((int)_ddi.m_WeaponType == 11 && flag)
		{
			__instance.SetCurrentAmmo(__instance.m_CurrentAmmo - 1);
			Debug.Log((object)(__instance.m_CurrentAmmo + " ammo remaining"));
		}
		if (_ddi.m_ProfSuccess)
		{
			bool flag5 = true;
			if (__instance is EnemyDummy)
			{
				flag5 = false;
			}
			else if ((int)_ddi.m_SpecialAttack > 0)
			{
				flag5 = false;
			}
			else if ((int)_ddi.m_Prof != -1 && !FTK_proficiencyTableDB.GetDB().GetEntry(_ddi.m_Prof).m_FullSlots)
			{
				flag5 = false;
			}
			if (flag5)
			{
				__instance.SpawnHudTextRPC(FTKHub.Localized<TextMisc>("STR_HudPerfect"), string.Empty, (HudTextID)4, (ID)(-1));
			}
			__instance.m_DummyFX.ProficiencyFXOn(_ddi.m_Prof);
		}
		else if ((int)_ddi.m_AttackResponse == 8 && (int)_ddi.m_DamageType == 1)
		{
			HitEffectManager.Instance.GetFizzleEffect().Play(__instance.m_EventListener, _ddi, (Flag)2, true);
			__instance.SpawnHudTextRPC(FTKHub.Localized<TextMisc>("STR_HudFizzle"), string.Empty, (HudTextID)4, (ID)(-1));
		}
		CharacterDummy dummyByFID2 = EncounterSession.Instance.GetDummyByFID(__instance.m_AttackInfo.m_VictimID);
		dummyByFID2.SetDefendType(__instance, _ddi);
		dummyByFID2.m_OtherVictims.Clear();
		if (Main.combatAoeReworksDDI_list_receive.Count == 0)
		{
			Main.combatAoeReworksDDI_list_receive.Add(_ddi1);
			Main.combatAoeReworksDDI_list_receive.Add(_ddi2);
		}
		Debug.Log((object)(" [CharacterDummy_PlayAttackSequence_Prefix] combatAoeReworksDDI_list_receive 长度为: " + Main.combatAoeReworksDDI_list_receive.Count));
		foreach (DummyDamageInfo item in Main.combatAoeReworksDDI_list_receive)
		{
			if (item != null)
			{
				__instance.m_PostAttackHealthMod += item.m_AttackerHealthMod;
				CharacterDummy dummyByFID3 = EncounterSession.Instance.GetDummyByFID(item.m_VictimID);
				dummyByFID3.SetDefendType(__instance, item);
				if (!dummyByFID2.m_OtherVictims.Contains(dummyByFID3))
				{
					dummyByFID2.m_OtherVictims.Add(dummyByFID3);
				}
			}
		}
		Main.combatAoeReworksDDI_list.Clear();
		Main.combatAoeReworksDDI_list_receive.Clear();
		switch ((int)_ddi.m_SpecialAttack)
		{
		case 1:
		{
			IEnumerator enumerator9 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[5]
			{
				typeof(ID),
				typeof(AttackAnim),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo)
			}, (Type[])null).Invoke(__instance, new object[5] { 4, _attackAnim, _ddi, _ddi1, _ddi2 });
			((MonoBehaviour)__instance).StartCoroutine(enumerator9);
			return false;
		}
		case 4:
		{
			IEnumerator enumerator8 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[8]
			{
				typeof(AttackAnim),
				typeof(CombatAnimTrigger),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(CombatAnimTrigger),
				typeof(string),
				typeof(string)
			}, (Type[])null).Invoke(__instance, new object[8]
			{
				_attackAnim,
				_override,
				_ddi,
				_ddi1,
				_ddi2,
				15,
				string.Empty,
				string.Empty
			});
			((MonoBehaviour)__instance).StartCoroutine(enumerator8);
			return false;
		}
		case 6:
		{
			IEnumerator enumerator7 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[5]
			{
				typeof(ID),
				typeof(AttackAnim),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo)
			}, (Type[])null).Invoke(__instance, new object[5] { 5, _attackAnim, _ddi, _ddi1, _ddi2 });
			((MonoBehaviour)__instance).StartCoroutine(enumerator7);
			return false;
		}
		case 7:
		{
			IEnumerator enumerator6 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[8]
			{
				typeof(AttackAnim),
				typeof(CombatAnimTrigger),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(CombatAnimTrigger),
				typeof(string),
				typeof(string)
			}, (Type[])null).Invoke(__instance, new object[8]
			{
				_attackAnim,
				_override,
				_ddi,
				_ddi1,
				_ddi2,
				15,
				FTKHub.Localized<TextMisc>("STR_HudIlluminate"),
				"Play_com_abi_justice"
			});
			((MonoBehaviour)__instance).StartCoroutine(enumerator6);
			return false;
		}
		case 8:
		{
			IEnumerator enumerator5 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[8]
			{
				typeof(AttackAnim),
				typeof(CombatAnimTrigger),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(CombatAnimTrigger),
				typeof(string),
				typeof(string)
			}, (Type[])null).Invoke(__instance, new object[8]
			{
				_attackAnim,
				_override,
				_ddi,
				_ddi1,
				_ddi2,
				15,
				FTKHub.Localized<TextMisc>("STR_HudDarkness"),
				string.Empty
			});
			((MonoBehaviour)__instance).StartCoroutine(enumerator5);
			return false;
		}
		case 9:
		{
			IEnumerator enumerator4 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[5]
			{
				typeof(ID),
				typeof(AttackAnim),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo)
			}, (Type[])null).Invoke(__instance, new object[5] { 6, _attackAnim, _ddi, _ddi1, _ddi2 });
			((MonoBehaviour)__instance).StartCoroutine(enumerator4);
			return false;
		}
		case 10:
		{
			__instance.m_CharacterDummyFSM.SendEvent("StanceSelected");
			IEnumerator enumerator3 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[8]
			{
				typeof(AttackAnim),
				typeof(CombatAnimTrigger),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(CombatAnimTrigger),
				typeof(string),
				typeof(string)
			}, (Type[])null).Invoke(__instance, new object[8]
			{
				_attackAnim,
				_override,
				_ddi,
				_ddi1,
				_ddi2,
				24,
				FTKHub.Localized<TextMisc>("STR_HudReloading"),
				string.Empty
			});
			((MonoBehaviour)__instance).StartCoroutine(enumerator3);
			return false;
		}
		case 11:
		{
			__instance.m_CharacterDummyFSM.SendEvent("StanceSelected");
			IEnumerator enumerator2 = (IEnumerator)AccessTools.Method(typeof(CharacterDummy), "WaitPlayCharacterAbilityEvent", new Type[5]
			{
				typeof(ID),
				typeof(AttackAnim),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo),
				typeof(DummyDamageInfo)
			}, (Type[])null).Invoke(__instance, new object[5] { 20, _attackAnim, _ddi, _ddi1, _ddi2 });
			((MonoBehaviour)__instance).StartCoroutine(enumerator2);
			return false;
		}
		default:
			AccessTools.Method(typeof(CharacterDummy), "PlayAttackSequenceComplete", (Type[])null, (Type[])null).Invoke(__instance, new object[5] { _attackAnim, _override, _ddi, _ddi1, _ddi2 });
			return false;
		}
	}
}
[HarmonyPatch(typeof(DamageCalculator), "_finishEngageAttack")]
public class DamageCalculator__finishEngageAttack_Patch
{
	[HarmonyPrefix]
	public static bool DamageCalculator__finishEngageAttack_Prefix(AttackAttempt _aa, float _dmgMod, float _aoeDmgMod, TargetType _targetType, bool _targetFriendly, bool _consumable, AttackCheatType _cheatType)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: 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_0009: Invalid comparison between Unknown and I4
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Invalid comparison between Unknown and I4
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Invalid comparison between Unknown and I4
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Expected O, but got Unknown
		//IL_002c: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Expected O, but got Unknown
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Invalid comparison between Unknown and I4
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Expected O, but got Unknown
		SpecialAttack specialAttack = _aa.m_SpecialAttack;
		if ((int)specialAttack != 1)
		{
			if ((int)specialAttack == 5)
			{
			}
		}
		else if ((int)_targetType == 0)
		{
			_targetType = (TargetType)1;
		}
		DummyDamageInfo val = null;
		if ((int)_targetType == 4)
		{
			AttackAttempt val2 = _aa;
			val2.m_AttackProficiency = (ID)(-1);
			val2.m_Harmless = true;
			val = (DummyDamageInfo)AccessTools.Method(typeof(DamageCalculator), "_calcDamage", (Type[])null, (Type[])null).Invoke(null, new object[5] { val2, 0f, true, _consumable, _cheatType });
		}
		else
		{
			val = (DummyDamageInfo)AccessTools.Method(typeof(DamageCalculator), "_calcDamage", (Type[])null, (Type[])null).Invoke(null, new object[5]
			{
				_aa,
				_dmgMod * _aoeDmgMod,
				true,
				_consumable,
				_cheatType
			});
		}
		_aa.m_AoeTargets = EncounterSession.Instance.GetAoeTargets(_aa.m_DamagedDummy, _targetType, (List<DefendMarkerType>)null);
		List<DummyDamageInfo> list = new List<DummyDamageInfo>();
		if (_aa.m_AoeTargets.Count > 0)
		{
			foreach (CharacterDummy aoeTarget in _aa.m_AoeTargets)
			{
				Debug.Log((object)(" [DamageCalculator__finishEngageAttack] 获取的AOE对象为:  " + aoeTarget.GameLogID));
				AttackAttempt val3 = _aa;
				val3.m_DamagedDummy = aoeTarget;
				val3.m_VictimHealthStart = val3.m_DamagedDummy.GetCurrentHealth();
				if ((int)_targetType == 1)
				{
					_aoeDmgMod = 0.5f;
				}
				object obj = AccessTools.Method(typeof(DamageCalculator), "_calcDamage", (Type[])null, (Type[])null).Invoke(null, new object[5]
				{
					val3,
					_dmgMod * _aoeDmgMod,
					false,
					_consumable,
					_cheatType
				});
				list.Add((DummyDamageInfo)obj);
			}
			foreach (DummyDamageInfo item in list)
			{
				if (!Main.combatAoeReworksDDI_list.Contains(item))
				{
					Main.combatAoeReworksDDI_list.Add(item);
					Debug.Log((object)(" [DamageCalculator__finishEngageAttack] 目标为 " + ((object)Unsafe.As<AttackResponse, AttackResponse>(ref item.m_AttackResponse)/*cast due to .constrained prefix*/).ToString()));
				}
			}
			if (Main.combatAoeReworksDDI_list.Count >= 3)
			{
				Main instance = Main.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance._SyncAttactAoeRPC();
				}
				else
				{
					Debug.LogError((object)"Unable to find the RPCPatchPlugin instance.");
				}
			}
		}
		AccessTools.Method(typeof(DamageCalculator), "_playAttackSequence", (Type[])null, (Type[])null).Invoke(null, new object[4]
		{
			_aa,
			val,
			(list.Count <= 0) ? null : list[0],
			(list.Count <= 1) ? null : list[1]
		});
		return false;
	}
}
[HarmonyPatch(typeof(EncounterSession), "GetAoeTargets")]
public class EncounterSession_GetAoeTargets_Patch
{
	[HarmonyPrefix]
	public static bool EncounterSession_GetAoeTargets_Prefix(ref List<CharacterDummy> __result, EncounterSession __instance, CharacterDummy _target, TargetType _targetType, List<DefendMarkerType> _markerTypes = null)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected I4, but got Unknown
		List<CharacterDummy> list = new List<CharacterDummy>();
		int num = (int)_targetType;
		_markerTypes?.Clear();
		if (num == 3)
		{
			__result = list;
			return false;
		}
		if (num == 2 || num == 4)
		{
			if (_target is EnemyDummy)
			{
				foreach (EnemyDummy value in __instance.m_EnemyDummies.Values)
				{
					if (!((Object)(object)value == (Object)(object)_target) && ((EnemyInfo)value).m_CurrentHealth > 0 && !((CharacterDummy)value).m_DidFlee)
					{
						list.Add((CharacterDummy)(object)value);
						_markerTypes?.Add((DefendMarkerType)1);
					}
				}
			}
			else
			{
				foreach (CharacterDummy value2 in __instance.m_PlayerDummies.Values)
				{
					if (!((Object)(object)value2 == (Object)(object)_target))
					{
						CharacterOverworld characterOverworld = value2.m_CharacterOverworld;
						if (characterOverworld.m_CharacterStats.m_IsInCombat && characterOverworld.m_CharacterStats.m_HealthCurrent > 0)
						{
							list.Add(characterOverworld.m_CurrentDummy);
							_markerTypes?.Add((DefendMarkerType)1);
						}
					}
				}
			}
		}
		else if (num == 1)
		{
			CharacterDummy leftDummy = _target.GetLeftDummy();
			if (Object.op_Implicit((Object)(object)leftDummy))
			{
				list.Add(leftDummy);
				_markerTypes?.Add((DefendMarkerType)3);
			}
			CharacterDummy rightDummy = _target.GetRightDummy();
			if (Object.op_Implicit((Object)(object)rightDummy))
			{
				list.Add(rightDummy);
				_markerTypes?.Add((DefendMarkerType)4);
			}
		}
		__result = list;
		return false;
	}
}
public static class ConfigHandler
{
	public static ConfigEntry<int> MaxPlayersConfig { get; private set; }

	public static ConfigEntry<bool> TurnReminderEnabledConfig { get; private set; }

	public static ConfigEntry<int> TurnReminderIdleSecondsConfig { get; private set; }

	public static void InitializeConfig()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		string text = Path.Combine(Paths.ConfigPath, "MultiMaxRework.cfg");
		ConfigFile val = new ConfigFile(text, true);
		MaxPlayersConfig = val.Bind<int>("General", "MaxPlayers", 5, "The max number of players");
		TurnReminderEnabledConfig = val.Bind<bool>("Turn Reminder", "Enabled", true, "Show a reminder to pass the turn after inactivity on the overworld.");
		TurnReminderIdleSecondsConfig = val.Bind<int>("Turn Reminder", "IdleSeconds", 30, "Seconds without input before the reminder appears (5-600).");
		if (!File.Exists(text))
		{
			val.Save();
		}
	}

	public static void InitializeMaxPlayers()
	{
		if (MaxPlayersConfig != null)
		{
			GameFlowMC.gMaxPlayers = MaxPlayersConfig.Value;
			GameFlowMC.gMaxEnemies = GameFlowMC.gMaxPlayers;
			uiQuickPlayerCreate.Default_Classes = new int[GameFlowMC.gMaxPlayers];
		}
		else
		{
			Debug.LogError((object)"maxPlayersConfig is not initialized!");
		}
	}
}
public static class DummiesHandler
{
	public static void CreateDummies()
	{
		Debug.Log((object)"MAKING DUMMIES");
		List<GameObject> list = new List<GameObject>();
		for (int i = 0; i < Mathf.Max(3, GameFlowMC.gMaxPlayers); i++)
		{
			if (i < 3)
			{
				list.Add(FTKHub.Instance.m_Dummies[i]);
				continue;
			}
			GameObject val = Object.Instantiate<GameObject>(FTKHub.Instance.m_Dummies[2], FTKHub.Instance.m_Dummies[2].transform.parent);
			((Object)val).name = "Player " + (i + 1) + " Dummy";
			val.GetComponent<PhotonView>().viewID = 3245 + i;
			list.Add(val);
		}
		for (int j = 0; j < Mathf.Max(3, GameFlowMC.gMaxEnemies); j++)
		{
			if (j < 3)
			{
				list.Add(FTKHub.Instance.m_Dummies[j + 3]);
				continue;
			}
			GameObject val2 = Object.Instantiate<GameObject>(FTKHub.Instance.m_Dummies[5], FTKHub.Instance.m_Dummies[5].transform.parent);
			((Object)val2).name = "Enemy " + (j + 1) + " Dummy";
			val2.GetComponent<PhotonView>().viewID = 3045 + j;
			list.Add(val2);
		}
		FTKHub.Instance.m_Dummies = list.ToArray();
		_ = FTKHub.Instance.m_Dummies;
		Debug.Log((object)"MultiMax - Done");
	}

	public static GameObject CreateDummy(GameObject[] source, int index, string prefix)
	{
		GameObject val;
		if (index < 3)
		{
			val = source[index];
		}
		else
		{
			val = Object.Instantiate<GameObject>(source[2], source[2].transform.parent);
			((Object)val).name = $"{prefix} {index + 1} Dummy";
			val.GetComponent<PhotonView>().viewID = 3245 + index;
		}
		return val;
	}
}
public static class DiagnosticLogger
{
	public const string BuildId = "FTK-MultiMax-Reforged-Lucario-2026-10-14";

	private static readonly object FileLock = new object();

	private static string _logPath;

	private static bool _initialized;

	public static string LogPath => _logPath;

	public static void Initialize()
	{
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Expected O, but got Unknown
		if (_initialized)
		{
			return;
		}
		_initialized = true;
		try
		{
			if (!string.IsNullOrEmpty(Paths.PluginPath))
			{
				_logPath = Path.Combine(Paths.PluginPath, "FTK-MultiMax-Reforged-Lucario-diagnostic.log");
				Directory.CreateDirectory(Paths.PluginPath);
				using (new FileStream(_logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
				{
				}
			}
		}
		catch
		{
			_logPath = null;
		}
		if (string.IsNullOrEmpty(_logPath))
		{
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				if (!string.IsNullOrEmpty(directoryName))
				{
					string text = Path.Combine(directoryName, "FTK-MultiMax-Reforged-Lucario-diagnostic.log");
					using (new FileStream(text, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
					{
					}
					_logPath = text;
				}
			}
			catch
			{
				_logPath = null;
			}
		}
		if (string.IsNullOrEmpty(_logPath))
		{
			try
			{
				string text2 = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BepInEx"), "plugins");
				Directory.CreateDirectory(text2);
				string text3 = Path.Combine(text2, "FTK-MultiMax-Reforged-Lucario-diagnostic.log");
				using (new FileStream(text3, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
				{
				}
				_logPath = text3;
			}
			catch
			{
				_logPath = null;
			}
		}
		if (string.IsNullOrEmpty(_logPath))
		{
			_logPath = Path.Combine(Path.GetTempPath(), "FTK-MultiMax-Reforged-Lucario-diagnostic.log");
		}
		try
		{
			Application.logMessageReceivedThreaded += new LogCallback(OnUnityLog);
		}
		catch
		{
		}
		try
		{
			AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
		}
		catch
		{
		}
		string text4 = "<unknown>";
		string text5 = "<unknown>";
		string text6 = "<unknown>";
		try
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			text4 = executingAssembly.Location;
			text5 = executingAssembly.FullName;
			text6 = executingAssembly.ManifestModule.ModuleVersionId.ToString("D");
		}
		catch
		{
		}
		Write("BOOT", "BUILD=FTK-MultiMax-Reforged-Lucario-2026-10-14; Assembly=" + text5 + "; MVID=" + text6 + "; AssemblyLocation=" + text4 + "; LogPath=" + _logPath + "; GameBase=" + AppDomain.CurrentDomain.BaseDirectory + "; BepInExPluginPath=" + SafePluginPath());
		Write("INFO", "This logger records managed exceptions and the last instrumented game method. For native/Mono fail-fast crashes, also inspect the Windows dump.");
	}

	private static string SafePluginPath()
	{
		try
		{
			return Paths.PluginPath ?? "<null>";
		}
		catch (Exception ex)
		{
			return "<unavailable: " + ex.GetType().Name + ">";
		}
	}

	public static void Register(Harmony harmony, Type targetType, string methodName)
	{
		Register(harmony, targetType, methodName, null);
	}

	public static void Register(Harmony harmony, Type targetType, string methodName, Type[] parameterTypes)
	{
		if (harmony == null || (object)targetType == null || string.IsNullOrEmpty(methodName))
		{
			Write("WARN", "DIAG PATCH SKIPPED: invalid registration arguments for " + (((object)targetType == null) ? "<null type>" : targetType.FullName) + "." + methodName);
			return;
		}
		if (parameterTypes != null)
		{
			MethodInfo methodInfo = null;
			try
			{
				methodInfo = AccessTools.Method(targetType, methodName, parameterTypes, (Type[])null);
			}
			catch (Exception ex)
			{
				Write("ERROR", "Could not resolve exact diagnostic target " + targetType.FullName + "." + methodName + Signature(parameterTypes) + ": " + ex);
				return;
			}
			if ((object)methodInfo == null)
			{
				Write("WARN", "DIAG PATCH NOT FOUND: " + targetType.FullName + "." + methodName + Signature(parameterTypes));
			}
			else
			{
				InstrumentMethod(harmony, methodInfo);
			}
			return;
		}
		MethodInfo[] declaredMethods = GetDeclaredMethods(targetType, methodName);
		if (declaredMethods.Length == 0)
		{
			MethodInfo methodInfo2 = null;
			try
			{
				methodInfo2 = AccessTools.Method(targetType, methodName, (Type[])null, (Type[])null);
			}
			catch
			{
			}
			if ((object)methodInfo2 != null && (object)methodInfo2.DeclaringType != targetType)
			{
				Write("WARN", "Skipped diagnostic wrapper for " + targetType.FullName + "." + methodName + ": resolves to inherited method " + MethodName(methodInfo2) + ". Supply an exact parameter signature only if this inherited method should be monitored.");
			}
			else
			{
				Write("WARN", "DIAG PATCH NOT FOUND: declared method " + targetType.FullName + "." + methodName);
			}
		}
		else
		{
			for (int i = 0; i < declaredMethods.Length; i++)
			{
				InstrumentMethod(harmony, declaredMethods[i]);
			}
		}
	}

	private static void InstrumentMethod(Harmony harmony, MethodInfo original)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		try
		{
			HarmonyMethod val = new HarmonyMethod(typeof(DiagnosticLogger), "BeforeOriginal", (Type[])null);
			HarmonyMethod val2 = new HarmonyMethod(typeof(DiagnosticLogger), "AfterOriginal", (Type[])null);
			try
			{
				val.priority = 800;
			}
			catch
			{
			}
			try
			{
				val2.priority = 0;
			}
			catch
			{
			}
			PatchProcessor obj3 = harmony.CreateProcessor((MethodBase)original);
			obj3.AddPrefix(val);
			obj3.AddFinalizer(val2);
			obj3.Patch();
			Write("INFO", "Instrumentation attached: " + MethodName(original));
		}
		catch (Exception ex)
		{
			Write("ERROR", "Could not instrument " + MethodName(original) + ": " + ex);
		}
	}

	private static string Signature(Type[] parameterTypes)
	{
		StringBuilder stringBuilder = new StringBuilder("(");
		if (parameterTypes != null)
		{
			for (int i = 0; i < parameterTypes.Length; i++)
			{
				if (i > 0)
				{
					stringBuilder.Append(", ");
				}
				stringBuilder.Append(((object)parameterTypes[i] == null) ? "<null>" : (parameterTypes[i].FullName ?? parameterTypes[i].Name));
			}
		}
		stringBuilder.Append(")");
		return stringBuilder.ToString();
	}

	public static void RegisterExceptionMonitor(Harmony harmony, Type targetType, string methodName)
	{
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		MethodInfo[] declaredMethods = GetDeclaredMethods(targetType, methodName);
		if (declaredMethods.Length == 0)
		{
			MethodInfo methodInfo = null;
			try
			{
				methodInfo = AccessTools.Method(targetType, methodName, (Type[])null, (Type[])null);
			}
			catch
			{
			}
			if ((object)methodInfo != null && (object)methodInfo.DeclaringType != targetType)
			{
				Write("WARN", "Skipped exception monitor for " + targetType.FullName + "." + methodName + ": name resolves to inherited method " + MethodName(methodInfo) + ".");
			}
			else
			{
				Write("WARN", "DIAG EXCEPTION MONITOR NOT FOUND: declared method " + targetType.FullName + "." + methodName);
			}
			return;
		}
		foreach (MethodInfo methodInfo2 in declaredMethods)
		{
			try
			{
				HarmonyMethod val = new HarmonyMethod(typeof(DiagnosticLogger), "RecordExceptionOnly", (Type[])null);
				try
				{
					val.priority = 0;
				}
				catch
				{
				}
				PatchProcessor obj3 = harmony.CreateProcessor((MethodBase)methodInfo2);
				obj3.AddFinalizer(val);
				obj3.Patch();
				Write("INFO", "Exception-only monitor attached: " + MethodName(methodInfo2));
			}
			catch (Exception ex)
			{
				Write("ERROR", "Could not monitor exceptions for " + MethodName(methodInfo2) + ": " + ex);
			}
		}
	}

	private static MethodInfo[] GetDeclaredMethods(Type targetType, string methodName)
	{
		if ((object)targetType == null || string.IsNullOrEmpty(methodName))
		{
			return new MethodInfo[0];
		}
		MethodInfo[] methods = targetType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		ArrayList arrayList = new ArrayList();
		for (int i = 0; i < methods.Length; i++)
		{
			if (string.Equals(methods[i].Name, methodName, StringComparison.Ordinal))
			{
				arrayList.Add(methods[i]);
			}
		}
		MethodInfo[] array = new MethodInfo[arrayList.Count];
		arrayList.CopyTo(array);
		return array;
	}

	public static Exception RecordExceptionOnly(Exception __exception, MethodBase __originalMethod)
	{
		if (__exception != null)
		{
			Write("EXCEPTION", MethodName(__originalMethod) + " threw: " + __exception);
		}
		return __exception;
	}

	public static void BeforeOriginal(MethodBase __originalMethod)
	{
		Write("ENTER", MethodName(__originalMethod));
	}

	public static Exception AfterOriginal(Exception __exception, MethodBase __originalMethod)
	{
		if (__exception != null)
		{
			Write("EXCEPTION", MethodName(__originalMethod) + " threw: " + __exception);
		}
		else
		{
			Write("EXIT", MethodName(__originalMethod));
		}
		return __exception;
	}

	public static void Mark(string message)
	{
		Write("MARK", message);
	}

	private static string MethodName(MethodBase method)
	{
		if ((object)method == null)
		{
			return "<unknown method>";
		}
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(((object)method.DeclaringType == null) ? "<unknown type>" : method.DeclaringType.FullName);
		stringBuilder.Append(".").Append(method.Name).Append("(");
		ParameterInfo[] parameters = method.GetParameters();
		for (int i = 0; i < parameters.Length; i++)
		{
			if (i > 0)
			{
				stringBuilder.Append(", ");
			}
			Type parameterType = parameters[i].ParameterType;
			stringBuilder.Append(((object)parameterType == null) ? "?" : (parameterType.FullName ?? parameterType.Name));
		}
		stringBuilder.Append(")");
		return stringBuilder.ToString();
	}

	private unsafe static void OnUnityLog(string condition, string stackTrace, LogType type)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Invalid comparison between Unknown and I4
		//IL_0004: 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_0009: Invalid comparison between Unknown and I4
		if ((int)type == 4 || (int)type == 0 || (int)type == 1)
		{
			string text = condition ?? "<empty Unity log message>";
			if (!string.IsNullOrEmpty(stackTrace))
			{
				text = text + Environment.NewLine + stackTrace;
			}
			Write("UNITY-" + ((object)(*(LogType*)(&type))/*cast due to .constrained prefix*/).ToString().ToUpperInvariant(), text);
		}
	}

	private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
	{
		string text = "IsTerminating=" + args.IsTerminating + Environment.NewLine;
		text += ((args.ExceptionObject == null) ? "ExceptionObject=<null>" : args.ExceptionObject.ToString());
		Write("APPDOMAIN-UNHANDLED", text);
	}

	private static void Write(string level, string message)
	{
		string line;
		try
		{
			line = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " [" + level + "] " + (message ?? "<null>") + Environment.NewLine;
		}
		catch
		{
			return;
		}
		try
		{
			lock (FileLock)
			{
				string text = _logPath;
				if (string.IsNullOrEmpty(text))
				{
					text = Path.Combine(Path.GetTempPath(), "FTK-MultiMax-Reforged-Lucario-diagnostic.log");
				}
				try
				{
					AppendLine(text, line);
				}
				catch
				{
					string text2 = Path.Combine(Path.GetTempPath(), "FTK-MultiMax-Reforged-Lucario-diagnostic.log");
					if (!string.Equals(text, text2, StringComparison.OrdinalIgnoreCase))
					{
						AppendLine(text2, line);
						_logPath = text2;
					}
				}
			}
		}
		catch
		{
		}
	}

	private static void AppendLine(string path, string line)
	{
		using FileStream fileStream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
		byte[] bytes = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false).GetBytes(line);
		fileStream.Write(bytes, 0, bytes.Length);
		fileStream.Flush();
	}
}
public static class DioramaPatches
{
	public static void DummySlide()
	{
		DiagnosticLogger.Mark("PATCH DioramaPatches.DummySlide: entered.");
		DummyAttackSlide[] array = Object.FindObjectsOfType<DummyAttackSlide>();
		DiagnosticLogger.Mark("PATCH DioramaPatches.DummySlide: slides=" + ((array == null) ? (-1) : array.Length));
		DummyAttackSlide[] array2 = array;
		foreach (DummyAttackSlide val in array2)
		{
			if (!((Object)(object)val == (Object)null) && val.m_Distances != null && val.m_Distances.Length < 1000)
			{
				float[] array3 = new float[1000];
				Array.Copy(val.m_Distances, array3, val.m_Distances.Length);
				val.m_Distances = array3;
				Main.Log("Expanded dummy slide distances to 1000 entries.");
			}
		}
	}

	public static void SortTargets(ref List<Transform> __2)
	{
		int num = ((__2 == null) ? (-1) : __2.Count);
		DiagnosticLogger.Mark("PATCH DioramaPatches.SortTargets: argumentIndex=2; targetCount=" + num);
		if (__2 == null || num < 2)
		{
			return;
		}
		if (num > 512)
		{
			DiagnosticLogger.Mark("WARN SortTargets skipped: implausible targetCount=" + num);
			return;
		}
		int num2 = Math.Max(0, GameFlowMC.gMaxPlayers);
		for (int i = 0; i < num2; i++)
		{
			for (int j = 0; j < __2.Count - 1; j++)
			{
				Transform val = __2[j];
				Transform val2 = __2[j + 1];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && ((Object)val).name.Contains("Player ") && ((Object)val2).name.Contains("Player "))
				{
					Match match = Regex.Match(((Object)val).name, "\\d+");
					Match match2 = Regex.Match(((Object)val2).name, "\\d+");
					if (match.Success && match2.Success && int.TryParse(match.Value, out var result) && int.TryParse(match2.Value, out var result2) && result > result2)
					{
						__2[j] = val2;
						__2[j + 1] = val;
					}
				}
			}
		}
	}
}
public static class SceneDioramaPatches
{
	private static int _nonSceneAwakeCalls;

	private static int _emptyDioramaCalls;

	public static void FixDummyPositions(object __instance)
	{
		SceneDiorama val = (SceneDiorama)((__instance is SceneDiorama) ? __instance : null);
		if ((Object)(object)val == (Object)null)
		{
			int num = Interlocked.Increment(ref _nonSceneAwakeCalls);
			if (num <= 3 || num % 500 == 0)
			{
				DiagnosticLogger.Mark("PATCH FixDummyPositions: skipped non-SceneDiorama Awake; runtimeType=" + ((__instance == null) ? "<null>" : __instance.GetType().FullName) + "; skippedCount=" + num);
			}
			return;
		}
		Diorama[] componentsInChildren = ((Component)val).GetComponentsInChildren<Diorama>();
		if (componentsInChildren == null || componentsInChildren.Length == 0)
		{
			int num2 = Interlocked.Increment(ref _emptyDioramaCalls);
			if (num2 <= 3 || num2 % 100 == 0)
			{
				DiagnosticLogger.Mark("PATCH FixDummyPositions: SceneDiorama has no child Diorama; emptyCallCount=" + num2);
			}
			return;
		}
		DiagnosticLogger.Mark("PATCH FixDummyPositions: runtimeType=" + ((object)val).GetType().FullName + "; dioramaCount=" + componentsInChildren.Length);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if ((Object)(object)componentsInChildren[i] != (Object)null)
			{
				FixDiorama(componentsInChildren[i]);
			}
		}
	}

	public static void ApplyCurrentPlayerCount()
	{
		SceneDiorama[] array = Object.FindObjectsOfType<SceneDiorama>();
		if (array == null)
		{
			return;
		}
		for (int i = 0; i < array.Length; i++)
		{
			if ((Object)(object)array[i] == (Object)null)
			{
				continue;
			}
			Diorama[] componentsInChildren = ((Component)array[i]).GetComponentsInChildren<Diorama>();
			if (componentsInChildren == null)
			{
				continue;
			}
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				if ((Object)(object)componentsInChildren[j] != (Object)null)
				{
					FixDiorama(componentsInChildren[j]);
				}
			}
		}
	}

	private static void FixDiorama(Diorama diorama)
	{
		if ((Object)(object)diorama == (Object)null || diorama.m_LayoutTable == null)
		{
			return;
		}
		Main.Log("Fixing dummy positions for " + ((Object)diorama).name);
		DiagnosticLogger.Mark("PATCH SceneDioramaPatches.FixDiorama: " + ((Object)diorama).name + "; layouts=" + diorama.m_LayoutTable.Count);
		foreach (Layout value in diorama.m_LayoutTable.Values)
		{
			if (value != null && (Object)(object)value.m_TargetRoot != (Object)null)
			{
				TargetPositions.Fix(value.m_TargetRoot);
			}
		}
	}
}
public static class TargetPositions
{
	private sealed class LayoutBasis
	{
		public Vector3 Origin;

		public Vector3 Step;
	}

	private static readonly Dictionary<Transform, LayoutBasis> OriginalLayouts = new Dictionary<Transform, LayoutBasis>();

	public static void Fix(Transform targetRoot)
	{
		//IL_0065: 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)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Max(1, GameFlowMC.gMaxPlayers);
		if ((Object)(object)targetRoot == (Object)null)
		{
			return;
		}
		Transform val = targetRoot.Find("Player 2_target");
		Transform val2 = targetRoot.Find("Player 3_target");
		if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
		{
			Main.Log("Target layout missing Player 2_target or Player 3_target; skipping layout fix.");
			return;
		}
		if (!OriginalLayouts.TryGetValue(targetRoot, out var value) || value == null)
		{
			value = new LayoutBasis();
			value.Origin = val.localPosition;
			value.Step = val2.localPosition - val.localPosition;
			OriginalLayouts[targetRoot] = value;
		}
		Vector3 origin = value.Origin;
		Vector3 step = value.Step;
		Vector3 val3 = step * (float)num / 3f;
		Vector3 val4 = (val3 - step) * -0.5f;
		int siblingIndex = val.GetSiblingIndex();
		int num2 = Math.Max(5, num);
		for (int i = 0; i < num; i++)
		{
			string text = $"Player {i + 1}_target";
			Transform val5 = targetRoot.Find(text);
			if ((Object)(object)val5 == (Object)null)
			{
				GameObject obj = Object.Instantiate<GameObject>(((Component)val2).gameObject, targetRoot);
				((Object)obj).name = text;
				val5 = obj.transform;
				val5.SetSiblingIndex(siblingIndex + i);
			}
			else if (i == 0)
			{
				val5.SetSiblingIndex(siblingIndex + 1);
			}
			float num3 = ((num == 1) ? 0.5f : ((float)i / (float)(num - 1)));
			val5.localPosition = origin + val3 * num3 + val4;
			((Component)val5).gameObject.SetActive(true);
		}
		for (int j = num; j < num2; j++)
		{
			Transform val6 = targetRoot.Find($"Player {j + 1}_target");
			if ((Object)(object)val6 != (Object)null)
			{
				((Component)val6).gameObject.SetActive(false);
			}
		}
	}
}
public static class TurnReminder
{
	private const float HudSearchInterval = 0.75f;

	private static float _nextHudSearch;

	private static uiPlayerMainHud _activeHud;

	private static bool _wasGameplayActive;

	private static bool _hasMousePosition;

	private static Vector3 _lastMousePosition;

	private static float _lastActivityTime;

	private static bool _alertVisible;

	private static bool _rewiredMethodChecked;

	private static MethodInfo _rewiredAnyButtonDownMethod;

	private static Texture2D _backgroundTexture;

	private static Texture2D _borderTexture;

	private static GUIStyle _titleStyle;

	private static GUIStyle _detailStyle;

	private static GUIStyle _hintStyle;

	public static void Update()
	{
		if (!IsEnabled())
		{
			ResetReminderState();
			return;
		}
		if (!Application.isFocused)
		{
			ResetReminderState();
			RememberMousePosition();
			return;
		}
		if (!IsOverworldHudActive())
		{
			ResetReminderState();
			RememberMousePosition();
			return;
		}
		float unscaledTime = Time.unscaledTime;
		if (!_wasGameplayActive)
		{
			_wasGameplayActive = true;
			_lastActivityTime = unscaledTime;
			_alertVisible = false;
			RememberMousePosition();
		}
		else if (HasUserActivity())
		{
			_lastActivityTime = unscaledTime;
			_alertVisible = false;
		}
		else if (unscaledTime - _lastActivityTime >= (float)GetIdleDelaySeconds())
		{
			_alertVisible = true;
		}
	}

	public static void Draw()
	{
		//IL_003b: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		if (!_alertVisible || !IsEnabled())
		{
			return;
		}
		EnsureGuiResources();
		if (!((Object)(object)_backgroundTexture == (Object)null) && !((Object)(object)_borderTexture == (Object)null) && _titleStyle != null)
		{
			int depth = GUI.depth;
			Color color = GUI.color;
			GUI.depth = -10000;
			GUI.color = Color.white;
			float num = Mathf.Min(550f, (float)Screen.width - 24f);
			if (num < 260f)
			{
				num = Mathf.Max(220f, (float)Screen.width - 12f);
			}
			float num2 = ((float)Screen.width - num) * 0.5f;
			float num3 = ((float)Screen.height - 94f) * 0.5f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(num2, num3, num, 94f);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x - 2f, ((Rect)(ref val)).y - 2f, ((Rect)(ref val)).width + 4f, ((Rect)(ref val)).height + 4f), (Texture)(object)_borderTexture);
			GUI.DrawTexture(val, (Texture)(object)_backgroundTexture);
			GUI.Label(new Rect(num2 + 10f, num3 + 7f, num - 20f, 28f), "¡NO OLVIDES PASAR TURNO!", _titleStyle);
			GUI.Label(new Rect(num2 + 10f, num3 + 36f, num - 20f, 22f), "Sin actividad durante " + GetIdleDelaySeconds() + " segundos", _detailStyle);
			GUI.Label(new Rect(num2 + 10f, num3 + 60f, num - 20f, 22f), "Pulsa un botón o mueve el ratón para cerrar", _hintStyle);
			GUI.color = color;
			GUI.depth = depth;
		}
	}

	private static bool IsEnabled()
	{
		return ConfigHandler.TurnReminderEnabledConfig?.Value ?? true;
	}

	private static int GetIdleDelaySeconds()
	{
		return Mathf.Clamp(ConfigHandler.TurnReminderIdleSecondsConfig?.Value ?? 30, 5, 600);
	}

	private static bool IsOverworldHudActive()
	{
		if ((Object)(object)_activeHud != (Object)null && (Object)(object)((Component)_activeHud).gameObject != (Object)null && ((Component)_activeHud).gameObject.activeInHierarchy && (Object)(object)_activeHud.m_Cow != (Object)null)
		{
			return (Object)(object)GameLogic.Instance != (Object)null;
		}
		if (Time.unscaledTime < _nextHudSearch)
		{
			return false;
		}
		_nextHudSearch = Time.unscaledTime + 0.75f;
		_activeHud = null;
		try
		{
			Object[] array = Object.FindObjectsOfType(typeof(uiPlayerMainHud));
			foreach (Object obj in array)
			{
				uiPlayerMainHud val = (uiPlayerMainHud)(object)((obj is uiPlayerMainHud) ? obj : null);
				if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && ((Component)val).gameObject.activeInHierarchy && (Object)(object)val.m_Cow != (Object)null)
				{
					_activeHud = val;
					break;
				}
			}
		}
		catch (Exception ex)
		{
			Main.Log("Turn reminder: could not check overworld HUD: " + ex.Message);
			_activeHud = null;
		}
		if ((Object)(object)_activeHud != (Object)null)
		{
			return (Object)(object)GameLogic.Instance != (Object)null;
		}
		return false;
	}

	private static bool HasUserActivity()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		Vector3 mousePosition = Input.mousePosition;
		bool flag = _hasMousePosition && mousePosition != _lastMousePosition;
		_lastMousePosition = mousePosition;
		_hasMousePosition = true;
		if (Input.anyKey || Input.anyKeyDown || flag || Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
		{
			return true;
		}
		try
		{
			int playerCount = ReInput.players.playerCount;
			for (int i = 0; i < playerCount; i++)
			{
				object player = ReInput.players.GetPlayer(i);
				if (player != null)
				{
					if (!_rewiredMethodChecked)
					{
						_rewiredAnyButtonDownMethod = player.GetType().GetMethod("GetAnyButtonDown", BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null);
						_rewiredMethodChecked = true;
					}
					if ((object)_rewiredAnyButtonDownMethod != null && (bool)_rewiredAnyButtonDownMethod.Invoke(player, null))
					{
						return true;
					}
				}
			}
		}
		catch
		{
		}
		return false;
	}

	private static void RememberMousePosition()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		_lastMousePosition = Input.mousePosition;
		_hasMousePosition = true;
	}

	private static void ResetReminderState()
	{
		_wasGameplayActive = false;
		_lastActivityTime = Time.unscaledTime;
		_alertVisible = false;
	}

	private static void EnsureGuiResources()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Expected O, but got Unknown
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Expected O, but got Unknown
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_backgroundTexture == (Object)null)
		{
			_backgroundTexture = CreateTexture(new Color(0.157f, 0.494f, 0.663f, 1f));
		}
		if ((Object)(object)_borderTexture == (Object)null)
		{
			_borderTexture = CreateTexture(new Color(0.12f, 0.83f, 0.96f, 1f));
		}
		if (_titleStyle == null)
		{
			_titleStyle = new GUIStyle(GUI.skin.label);
			_titleStyle.alignment = (TextAnchor)4;
			_titleStyle.fontSize = 21;
			_titleStyle.fontStyle = (FontStyle)1;
			_titleStyle.normal.textColor = Color.white;
			_titleStyle.wordWrap = false;
		}
		if (_detailStyle == null)
		{
			_detailStyle = new GUIStyle(GUI.skin.label);
			_detailStyle.alignment = (TextAnchor)4;
			_detailStyle.fontSize = 15;
			_detailStyle.normal.textColor = new Color(0.8f, 0.96f, 1f, 1f);
			_detailStyle.wordWrap = false;
		}
		if (_hintStyle == null)
		{
			_hintStyle = new GUIStyle(GUI.skin.label);
			_hintStyle.alignment = (TextAnchor)4;
			_hintStyle.fontSize = 13;
			_hintStyle.normal.textColor = new Color(0.55f, 0.88f, 1f, 1f);
			_hintStyle.wordWrap = false;
		}
	}

	private static Texture2D CreateTexture(Color color)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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_0021: Expected O, but got Unknown
		Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
		val.SetPixel(0, 0, color);
		val.Apply();
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}
}
public static class EncounterSessionPatches
{
	public static void XPModifierPatch(ref FTKPlayerID _recvPlayer, ref int _xp, ref int _gold)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		CharacterOverworld characterOverworldByFID = FTKHub.Instance.GetCharacterOverworldByFID(_recvPlayer);
		float xpModifier = characterOverworldByFID.m_CharacterStats.XpModifier;
		float goldModifier = characterOverworldByFID.m_CharacterStats.GoldModifier;
		if (GameFlowMC.gMaxPlayers > 3)
		{
			_xp = Mathf.RoundToInt((float)((double)((float)_xp * xpModifier) * 1.5));
			_gold = Mathf.RoundToInt((float)((double)((float)_gold * goldModifier) * 1.5));
		}
	}
}
public static class RoomHandler
{
	public static bool CreateRoom(ref GameLogic __instance, string _roomName, bool _isOpen)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		PhotonNetwork.offlineMode = false;
		RoomOptions val = new RoomOptions();
		TypedLobby val2 = new TypedLobby();
		val.IsOpen = _isOpen;
		val.IsVisible = _isOpen;
		if ((int)__instance.m_GameMode == 0)
		{
			val.MaxPlayers = 1;
		}
		else
		{
			val.MaxPlayers = (byte)GameFlowMC.gMaxPlayers;
		}
		val2.Type = (LobbyType)0;
		PhotonNetwork.CreateRoom(_roomName, val, val2);
		return false;
	}
}
public static class SessionPlayerCountSelector
{
	private const int HardMaximum = 5;

	public const string RoomPropertyKey = "mmrwRosterCount";

	private static int _lastBlockedSlotLog = -1;

	private static int _claimSlotRpcSequence = 0;

	private static uiCharacterCreateRoot _activeRoot;

	private static uiCharacterCreateRoot _baseRoot;

	private static bool _selectionConfirmed;

	private static int _selectedCount;

	private static int _pendingCount;

	private static bool _applyPendingAfterRootSetup;

	private static Transform[] _baseCreateTargets;

	private static Vector2[] _baseCreateAnchoredPositions;

	private static Transform[] _baseCameraTargets;

	private static SelectScreenCamera _baseCameraOwner;

	private static Vector3[] _baseCameraWorldPositions;

	private static Array _baseQuickCreateArray;

	private static bool _loadOrResumeFlow;

	private static bool _newCampaignExplicitlyRequested;

	private static int _loadFlowHooksInstalled;

	private static int _newCampaignHooksInstalled;

	private static bool _guiStylesInitialized;

	private static GUIStyle _selectorPanelStyle;

	private static GUIStyle _selectorFrameStyle;

	private static GUIStyle _titleStyle;

	private static GUIStyle _helpStyle;

	private static GUIStyle _waitingStyle;

	private static GUIStyle _playerButtonStyle;

	private static GUIStyle _playerNumberStyle;

	private static GUIStyle _playerCaptionStyle;

	private static Texture2D _panelTexture;

	private static Texture2D _panelFrameTexture;

	private static Texture2D _buttonFrameTexture;

	private static Texture2D _buttonTexture;

	private static Texture2D _buttonHoverTexture;

	private static Texture2D _buttonActiveTexture;

	public static bool IsSelectionConfirmed => _selectionConfirmed;

	public static void RegisterGuards(Harmony harmony)
	{
		PatchOptional(harmony, typeof(uiCharacterCreateRoot), "Update", "CharacterCreateRootUpdatePrefix");
		PatchOptional(harmony, typeof(uiQuickPlayerCreate), "Update", "QuickPlayerCreateUpdatePrefix");
		PatchOptional(harmony, typeof(uiStartGame), "Update", "StartGameUpdatePrefix");
		PatchOptional(harmony, typeof(uiStartGame), "ClaimSlotRPC", "ClaimSlotRpcPrefix");
		RegisterCampaignFlowHooks(harmony);
	}

	private static void RegisterCampaignFlowHooks(Harmony harmony)
	{
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Expected O, but got Unknown
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Expected O, but got Unknown
		Type[] array;
		try
		{
			array = typeof(uiStartGame).Assembly.GetTypes();
		}
		catch (ReflectionTypeLoadException ex)
		{
			array = ex.Types;
		}
		catch
		{
			array = new Type[0];
		}
		MethodInfo methodInfo = AccessTools.Method(typeof(SessionPlayerCountSelector), "LoadOrResumeFlowPrefix", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(SessionPlayerCountSelector), "NewCampaignFlowPrefix", (Type[])null, (Type[])null);
		foreach (Type type in array)
		{
			if ((object)type == null || !IsCampaignFlowUiType(type))
			{
				continue;
			}
			MethodInfo[] methods;
			try
			{
				methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch
			{
				continue;
			}
			foreach (MethodInfo methodInfo3 in methods)
			{
				if ((object)methodInfo3 == null || methodInfo3.IsAbstract || methodInfo3.ContainsGenericParameters)
				{
					continue;
				}
				string name = methodInfo3.Name;
				try
				{
					if (IsLoadOrResumeEntryName(name))
					{
						harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						_loadFlowHooksInstalled++;
						Main.Log("Flexible player selector: load/resume flow hook installed on " + type.Name + "." + name);
					}
					else if (IsNewCampaignEntryName(name))
					{
						harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						_newCampaignHooksInstalled++;
						Main.Log("Flexible player selector: new-campaign flow hook installed on " + type.Name + "." + name);
					}
				}
				catch (Exception ex2)
				{
					Main.Log("Flexible player selector: could not hook campaign flow method " + type.Name + "." + name + ": " + ex2.Message);
				}
			}
		}
		Main.Log("Flexible player selector: campaign-flow hooks registered; load/resume=" + _loadFlowHooksInstalled + ", new-campaign=" + _newCampaignHooksInstalled + ".");
	}

	private static bool IsCampaignFlowUiType(Type type)
	{
		string text = type.Name.ToLowerInvariant();
		if (text == "mainscreen" || text == "continuefsmmanager")
		{
			return true;
		}
		if (!text.StartsWith("ui"))
		{
			return false;
		}
		if (!text.Contains("start") && !text.Contains("main") && !text.Contains("save") && !text.Contains("load") && !text.Contains("continue") && !text.Contains("resume") && !text.Contains("newgame") && !text.Contains("campaign"))
		{
			return text.Contains("popup");
		}
		return true;
	}

	private static bool IsLoadOrResumeEntryName(string methodName)
	{
		if (string.IsNullOrEmpty(methodName))
		{
			return false;
		}
		string text = methodName.ToLowerInvariant();
		if (text.Contains("continue") || text.Contains("resume"))
		{
			return true;
		}
		if (!text.Contains("loadgame") && !text.Contains("load_game") && !text.Contains("loadsave") && !text.Contains("load_save") && !text.Contains("loadrun") && !text.Contains("loadsession") && !text.Contains("loadslot"))
		{
			if (text.Contains("select"))
			{
				return text.Contains("save");
			}
			return false;
		}
		return true;
	}

	private static bool IsNewCampaignEntryName(string methodName)
	{
		if (string.IsNullOrEmpty(methodName))
		{
			return false;
		}
		string text = methodName.ToLowerInvariant();
		if (!text.Contains("newgame") && !text.Contains("newcampaign") && !text.Contains("newrun") && !text.Contains("startnew") && !text.Contains("createnewgame"))
		{
			return text.Contains("createcampaign");
		}
		return true;
	}

	public static void LoadOrResumeFlowPrefix(MethodBase __originalMethod)
	{
		_loadOrResumeFlow = true;
		_newCampaignExplicitlyRequested = false;
		_selectionConfirmed = true;
		_selectedCount = 0;
		_pendingCount = 0;
		_applyPendingAfterRootSetup = false;
		Main.Log("Flexible player selector: hiding roster choice for load/resume flow (" + MethodLabel(__originalMethod) + ").");
	}

	public static void NewCampaignFlowPrefix(MethodBase __originalMethod)
	{
		_loadOrResumeFlow = false;
		_newCampaignExplicitlyRequested = true;
		_selectionConfirmed = false;
		_selectedCount = 0;
		_pendingCount = 0;
		_applyPendingAfterRootSetup = false;
		_activeRoot = null;
		_claimSlotRpcSequence = 0;
		_lastBlockedSlotLog = -1;
		Main.Log("Flexible player selector: roster choice enabled for new campaign (" + MethodLabel(__originalMethod) + ").");
	}

	private static string MethodLabel(MethodBase method)
	{
		if ((object)method == null)
		{
			return "unknown method";
		}
		return (((object)method.DeclaringType == null) ? "<unknown type>" : method.DeclaringType.Name) + "." + method.Name;
	}

	private static bool DetectLoadOrResumeStateFromFlags()
	{
		if (_newCampaignExplicitlyRequested)
		{
			return false;
		}
		if (_loadOrResumeFlow)
		{
			return true;
		}
		string[] array = new string[3] { "MainScreen", "uiStartGame", "ContinueFSMManager" };
		for (int i = 0; i < array.Length; i++)
		{
			Type type = AccessTools.TypeByName(array[i]);
			if ((object)type == null)
			{
				continue;
			}
			object obj = null;
			try
			{
				obj = Object.FindObjectOfType(type);
			}
			catch
			{
			}
			FieldInfo[] fields;
			try
			{
				fields = type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch
			{
				continue;
			}
			foreach (FieldInfo fieldInfo in fields)
			{
				string text = fieldInfo.Name.ToLowerInvariant();
				if ((!text.Contains("resume") && !text.Contains("continue") && (!text.Contains("load") || (!text.Contains("save") && !text.Contains("game") && !text.Contains("session") && !text.Contains("run") && !text.Contains("slot")))) || (!fieldInfo.IsStatic && obj == null))
				{
					continue;
				}
				try
				{
					object value = fieldInfo.GetValue(fieldInfo.IsStatic ? null : obj);
					if (value is bool && (bool)value)
					{
						return true;
					}
					if (value != null && (fieldInfo.FieldType.IsEnum || value is string))
					{
						string text2 = value.ToString().ToLowerInvariant();
						if (text2.Contains("resume") || text2.Contains("continue") || text2.Contains("loadsave") || text2.Contains("load_session") || text2.Contains("loadsession"))
						{
							return true;
						}
					}
				}
				catch
				{
				}
			}
		}
		return false;
	}

	private static void PatchOptional(Harmony harmony, Type targetType, string targetName, string patchName)
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		try
		{
			MethodInfo methodInfo = AccessTools.Method(targetType, targetName, (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(SessionPlayerCountSelector), patchName, (Type[])null, (Type[])null);
			if ((object)methodInfo == null || (object)methodInfo2 == null)
			{
				Main.Log("Flexible player selector: optional input guard not installed for " + targetType.FullName + "." + targetName + "; originalFound=" + ((object)methodInfo != null));
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Main.Log("Flexible player selector: installed input guard on " + targetType.FullName + "." + targetName);
			}
		}
		catch (Exception ex)
		{
			Main.Log("Flexible player selector: could not patch " + targetType.FullName + "." + targetName + ": " + ex.Message);
		}
	}

	public static bool CharacterCreateRootUpdatePrefix(uiCharacterCreateRoot __instance)
	{
		return AllowRootUpdate(__instance);
	}

	private static bool IsWaitingForRosterChoice()
	{
		if (_loadOrResumeFlow)
		{
			return false;
		}
		uiCharacterCreateRoot activeRoot = _activeRoot;
		if (!_selectionConfirmed && (Object)(object)activeRoot != (Object)null && (Object)(object)((Component)activeRoot).gameObject != (Object)null)
		{
			return ((Component)activeRoot).gameObject.activeInHierarchy;
		}
		return false;
	}

	public static bool QuickPlayerCreateUpdatePrefix()
	{
		return !IsWaitingForRosterChoice();
	}

	public static bool StartGameUpdatePrefix()
	{
		return !IsWaitingForRosterChoice();
	}

	public static bool ClaimSlotRpcPrefix(int __0)
	{
		if (!_selectionConfirmed || _selectedCount <= 0)
		{
			return true;
		}
		uiCharacterCreateRoot activeRoot = _activeRoot;
		bool num = (Object)(object)activeRoot != (Object)null && (Object)(object)((Component)activeRoot).gameObject != (Object)null && ((Component)activeRoot).gameObject.activeInHierarchy;
		_claimSlotRpcSequence++;
		if (!num)
		{
			Main.Log("Flexible player selector DEBUG: ClaimSlotRPC #" + _claimSlotRpcSequence + " slotArg=" + __0 + ", selected=" + _selectedCount + ", rootActive=false -> ALLOW (creation screen inactive)");
			return true;
		}
		if (__0 >= 0 && __0 < _selectedCount)
		{
			Main.Log("Flexible player selector DEBUG: ClaimSlotRPC #" + _claimSlotRpcSequence + " slotArg=" + __0 + ", selected=" + _selectedCount + ", rootActive=true -> ALLOW");
			return true;
		}
		Main.Log("Flexible player selector DEBUG: ClaimSlotRPC #" + _claimSlotRpcSequence + " slotArg=" + __0 + ", selected=" + _selectedCount + ", rootActive=true -> BLOCK");
		if (_lastBlockedSlotLog != __0)
		{
			_lastBlockedSlotLog = __0;
			Main.Log("Flexible player selector: ignored claim for slot " + __0 + " outside zero-based roster 0.." + (_selectedCount - 1));
		}
		return false;
	}

	private static bool AllowRootUpdate(uiCharacterCreateRoot root)
	{
		if ((Object)(object)root == (Object)null)
		{
			return true;
		}
		if ((Object)(object)_activeRoot != (Object)(object)root)
		{
			BeginSelection(root);
			CompleteRootSetup(root);
		}
		return _selectionConfirmed;
	}

	public static void BeginSelection(uiCharacterCreateRoot root)
	{
		if ((Object)(object)root == (Object)null)
		{
			return;
		}
		_activeRoot = root;
		if (DetectLoadOrResumeStateFromFlags())
		{
			_loadOrResumeFlow = true;
			_selectedCount = 0;
			_selectionConfirmed = true;
			_pendingCount = 0;
			_applyPendingAfterRootSetup = false;
			RestoreQuickCreateArray();
			RestoreCameraTargetsIfValid();
			Main.Log("Flexible player selector: hidden because a saved campaign is loading/resuming; keeping the save's roster.");
			return;
		}
		int num = (GameFlowMC.gMaxEnemies = (GameFlowMC.gMaxPlayers = GetMaximumAllowed()));
		bool num2 = _pendingCount > 0;
		RestoreQuickCreateArray();
		RestoreCameraTargetsIfValid();
		if ((Object)(object)_baseRoot == (Object)(object)root && _baseCreateTargets != null && _baseCreateTargets.Length >= num)
		{
			root.m_CreateUITargets = CopyTransforms(_baseCreateTargets, _baseCreateTargets.Length);
			SetTargetsActive(root.m_CreateUITargets, active: true);
			RestoreCreateTargetPositions(root);
		}
		if (num2)
		{
			_selectedCount = ClampCount(_pendingCount);
			_selectionConfirmed = true;
			_applyPendingAfterRootSetup = true;
			_pendingCount = 0;
		}
		else
		{
			_selectedCount = 0;
			_selectionConfirmed = false;
			_applyPendingAfterRootSetup = false;
		}
	}

	public static void CompleteRootSetup(uiCharacterCreateRoot root)
	{
		if (!((Object)(object)root == (Object)null))
		{
			CaptureBaseArrays(root, forceCameraCapture: true);
			if (_applyPendingAfterRootSetup && _selectedCount > 0)
			{
				int selectedCount = _selectedCount;
				_applyPendingAfterRootSetup = false;
				ApplyLocal(selectedCount);
			}
		}
	}

	public static void HandleInput()
	{
		if (!_loadOrResumeFlow && _selectionConfirmed && _selectedCount > 0 && (Object)(object)_activeRoot != (Object)null && (Object)(object)((Component)_activeRoot).gameObject != (Object)null && ((Component)_activeRoot).gameObject.activeInHierarchy && Input.GetKeyDown((KeyCode)32))
		{
			Main.Log("Flexible player selector DEBUG: Space key-down; selected=" + _selectedCount + ", activeCreateTargets=" + CountActiveCreateTargets(_activeRoot));
		}
		if (!_loadOrResumeFlow && !_selectionConfirmed && !((Object)(object)_activeRoot == (Object)null) && ((Component)_activeRoot).gameObject.activeInHierarchy && CanLocalPlayerChoose())
		{
			if (Input.GetKeyDown((KeyCode)49) || Input.GetKeyDown((KeyCode)257))
			{
				ChooseFromKeyboard(1);
			}
			else if (Input.GetKeyDown((KeyCode)50) || Input.GetKeyDown((KeyCode)258))
			{
				ChooseFromKeyboard(2);
			}
			else if (Input.GetKeyDown((KeyCode)51) || Input.GetKeyDown((KeyCode)259))
			{
				ChooseFromKeyboard(3);
			}
			else if (Input.GetKeyDown((KeyCode)52) || Input.GetKeyDown((KeyCode)260))
			{
				ChooseFromKeyboard(4);
			}
			else if (Input.GetKeyDown((KeyCode)53) || Input.GetKeyDown((KeyCode)261))
			{
				ChooseFromKeyboard(5);
			}
		}
	}

	private static void ChooseFromKeyboard(int count)
	{
		if (count <= GetMaximumAllowed())
		{
			Main instance = Main.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.ChooseSessionPlayerCount(count);
			}
			else
			{
				ApplyLocal(count);
			}
		}
	}

	public static void Draw()
	{
		//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: 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)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		if (_loadOrResumeFlow || _selectionConfirmed)
		{
			return;
		}
		uiCharacterCreateRoot val = _activeRoot;
		if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).gameObject == (Object)null || !((Component)val).gameObject.activeInHierarchy)
		{
			Object obj = Object.FindObjectOfType(typeof(uiCharacterCreateRoot));
			val = (uiCharacterCreateRoot)(object)((obj is uiCharacterCreateRoot) ? obj : null);
		}
		if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).gameObject == (Object)null || !((Component)val).gameObject.activeInHierarchy)
		{
			return;
		}
		if ((Object)(object)_activeRoot != (Object)(object)val)
		{
			BeginSelection(val);
			CompleteRootSetup(val);
		}
		if (_selectionConfirmed)
		{
			return;
		}
		CaptureBaseArrays(val, forceCameraCapture: false);
		EnsureGuiStyles();
		int maximumAllowed = GetMaximumAllowed();
		float num = ((float)Screen.width - 550f) * 0.5f;
		float num2 = Math.Max(18f, (float)Screen.height * 0.035f);
		Color color = GUI.color;
		Color backgroundColor = GUI.backgroundColor;
		Color contentColor = GUI.contentColor;
		try
		{
			GUI.color = Color.white;
			GUI.backgroundColor = Color.white;
			GUI.contentColor = Color.white;
			GUI.DrawTexture(new Rect(num, num2, 550f, 145f), (Texture)(object)_panelFrameTexture);
			GUI.DrawTexture(new Rect(num + 2f, num2 + 2f, 546f, 141f), (Texture)(object)_panelTexture);
			GUI.Label(new Rect(num + 12f, num2 + 7f, 526f, 29f), "CANTIDAD DE JUGADORES EN LA SESIÓN", _titleStyle);
			GUI.Label(new Rect(num + 12f, num2 + 35f, 526f, 22f), "Haz clic o usa una tecla del 1 al 5.", _helpStyle);
			GUI.DrawTexture(new Rect(num + 18f, num2 + 59f, 514f, 2f), (Texture)(object)_panelFrameTexture);
			GUI.DrawTexture(new Rect(num + 18f, num2 + 57f, 28f, 2f), (Texture)(object)_buttonFrameTexture);
			GUI.DrawTexture(new Rect(num + 550f - 46f, num2 + 61f, 28f, 2f), (Texture)(object)_buttonFrameTexture);
			if (!CanLocalPlayerChoose())
			{
				GUI.Label(new Rect(num + 12f, num2 + 70f, 526f, 42f), "Esperando a que el anfitrión elija la cantidad…", _waitingStyle);
				return;
			}
			float num3 = 7f;
			float num4 = (522f - num3 * (float)(maximumAllowed - 1)) / (float)maximumAllowed;
			Rect val2 = default(Rect);
			Rect val3 = default(Rect);
			for (int i = 1; i <= maximumAllowed; i++)
			{
				((Rect)(ref val2))..ctor(num + 14f + (float)(i - 1) * (num4 + num3), num2 + 63f, num4, 67f);
				GUI.DrawTexture(val2, (Texture)(object)_buttonFrameTexture);
				((Rect)(ref val3))..ctor(((Rect)(ref val2)).x + 2f, ((Rect)(ref val2)).y + 2f, ((Rect)(ref val2)).width - 4f, ((Rect)(ref val2)).height - 4f);
				bool num5 = GUI.Button(val3, GUIContent.none, _playerButtonStyle);
				GUI.Label(new Rect(((Rect)(ref val3)).x + 2f, ((Rect)(ref val3)).y + 4f, ((Rect)(ref val3)).width - 4f, 29f), i.ToString(), _playerNumberStyle);
				GUI.Label(new Rect(((Rect)(ref val3)).x + 2f, ((Rect)(ref val3)).y + 32f, ((Rect)(ref val3)).width - 4f, 24f), "PLAYERS", _playerCaptionStyle);
				if (num5)
				{
					Main instance = Main.Instance;
					if ((Object)(object)instance != (Object)null)
					{
						instance.ChooseSessionPlayerCount(i);
					}
					else
					{
						ApplyLocal(i);
					}
				}
			}
		}
		finally
		{
			GUI.color = color;
			GUI.backgroundColor = backgroundColor;
			GUI.contentColor = contentColor;
		}
	}

	private static void EnsureGuiStyles()
	{
		//IL_004c: 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)
		//IL_0092: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Expected O, but got Unknown
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Expected O, but got Unknown
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Expected O, but got Unknown
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Expected O, but got Unknown
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Expected O, but got Unknown
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Expected O, but got Unknown
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Expected O, but got Unknown
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Expected O, but got Unknown
		//IL_0471: Unknown result type (might be due to invalid IL or missing references)
		//IL_0481: Unknown result type (might be due to invalid IL or missing references)
		//IL_0491: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0525: Unknown result type (might be due to invalid IL or missing references)
		//IL_052f: Expected O, but got Unknown
		//IL_0539: Unknown result type (might be due to invalid IL or missing references)
		//IL_0543: Expected O, but got Unknown
		//IL_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0578: Expected O, but got Unknown
		//IL_0591: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05af: Expected O, but got Unknown
		//IL_05da: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e4: Expected O, but got Unknown
		//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
		if (!_guiStylesInitialized || _selectorPanelStyle == null || _selectorFrameStyle == null || _playerButtonStyle == null || _playerNumberStyle == null || _playerCaptionStyle == null || !((Object)(object)_buttonFrameTexture != (Object)null))
		{
			_panelFrameTexture = CreateSolidTexture(new Color(0.12f, 0.83f, 0.96f, 1f));
			_buttonFrameTexture = CreateSolidTexture(new Color(0.5f, 0.96f, 1f, 1f));
			_panelTexture = CreateSolidTexture(new Color(0.157f, 0.494f, 0.663f, 1f));
			_buttonTexture = CreateSolidTexture(new Color(0.094f, 0.408f, 0.557f, 1f));
			_buttonHoverTexture = CreateSolidTexture(new Color(0.22f, 0.78f, 0.9f, 1f));
			_buttonActiveTexture = CreateSolidTexture(new Color(0.047f, 0.3f, 0.42f, 1f));
			_selectorFrameStyle = new GUIStyle(GUI.skin.box);
			_selectorFrameStyle.normal.background = _panelFrameTexture;
			_selectorFrameStyle.hover.background = _panelFrameTexture;
			_selectorFrameStyle.active.background = _panelFrameTexture;
			_selectorFrameStyle.focused.background = _panelFrameTexture;
			_selectorFrameStyle.onNormal.background = _panelFrameTexture;
			_selectorFrameStyle.onHover.background = _panelFrameTexture;
			_selectorFrameStyle.onActive.background = _panelFrameTexture;
			_selectorFrameStyle.onFocused.background = _panelFrameTexture;
			_selectorFrameStyle.border = new RectOffset(1, 1, 1, 1);
			_selectorPanelStyle = new GUIStyle(GUI.skin.box);
			_selectorPanelStyle.normal.background = _panelTexture;
			_selectorPanelStyle.hover.background = _panelTexture;
			_selectorPanelStyle.active.background = _panelTexture;
			_selectorPanelStyle.focused.background = _panelTexture;
			_selectorPanelStyle.onNormal.background = _panelTexture;
			_selectorPanelStyle.onHover.background = _panelTexture;
			_selectorPanelStyle.onActive.background = _panelTexture;
			_selectorPanelStyle.onFocused.background = _panelTexture;
			_selectorPanelStyle.border = new RectOffset(2, 2, 2, 2);
			_titleStyle = new GUIStyle(GUI.skin.label);
			_titleStyle.fontSize = 16;
			_titleStyle.fontStyle = (FontStyle)1;
			_titleStyle.alignment = (TextAnchor)4;
			SetStyleTextColor(_titleStyle, new Color(0.83f, 0.98f, 1f, 1f));
			_helpStyle = new GUIStyle(GUI.skin.label);
			_helpStyle.fontSize = 12;
			_helpStyle.alignment = (TextAnchor)4;
			SetStyleTextColor(_helpStyle, new Color(0.38f, 0.88f, 0.98f, 1f));
			_waitingStyle = new GUIStyle(GUI.skin.label);
			_waitingStyle.fontSize = 13;
			_waitingStyle.fontStyle = (FontStyle)1;
			_waitingStyle.alignment = (TextAnchor)4;
			SetStyleTextColor(_waitingStyle, new Color(0.8f, 0.98f, 1f, 1f));
			_playerButtonStyle = new GUIStyle(GUI.skin.button);
			_playerButtonStyle.normal.background = _buttonTexture;
			_playerButtonStyle.hover.background = _buttonHoverTexture;
			_playerButtonStyle.active.background = _buttonActiveTexture;
			_playerButtonStyle.focused.background = _buttonHoverTexture;
			_playerButtonStyle.onNormal.background = _buttonTexture;
			_playerButtonStyle.onHover.background = _buttonHoverTexture;
			_playerButtonStyle.onActive.background = _buttonActiveTexture;
			_playerButtonStyle.onFocused.background = _buttonHoverTexture;
			Color textColor = default(Color);
			((Color)(ref textColor))..ctor(0.92f, 0.99f, 1f, 1f);
			_playerButtonStyle.normal.textColor = textColor;
			_playerButtonStyle.hover.textColor = textColor;
			_playerButtonStyle.active.textColor = Color.white;
			_playerButtonStyle.focused.textColor = textColor;
			_playerButtonStyle.onNormal.textColor = textColor;
			_playerButtonStyle.onHover.textColor = textColor;
			_playerButtonStyle.onActive.textColor = Color.white;
			_playerButtonStyle.onFocused.textColor = textColor;
			_playerButtonStyle.fontSize = 14;
			_playerButtonStyle.fontStyle = (FontStyle)1;
			_playerButtonStyle.alignment = (TextAnchor)4;
			_playerButtonStyle.wordWrap = false;
			_playerButtonStyle.padding = new RectOffset(2, 2, 3, 3);
			_playerNumberStyle = new GUIStyle(GUI.skin.label);
			_playerNumberStyle.fontSize = 20;
			_playerNumberStyle.fontStyle = (FontStyle)1;
			_playerNumberStyle.alignment = (TextAnchor)4;
			_playerNumberStyle.padding = new RectOffset(0, 0, 0, 0);
			SetStyleTextColor(_playerNumberStyle, new Color(0.94f, 1f, 1f, 1f));
			_playerCaptionStyle = new GUIStyle(GUI.skin.label);
			_playerCaptionStyle.fontSize = 11;
			_playerCaptionStyle.fontStyle = (FontStyle)1;
			_playerCaptionStyle.alignment = (TextAnchor)4;
			_playerCaptionStyle.padding = new RectOffset(0, 0, 0, 0);
			SetStyleTextColor(_playerCaptionStyle, new Color(0.77f, 0.98f, 1f, 1f));
			_guiStylesInitialized = true;
		}
	}

	private static void SetStyleTextColor(GUIStyle style, Color color)
	{
		//IL_000a: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (style != null)
		{
			style.normal.textColor = color;
			style.hover.textColor = color;
			style.active.textColor = color;
			style.focused.textColor = color;
			style.onNormal.textColor = color;
			style.onHover.textColor = color;
			style.onActive.textColor = color;
			style.onFocused.textColor = color;
		}
	}

	private static Texture2D CreateSolidTexture(Color color)
	{
		//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_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_001f: Expected O, but got Unknown
		Texture2D val = new Texture2D(1, 1);
		val.SetPixel(0, 0, color);
		val.Apply();
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}

	private static int CountActiveCreateTargets(uiCharacterCreateRoot root)
	{
		if ((Object)(object)root == (Object)null || root.m_CreateUITargets == null)
		{
			return 0;
		}
		int num = 0;
		for (int i = 0; i < root.m_CreateUITargets.Length; i++)
		{
			Transform val = root.m_CreateUITargets[i];
			if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && ((Component)val).gameObject.activeInHierarchy)
			{
				num++;
			}
		}
		return num;
	}

	private static bool CanLocalPlayerChoose()
	{
		try
		{
			if ((Object)(object)GameLogic.Instance == (Object)null || GameLogic.Instance.IsSinglePlayer())
			{
				return true;
			}
			return PhotonNetwork.isMasterClient;
		}
		catch
		{
			return true;
		}
	}

	public static void ApplyLocal(int requestedCount)
	{
		if (_loadOrResumeFlow || DetectLoadOrResumeStateFromFlags())
		{
			_loadOrResumeFlow = true;
			_selectionConfirmed = true;
			_selectedCount = 0;
			_pendingCount = 0;
			_applyPendingAfterRootSetup = false;
			Main.Log("Flexible player selector: ignored roster-count update because this is a load/resume flow.");
			return;
		}
		int num = (_selectedCount = ClampCount(requestedCount));
		_selectionConfirmed = true;
		uiCharacterCreateRoot activeRoot = _activeRoot;
		if ((Object)(object)activeRoot == (Object)null || !((Component)activeRoot).gameObject.activeInHierarchy)
		{
			_pendingCount = num;
			_applyPendingAfterRootSetup = false;
			Main.Log("Flexible player selector: received roster count " + num + " before character creation UI was active; will apply it when the screen opens.");
			return;
		}
		_pendingCount = 0;
		_applyPendingAfterRootSetup = false;
		ApplyGlobals(num);
		CaptureBaseArrays(activeRoot, forceCameraCapture: false);
		ApplyLayout(activeRoot, num);
		Main.Log("Flexible player selector: campaign roster set to " + num + " character(s).");
	}

	private static void ApplyGlobals(int count)
	{
		GameFlowMC.gMaxPlayers = count;
		GameFlowMC.gMaxEnemies = count;
	}

	private static void ApplyLayout(uiCharacterCreateRoot root, int count)
	{
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: 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_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)root == (Object)null)
		{
			return;
		}
		ApplyGlobals(count);
		Transform[] array = (((Object)(object)_baseRoot == (Object)(object)root && _baseCreateTargets != null) ? _baseCreateTargets : root.m_CreateUITargets);
		if (array != null && array.Length != 0)
		{
			root.m_CreateUITargets = CopyTransforms(array, array.Length);
			for (int i = 0; i < root.m_CreateUITargets.Length; i++)
			{
				Transform val = root.m_CreateUITargets[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				bool flag = i < count;
				((Component)val).gameObject.SetActive(flag);
				if (flag)
				{
					RectTransform component = ((Component)val).GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null)
					{
						float num = ((count == 1) ? 0f : Mathf.Lerp(-550f, 550f, (float)i / (float)(count - 1)));
						component.anchoredPosition = new Vector2(num, 129f);
					}
				}
			}
		}
		SelectScreenCamera instance = SelectScreenCamera.Instance;
		Transform[] array2 = _baseCameraTargets;
		if ((Object)(object)instance != (Object)null)
		{
			if (array2 == null || array2.Length == 0 || (Object)(object)array2[0] == (Object)null)
			{
				array2 = instance.m_PlayerTargets;
			}
			if (array2 != null && array2.Length != 0 && (Object)(object)array2[0] != (Object)null)
			{
				instance.m_PlayerTargets = CopyTransforms(array2, array2.Length);
				SetTargetsActive(instance.m_PlayerTargets, active: true);
				Vector3 baseCameraPosition = GetBaseCameraPosition(0, array2[0].position);
				Vector3 baseCameraPosition2 = GetBaseCameraPosition(array2.Length - 1, array2[^1].position);
				Vector3 val2 = baseCameraPosition;
				for (int j = 0; j < array2.Length; j++)
				{
					if (!((Object)(object)array2[j] == (Object)null))
					{
						Vector3 val3;
						if (j < count)
						{
							float num2 = ((count == 1) ? 0.5f : ((float)j / (float)(count - 1)));
							val3 = Vector3.Lerp(baseCameraPosition, baseCameraPosition2, num2);
							val2 = val3;
						}
						else
						{
							val3 = val2;
						}
						array2[j].position = val3;
					}
				}
			}
		}
		ResizeQuickCreateArray(count);
		uiQuickPlayerCreate.Default_Classes = new int[GetMaximumAllowed()];
		SceneDioramaPatches.ApplyCurrentPlayerCount();
	}

	private static void CaptureBaseArrays(uiCharacterCreateRoot root, bool forceCameraCapture)
	{
		if ((Object)(object)root == (Object)null)
		{
			return;
		}
		int maximumAllowed = GetMaximumAllowed();
		if (root.m_CreateUITargets != null && root.m_CreateUITargets.Length >= maximumAllowed && (!_selectionConfirmed || (Object)(object)_baseRoot != (Object)(object)root || _baseCreateTargets == null || _baseCreateTargets.Length < root.m_CreateUITargets.Length))
		{
			_baseRoot = root;
			_baseCreateTargets = CopyTransforms(root.m_CreateUITargets, root.m_CreateUITargets.Length);
			_baseCreateAnchoredPositions = CaptureAnchoredPositions(_baseCreateTargets);
		}
		SelectScreenCamera instance = SelectScreenCamera.Instance;
		if ((Object)(object)instance != (Object)null && instance.m_PlayerTargets != null && instance.m_PlayerTargets.Length >= maximumAllowed && (forceCameraCapture || (Object)(object)_baseCameraOwner != (Object)(object)instance || _baseCameraTargets == null || _baseCameraTargets.Length < instance.m_PlayerTargets.Length || _baseCameraTargets.Length == 0 || (Object)(object)_baseCameraTargets[0] == (Object)null))
		{
			_baseCameraOwner = instance;
			_baseCameraTargets = CopyTransforms(instance.m_PlayerTargets, instance.m_PlayerTargets.Length);
			_baseCameraWorldPositions = CaptureWorldPositions(_baseCameraTargets);
		}
		try
		{
			FieldInfo quickCreateArrayField = GetQuickCreateArrayField();
			Array array = (((object)quickCreateArrayField == null) ? null : (quickCreateArrayField.GetValue(null) as Array));
			if (array != null && array.Length >= maximumAllowed && (_baseQuickCreateArray == null || _baseQuickCreateArray.Length < array.Length || CountNonNull(array) > CountNonNull(_baseQuickCreateArray)))
			{
				_baseQuickCreateArray = (Array)array.Clone();
			}
		}
		catch (Exception ex)
		{
			Main.Log("Flexible player selector: could not capture quick-create slots: " + ex.Message);
		}
	}

	private static void RestoreQuickCreateArray()
	{
		try
		{
			FieldInfo quickCreateArrayField = GetQuickCreateArrayField();
			if ((object)quickCreateArrayField != null && _baseQuickCreateArray != null)
			{
				quickCreateArrayField.SetValue(null, (Array)_baseQuickCreateArray.Clone());
			}
			if (_baseQuickCreateArray != null)
			{
				for (int i = 0; i < _baseQuickCreateArray.Length; i++)
				{
					object? value = _baseQuickCreateArray.GetValue(i);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						val.gameObject.SetActive(true);
					}
				}
			}
			uiQuickPlayerCreate.Default_Classes = new int[GetMaximumAllowed()];
		}
		catch (Exception ex)
		{
			Main.Log("Flexible player selector: could not restore quick-create slots: " + ex.Message);
		}
	}

	private static void RestoreCameraTargetsIfValid()
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		SelectScreenCamera instance = SelectScreenCamera.Instance;
		if ((Object)(object)instance == (Object)null || _baseCameraTargets == null || _baseCameraTargets.Length == 0 || (Object)(object)_baseCameraTargets[0] == (Object)null)
		{
			return;
		}
		instance.m_PlayerTargets = CopyTransforms(_baseCameraTargets, _baseCameraTargets.Length);
		SetTargetsActive(instance.m_PlayerTargets, active: true);
		if (_baseCameraWorldPositions == null)
		{
			return;
		}
		int num = Math.Min(instance.m_PlayerTargets.Length, _baseCameraWorldPositions.Length);
		for (int i = 0; i < num; i++)
		{
			if ((Object)(object)instance.m_PlayerTargets[i] != (Object)null)
			{
				instance.m_PlayerTargets[i].position = _baseCameraWorldPositions[i];
			}
		}
	}

	private static void RestoreCreateTargetPositions(uiCharacterCreateRoot root)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)root == (Object)null || root.m_CreateUITargets == null || _baseCreateAnchoredPositions == null)
		{
			return;
		}
		int num = Math.Min(root.m_CreateUITargets.Length, _baseCreateAnchoredPositions.Length);
		for (int i = 0; i < num; i++)
		{
			if (!((Object)(object)root.m_CreateUITargets[i] == (Object)null))
			{
				RectTransform component = ((Component)root.m_CreateUITargets[i]).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.anchoredPosition = _baseCreateAnchoredPositions[i];
				}
			}
		}
	}

	private static Vector2[] CaptureAnchoredPositions(Transform[] targets)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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)
		if (targets == null)
		{
			return (Vector2[])(object)new Vector2[0];
		}
		Vector2[] array = (Vector2[])(object)new Vector2[targets.Length];
		for (int i = 0; i < targets.Length; i++)
		{
			RectTransform val = (((Object)(object)targets[i] == (Object)null) ? null : ((Component)targets[i]).GetComponent<RectTransform>());
			array[i] = (((Object)(object)val == (Object)null) ? Vector2.zero : val.anchoredPosition);
		}
		return array;
	}

	private static Vector3[] CaptureWorldPositions(Transform[] targets)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)