Decompiled source of Copy X Survivor v1.0.0

plugins/CopyXSurvivor/CopyXSurvivor.dll

Decompiled 9 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CopyXSurvivor.States;
using EntityStates;
using HarmonyLib;
using KinematicCharacterController;
using RoR2;
using RoR2.ContentManagement;
using RoR2.Projectile;
using RoR2.Skills;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Animations;
using UnityEngine.Networking;
using UnityEngine.Playables;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CopyXSurvivor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CopyXSurvivor")]
[assembly: AssemblyTitle("CopyXSurvivor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CopyXSurvivor
{
	public static class BusterShot
	{
		public static GameObject Prefab;

		public static void Build()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0165: 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_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			Sheets.ProjectilesRow projectilesRow = Sheets.Projectiles.First((Sheets.ProjectilesRow r) => r.id == "BusterShot");
			Prefab = Content.CloneNetworked(Content.Load<GameObject>(projectilesRow.baseProjectile), "CopyX" + projectilesRow.id);
			GameObject val = Content.ClonePlain(Content.Load<GameObject>("RoR2/Base/Mage/MageFireboltGhost.prefab"), "CopyX" + projectilesRow.id + "Ghost");
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				componentsInChildren[num].enabled = false;
			}
			ParticleSystem[] componentsInChildren2 = val.GetComponentsInChildren<ParticleSystem>(true);
			for (int num = 0; num < componentsInChildren2.Length; num++)
			{
				EmissionModule emission = componentsInChildren2[num].emission;
				((EmissionModule)(ref emission)).enabled = false;
			}
			Light[] componentsInChildren3 = val.GetComponentsInChildren<Light>(true);
			for (int num = 0; num < componentsInChildren3.Length; num++)
			{
				((Behaviour)componentsInChildren3[num]).enabled = false;
			}
			Color val2 = default(Color);
			ColorUtility.TryParseHtmlString(projectilesRow.glowColor, ref val2);
			Color c = default(Color);
			ColorUtility.TryParseHtmlString(projectilesRow.coreColor, ref c);
			float size = projectilesRow.size;
			Sphere(val.transform, "Glow", new Vector3(size, size, size * 1.6f), Glow(val2, 6f));
			Sphere(val.transform, "Core", new Vector3(size * 0.55f, size * 0.55f, size * 0.95f), Glow(c, 9f));
			Light obj = new GameObject("Light").AddComponent<Light>();
			((Component)obj).transform.SetParent(val.transform, false);
			obj.type = (LightType)2;
			obj.color = val2;
			obj.range = projectilesRow.light;
			obj.intensity = 2.5f;
			TrailRenderer obj2 = new GameObject("Trail").AddComponent<TrailRenderer>();
			((Component)obj2).transform.SetParent(val.transform, false);
			obj2.time = projectilesRow.trailTime;
			obj2.startWidth = size * 0.8f;
			obj2.endWidth = 0f;
			obj2.minVertexDistance = 0.05f;
			((Renderer)obj2).sharedMaterial = Glow(val2, 4f);
			((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
			ProjectileController component = Prefab.GetComponent<ProjectileController>();
			component.ghostPrefab = val;
			component.ghostPrefabAddress = new AssetReferenceT<GameObject>(string.Empty);
			component.startSound = "";
			ProjectileSimple component2 = Prefab.GetComponent<ProjectileSimple>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.desiredForwardSpeed = projectilesRow.speed;
				component2.lifetime = projectilesRow.lifetime;
			}
			ProjectileSingleTargetImpact component3 = Prefab.GetComponent<ProjectileSingleTargetImpact>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				component3.impactEffect = Content.Fx("RoR2/Base/Commando/HitsparkCommando.prefab");
			}
			ProjectileDamage component4 = Prefab.GetComponent<ProjectileDamage>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.damageType = DamageTypeCombo.GenericPrimary;
			}
			Content.Pack.projectilePrefabs.Add((GameObject[])(object)new GameObject[1] { Prefab });
			Plugin.Log.LogInfo((object)"Buster shot built");
		}

		private static Material Glow(Color c, float power)
		{
			//IL_0010: 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)
			Material obj = Content.MakeMaterial((Texture)(object)Texture2D.whiteTexture);
			obj.SetColor("_Color", c);
			obj.EnableKeyword("_EMISSION");
			obj.SetColor("_EmColor", c);
			obj.SetFloat("_EmPower", power);
			return obj;
		}

		private static void Sphere(Transform parent, string name, Vector3 scale, Material mat)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			((Object)obj).name = name;
			obj.transform.SetParent(parent, false);
			obj.transform.localScale = scale;
			MeshRenderer component = obj.GetComponent<MeshRenderer>();
			((Renderer)component).sharedMaterial = mat;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		}
	}
	public static class ChargedShots
	{
		public static float[] Sizes;

		public static float[] Levels;

		private static readonly Dictionary<string, GameObject[]> variants = new Dictionary<string, GameObject[]>();

		public static Sheets.ChargeRow Row => Sheets.Charge.First((Sheets.ChargeRow r) => r.id == "ElementalCharge");

		private static float[] Parse(string s)
		{
			return (from x in s.Split(',')
				select float.Parse(x.Trim(), CultureInfo.InvariantCulture)).ToArray();
		}

		public static float Coefficient(float charge01)
		{
			return Row.minCoef * Mathf.Pow(Row.maxCoef / Row.minCoef, Mathf.Clamp01(charge01));
		}

		public static int Tier(float charge01)
		{
			return Mathf.Clamp(Mathf.FloorToInt(Mathf.Clamp01(charge01) * (float)(Sizes.Length - 1) + 0.001f), 0, Sizes.Length - 1);
		}

		public static GameObject Projectile(string attackId, float charge01)
		{
			if (!variants.TryGetValue(attackId, out var value))
			{
				return null;
			}
			return value[Tier(charge01)];
		}

		public static void Build()
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: 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)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			Sizes = Parse(Row.shotSizes);
			Levels = Parse(Row.levelSeconds);
			List<GameObject> list = new List<GameObject>();
			foreach (Sheets.AttacksRow item in Sheets.Attacks.Where((Sheets.AttacksRow a) => a.skill == "ElementalCharge"))
			{
				GameObject val = Content.Load<GameObject>(item.projectile);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				ProjectileController component = val.GetComponent<ProjectileController>();
				GameObject val2 = component.ghostPrefab;
				if ((Object)(object)val2 == (Object)null && component.ghostPrefabAddress != null && ((AssetReference)component.ghostPrefabAddress).RuntimeKeyIsValid())
				{
					val2 = Addressables.LoadAssetAsync<GameObject>(((AssetReference)component.ghostPrefabAddress).RuntimeKey).WaitForCompletion();
				}
				GameObject[] array = (GameObject[])(object)new GameObject[Sizes.Length];
				for (int num = 0; num < Sizes.Length; num++)
				{
					float num2 = Sizes[num];
					GameObject val3 = Content.CloneNetworked(val, $"CopyX_{item.id}_{num}");
					val3.transform.localScale = val.transform.localScale * num2;
					ProjectileExplosion[] components = val3.GetComponents<ProjectileExplosion>();
					foreach (ProjectileExplosion obj in components)
					{
						obj.blastRadius *= num2;
					}
					ProjectileController component2 = val3.GetComponent<ProjectileController>();
					if ((Object)(object)val2 != (Object)null)
					{
						GameObject val4 = Content.ClonePlain(val2, $"CopyX_{item.id}_{num}_Ghost");
						val4.transform.localScale = val2.transform.localScale * num2;
						TrailRenderer[] componentsInChildren = val4.GetComponentsInChildren<TrailRenderer>(true);
						foreach (TrailRenderer obj2 in componentsInChildren)
						{
							obj2.widthMultiplier *= num2;
						}
						ParticleSystem[] componentsInChildren2 = val4.GetComponentsInChildren<ParticleSystem>(true);
						for (int num3 = 0; num3 < componentsInChildren2.Length; num3++)
						{
							MainModule main = componentsInChildren2[num3].main;
							((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0;
						}
						component2.ghostPrefab = val4;
						component2.ghostPrefabAddress = new AssetReferenceT<GameObject>(string.Empty);
					}
					array[num] = val3;
					list.Add(val3);
				}
				variants[item.id] = array;
			}
			Content.Pack.projectilePrefabs.Add(list.ToArray());
			Plugin.Log.LogInfo((object)$"Charged shots built: {list.Count} sizes");
		}
	}
	public class ChargeOrb : MonoBehaviour
	{
		public float charge01;

		public int level;

		private Transform glow;

		private Transform core;

		private Light light;

		private Material glowMat;

		private float flash;

		public static ChargeOrb Create(Transform anchor, Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CopyXChargeOrb");
			val.transform.SetParent(anchor, false);
			ChargeOrb chargeOrb = val.AddComponent<ChargeOrb>();
			chargeOrb.glowMat = MakeGlow(color, 5f);
			chargeOrb.glow = Sphere(val.transform, chargeOrb.glowMat);
			chargeOrb.core = Sphere(val.transform, MakeGlow(Color.white, 8f));
			chargeOrb.light = val.AddComponent<Light>();
			chargeOrb.light.type = (LightType)2;
			chargeOrb.light.color = color;
			chargeOrb.light.intensity = 1f;
			chargeOrb.light.range = ChargedShots.Row.lightRange;
			return chargeOrb;
		}

		private static Material MakeGlow(Color c, float power)
		{
			//IL_0010: 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)
			Material obj = Content.MakeMaterial((Texture)(object)Texture2D.whiteTexture);
			obj.SetColor("_Color", c);
			obj.EnableKeyword("_EMISSION");
			obj.SetColor("_EmColor", c);
			obj.SetFloat("_EmPower", power);
			return obj;
		}

		private static Transform Sphere(Transform parent, Material mat)
		{
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			obj.transform.SetParent(parent, false);
			MeshRenderer component = obj.GetComponent<MeshRenderer>();
			((Renderer)component).sharedMaterial = mat;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			return obj.transform;
		}

		public void SetLevel(int l)
		{
			if (l > level)
			{
				level = l;
				flash = 1f;
			}
		}

		private void Update()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00bf: 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)
			Sheets.ChargeRow row = ChargedShots.Row;
			float num = Mathf.Lerp(row.orbMinSize, row.orbMaxSize, charge01);
			float num2 = 1f + Mathf.Sin(Time.time * (10f + 14f * charge01)) * (0.06f + 0.1f * charge01);
			flash = Mathf.MoveTowards(flash, 0f, Time.deltaTime * 3f);
			glow.localScale = Vector3.one * num * num2 * (1f + flash * 0.6f);
			core.localScale = Vector3.one * num * 0.45f * num2;
			light.intensity = 1f + 4f * charge01 + 6f * flash;
			glowMat.SetFloat("_EmPower", 4f + 6f * charge01 + 10f * flash);
		}
	}
	public class Content : IContentPackProvider
	{
		public static readonly ContentPack Pack = new ContentPack();

		public static readonly Dictionary<string, SkillDef> SkillDefs = new Dictionary<string, SkillDef>();

		public static readonly Dictionary<string, string> Tokens = new Dictionary<string, string>();

		public static GameObject BodyPrefab;

		public static GameObject DisplayPrefab;

		public static SurvivorDef Survivor;

		private static GameObject holder;

		private static readonly Dictionary<string, Object> cache = new Dictionary<string, Object>();

		public string identifier => "melty.copyxsurvivor";

		public static T Load<T>(string key) where T : Object
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(key) || key == "-")
			{
				return default(T);
			}
			if (cache.TryGetValue(key, out var value))
			{
				return (T)(object)((value is T) ? value : null);
			}
			T val = default(T);
			try
			{
				val = Addressables.LoadAssetAsync<T>((object)key).WaitForCompletion();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("missing game asset " + key + ": " + ex.Message));
			}
			cache[key] = (Object)(object)val;
			return val;
		}

		public static GameObject Fx(string key)
		{
			return Content.Load<GameObject>(key);
		}

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			try
			{
				Build();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Copy X could not be built: " + ex));
			}
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(Pack, args.output);
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
		{
			args.ReportProgress(1f);
			yield break;
		}

		private static GameObject Clone(GameObject original, string name, bool networked)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)holder == (Object)null)
			{
				holder = new GameObject("CopyXPrefabs");
				holder.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)holder);
			}
			GameObject val = Object.Instantiate<GameObject>(original, holder.transform);
			((Object)val).name = name;
			NetworkIdentity component = val.GetComponent<NetworkIdentity>();
			if ((Object)(object)component != (Object)null && networked)
			{
				using MD5 mD = MD5.Create();
				string text = string.Concat(from b in mD.ComputeHash(Encoding.UTF8.GetBytes("melty.copyxsurvivor/" + name))
					select b.ToString("x2"));
				typeof(NetworkIdentity).GetField("m_AssetId", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(component, NetworkHash128.Parse(text));
			}
			return val;
		}

		public static GameObject CloneNetworked(GameObject o, string name)
		{
			return Clone(o, name, networked: true);
		}

		public static GameObject ClonePlain(GameObject o, string name)
		{
			return Clone(o, name, networked: false);
		}

		private static Sprite Icon(string id)
		{
			if (!DiveAssets.Sprites.TryGetValue(id, out var value))
			{
				return null;
			}
			return value;
		}

		private static Sprite SkillIcon(Sheets.SkillsRow r)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = (r.iconFile.StartsWith("personal:") ? r.iconFile.Substring(9) : r.iconFile);
				if (text != "-")
				{
					string path = Path.Combine(Path.GetDirectoryName(typeof(Content).Assembly.Location), text);
					if (File.Exists(path))
					{
						Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
						ImageConversion.LoadImage(val, File.ReadAllBytes(path));
						((Texture)val).wrapMode = (TextureWrapMode)1;
						return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("icon " + r.id + ": " + ex.Message));
			}
			return Icon(r.icon);
		}

		private static void Build()
		{
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f4: Expected O, but got Unknown
			//IL_05f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_078a: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			Sheets.SurvivorRow survivorRow = Sheets.Survivor[0];
			string text = "COPYX_";
			Tokens[text + "NAME"] = survivorRow.name;
			Tokens[text + "SUBTITLE"] = "The Perfect Copy";
			Tokens[text + "OUTRO"] = "..and so he left, still certain he was the true hero.";
			Tokens[text + "FAIL"] = "..and so he vanished, a copy without an original.";
			Tokens[text + "LORE"] = "Copy X, from your copy of MEGA MAN X DiVE Offline.";
			try
			{
				BusterShot.Build();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("buster shot: " + ex));
			}
			try
			{
				ChargedShots.Build();
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogError((object)("charged shots: " + ex2));
			}
			BodyPrefab = Clone(Content.Load<GameObject>("RoR2/Base/Commando/CommandoBody.prefab"), survivorRow.bodyName, networked: true);
			CharacterBody component = BodyPrefab.GetComponent<CharacterBody>();
			component.baseNameToken = text + "NAME";
			component.subtitleNameToken = text + "SUBTITLE";
			component.baseMaxHealth = survivorRow.baseHealth;
			component.levelMaxHealth = survivorRow.levelHealth;
			component.baseRegen = survivorRow.baseRegen;
			component.levelRegen = survivorRow.baseRegen * 0.2f;
			component.baseArmor = survivorRow.baseArmor;
			component.baseDamage = survivorRow.baseDamage;
			component.levelDamage = survivorRow.levelDamage;
			component.baseMoveSpeed = survivorRow.baseMoveSpeed;
			component.baseJumpCount = (int)survivorRow.baseJumpCount;
			Color val = default(Color);
			ColorUtility.TryParseHtmlString(survivorRow.color, ref val);
			component.bodyColor = val;
			Texture2D val2 = DiveAssets.SpriteToTexture(Icon(survivorRow.portraitSource));
			if ((Object)(object)val2 != (Object)null)
			{
				component.portraitIcon = (Texture)(object)val2;
			}
			BodyPrefab.AddComponent<WallKick>();
			EntityStateMachine val3 = BodyPrefab.AddComponent<EntityStateMachine>();
			val3.customName = "Seraph";
			val3.initialStateType = new SerializableEntityStateType(typeof(Idle));
			val3.mainStateType = new SerializableEntityStateType(typeof(Idle));
			NetworkStateMachine component2 = BodyPrefab.GetComponent<NetworkStateMachine>();
			component2.stateMachines = component2.stateMachines.Concat((IEnumerable<EntityStateMachine>)(object)new EntityStateMachine[1] { val3 }).ToArray();
			CharacterDeathBehavior component3 = BodyPrefab.GetComponent<CharacterDeathBehavior>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				component3.idleStateMachine = ((IEnumerable<EntityStateMachine>)(((object)component3.idleStateMachine) ?? ((object)new EntityStateMachine[0]))).Concat((IEnumerable<EntityStateMachine>)(object)new EntityStateMachine[1] { val3 }).ToArray();
			}
			List<Type> list = new List<Type>
			{
				typeof(FireElemental),
				typeof(SeraphTransform)
			};
			Sheets.SkillsRow[] skills = Sheets.Skills;
			foreach (Sheets.SkillsRow skillsRow in skills)
			{
				SkillDef val4 = ScriptableObject.CreateInstance<SkillDef>();
				((Object)val4).name = "CopyX" + skillsRow.id;
				val4.skillName = "CopyX" + skillsRow.id;
				val4.skillNameToken = text + skillsRow.id.ToUpperInvariant() + "_NAME";
				val4.skillDescriptionToken = text + skillsRow.id.ToUpperInvariant() + "_DESC";
				Tokens[val4.skillNameToken] = skillsRow.name;
				Tokens[val4.skillDescriptionToken] = skillsRow.desc;
				val4.icon = SkillIcon(skillsRow);
				Type type = typeof(FireBuster).Assembly.GetType("CopyXSurvivor.States." + skillsRow.state, throwOnError: true);
				list.Add(type);
				val4.activationState = new SerializableEntityStateType(type);
				val4.activationStateMachineName = skillsRow.stateMachine;
				val4.interruptPriority = (InterruptPriority)Enum.Parse(typeof(InterruptPriority), skillsRow.interrupt);
				val4.baseRechargeInterval = skillsRow.cooldown;
				val4.baseMaxStock = (int)skillsRow.stocks;
				val4.rechargeStock = 1;
				val4.requiredStock = 1;
				val4.stockToConsume = 1;
				val4.mustKeyPress = skillsRow.mustKeyPress;
				val4.isCombatSkill = skillsRow.isCombatSkill;
				val4.canceledFromSprinting = false;
				val4.cancelSprintingOnActivation = skillsRow.slot != "utility";
				val4.fullRestockOnAssign = true;
				val4.beginSkillCooldownOnSkillEnd = skillsRow.id == "ElementalCharge";
				val4.resetCooldownTimerOnUse = false;
				SkillDefs[skillsRow.id] = val4;
			}
			SkillLocator component4 = BodyPrefab.GetComponent<SkillLocator>();
			List<SkillFamily> families = new List<SkillFamily>();
			family(component4.primary, "primary");
			family(component4.secondary, "secondary");
			family(component4.utility, "utility");
			family(component4.special, "special");
			component4.passiveSkill.enabled = false;
			foreach (Sheets.SkillsRow item in Sheets.Skills.Where((Sheets.SkillsRow r) => r.form == "seraph" && r.showInSelect))
			{
				GenericSkill val5 = BodyPrefab.AddComponent<GenericSkill>();
				val5.skillName = "Seraph" + item.slot;
				val5.hideInCharacterSelect = false;
				val5.hideInLoadoutSelect = true;
				SkillFamily val6 = ScriptableObject.CreateInstance<SkillFamily>();
				((Object)val6).name = "CopyXSeraph" + item.slot + "Family";
				Variant[] array = new Variant[1];
				Variant val7 = new Variant
				{
					skillDef = SkillDefs[item.id]
				};
				((Variant)(ref val7)).viewableNode = new Node(item.id, false, (Node)null);
				array[0] = val7;
				val6.variants = (Variant[])(object)array;
				val5._skillFamily = val6;
				families.Add(val6);
			}
			Tokens[text + "DESC"] = survivorRow.blurb + "<color=#CCD3E0>\n\n" + string.Join("\n\n", Sheets.Skills.Select((Sheets.SkillsRow r) => "< ! > " + ((r.form == "seraph") ? "Seraph " : "") + r.name + ": " + r.overview)) + "</color>\n";
			DressModel(((Component)BodyPrefab.GetComponent<ModelLocator>().modelTransform).gameObject, display: false);
			DisplayPrefab = Clone(Content.Load<GameObject>("RoR2/Base/Commando/CommandoDisplay.prefab"), "CopyXDisplay", networked: false);
			CharacterModel componentInChildren = DisplayPrefab.GetComponentInChildren<CharacterModel>(true);
			DressModel(Object.op_Implicit((Object)(object)componentInChildren) ? ((Component)componentInChildren).gameObject : DisplayPrefab, display: true);
			Survivor = ScriptableObject.CreateInstance<SurvivorDef>();
			((Object)Survivor).name = "CopyX";
			Survivor.cachedName = "CopyX";
			Survivor.bodyPrefab = BodyPrefab;
			Survivor.displayPrefab = DisplayPrefab;
			Survivor.displayNameToken = text + "NAME";
			Survivor.descriptionToken = text + "DESC";
			Survivor.outroFlavorToken = text + "OUTRO";
			Survivor.mainEndingEscapeFailureFlavorToken = text + "FAIL";
			Survivor.primaryColor = val;
			Survivor.desiredSortPosition = survivorRow.sortPosition;
			Pack.bodyPrefabs.Add((GameObject[])(object)new GameObject[1] { BodyPrefab });
			Pack.survivorDefs.Add((SurvivorDef[])(object)new SurvivorDef[1] { Survivor });
			Pack.skillDefs.Add(SkillDefs.Values.ToArray());
			Pack.skillFamilies.Add(families.ToArray());
			Pack.entityStateTypes.Add(list.Distinct().ToArray());
			Plugin.Log.LogInfo((object)("Copy X built: " + SkillDefs.Count + " skills, " + list.Distinct().Count() + " states"));
			void family(GenericSkill gs, string slot)
			{
				//IL_0050: 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_0081: Expected O, but got Unknown
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				SkillFamily val8 = ScriptableObject.CreateInstance<SkillFamily>();
				((Object)val8).name = "CopyX" + slot + "Family";
				Sheets.SkillsRow skillsRow2 = Sheets.Skills.First((Sheets.SkillsRow r) => r.slot == slot && r.form == "base");
				Variant[] array2 = new Variant[1];
				Variant val9 = new Variant
				{
					skillDef = SkillDefs[skillsRow2.id]
				};
				((Variant)(ref val9)).viewableNode = new Node(skillsRow2.id, false, (Node)null);
				array2[0] = val9;
				val8.variants = (Variant[])(object)array2;
				gs._skillFamily = val8;
				families.Add(val8);
			}
		}

		public static Material MakeMaterial(Texture tex)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0057: Expected O, but got Unknown
			Material val = new Material(Content.Load<Shader>("RoR2/Base/Shaders/HGStandard.shader"))
			{
				mainTexture = tex
			};
			val.SetColor("_Color", Color.white);
			val.SetFloat("_Smoothness", 0.1f);
			val.SetFloat("_SpecularStrength", 0.15f);
			val.SetFloat("_Cull", 0f);
			return val;
		}

		private static void DressModel(GameObject model, bool display)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			ModelSkinController component = model.GetComponent<ModelSkinController>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			Renderer[] componentsInChildren = model.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val is SkinnedMeshRenderer || val is MeshRenderer)
				{
					val.enabled = false;
					((Component)val).gameObject.SetActive(false);
				}
			}
			GameObject val2 = Object.Instantiate<GameObject>(DiveAssets.ModelPrefab, model.transform);
			((Object)val2).name = "CopyXDiVE";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.Euler(0f, Plugin.ModelYaw.Value, 0f);
			val2.transform.localScale = Vector3.one * Plugin.ModelScale.Value;
			MonoBehaviour[] components = val2.GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val3 in components)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					_ = ((object)val3).GetType() == typeof(MonoBehaviour);
				}
			}
			DiveAssets.Textures.TryGetValue("ch_035_000", out var value);
			Material val4 = MakeMaterial((Texture)(object)value);
			List<RendererInfo> list = new List<RendererInfo>();
			SkinnedMeshRenderer val5 = null;
			SkinnedMeshRenderer[] componentsInChildren2 = val2.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val6 in componentsInChildren2)
			{
				((Renderer)val6).sharedMaterials = Enumerable.Repeat<Material>(val4, Math.Max(1, (!Object.op_Implicit((Object)(object)val6.sharedMesh)) ? 1 : val6.sharedMesh.subMeshCount)).ToArray();
				val6.updateWhenOffscreen = true;
				((Renderer)val6).enabled = true;
				((Renderer)val6).shadowCastingMode = (ShadowCastingMode)1;
				list.Add(new RendererInfo
				{
					renderer = (Renderer)(object)val6,
					defaultMaterial = val4,
					defaultShadowCastingMode = (ShadowCastingMode)1,
					ignoreOverlays = false
				});
				if (((Object)val6).name == "Unchange_BodyMesh_m")
				{
					val5 = val6;
				}
			}
			MeshRenderer val7 = SeraphModel.Attach(val2.transform);
			if (Object.op_Implicit((Object)(object)val7))
			{
				list.Add(new RendererInfo
				{
					renderer = (Renderer)(object)val7,
					defaultMaterial = ((Renderer)val7).sharedMaterial,
					defaultShadowCastingMode = (ShadowCastingMode)1,
					ignoreOverlays = false
				});
			}
			CharacterModel component2 = model.GetComponent<CharacterModel>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.baseRendererInfos = list.ToArray();
				if (Object.op_Implicit((Object)(object)val5))
				{
					component2.mainSkinnedMeshRenderer = val5;
				}
			}
			val2.AddComponent<CopyXVisual>().displayMode = display;
		}
	}
	public class CopyXVisual : MonoBehaviour
	{
		public bool displayMode;

		public CharacterBody body;

		private Animator animator;

		private PlayableGraph graph;

		private AnimationMixerPlayable mixer;

		private readonly Dictionary<string, int> index = new Dictionary<string, int>();

		private readonly List<AnimationClipPlayable> playables = new List<AnimationClipPlayable>();

		private float[] weights;

		private string current;

		private float oneShotUntil;

		private string oneShot;

		private bool seraph;

		private readonly List<GameObject> normalParts = new List<GameObject>();

		private readonly List<GameObject> seraphParts = new List<GameObject>();

		private EntityStateMachine weaponMachine;

		private EntityStateMachine bodyMachine;

		private EntityStateMachine seraphMachine;

		private GameObject seraphModel;

		private WallKick wallKick;

		private static readonly string[] Elements = new string[3] { "charge_fire", "charge_ice", "charge_thunder" };

		private readonly Dictionary<string, Material> schemeMats = new Dictionary<string, Material>();

		private string scheme = "base";

		private int shotsSeen;

		private object lastShotState;

		private bool wasSeraph;

		private Vector3 seraphBase;

		public bool IsSeraph => seraph;

		public string CurrentAnim => current;

		public string Scheme => scheme;

		public string NextElementId => Elements[shotsSeen % Elements.Length];

		public Color NextElementColor
		{
			get
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				string id = Elements[shotsSeen % Elements.Length];
				Sheets.ColorsRow colorsRow = Array.Find(Sheets.Colors, (Sheets.ColorsRow r) => r.id == id);
				Color result = default(Color);
				if (colorsRow == null || !ColorUtility.TryParseHtmlString(colorsRow.glow, ref result))
				{
					return Color.yellow;
				}
				return result;
			}
		}

		private void Awake()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//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)
			animator = ((Component)this).GetComponent<Animator>();
			foreach (Transform item in ((Component)this).transform)
			{
				Transform val = item;
				if (((Object)val).name.StartsWith("Changed_"))
				{
					seraphParts.Add(((Component)val).gameObject);
				}
				else if (((Object)val).name.StartsWith("Unchange_"))
				{
					normalParts.Add(((Component)val).gameObject);
				}
				else if (((Object)val).name == "CopyXSeraph")
				{
					seraphModel = ((Component)val).gameObject;
					seraphBase = val.localPosition;
				}
			}
			SetForm(s: false, force: true);
		}

		private void Start()
		{
			if ((Object)(object)body == (Object)null)
			{
				body = ((Component)this).GetComponentInParent<CharacterModel>()?.body;
			}
			if ((Object)(object)body != (Object)null)
			{
				weaponMachine = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Weapon");
				bodyMachine = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Body");
				seraphMachine = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Seraph");
			}
			BuildGraph();
			Play(displayMode ? "select" : "idle", restart: true);
		}

		private void BuildGraph()
		{
			//IL_0045: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00c0: 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_00cf: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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)
			if (!((Object)(object)animator == (Object)null))
			{
				animator.runtimeAnimatorController = null;
				animator.applyRootMotion = false;
				animator.cullingMode = (AnimatorCullingMode)0;
				((Behaviour)animator).enabled = true;
				graph = PlayableGraph.Create("CopyX");
				((PlayableGraph)(ref graph)).SetTimeUpdateMode((DirectorUpdateMode)1);
				AnimationPlayableOutput val = AnimationPlayableOutput.Create(graph, "CopyX", animator);
				Sheets.AnimationsRow[] animations = Sheets.Animations;
				mixer = AnimationMixerPlayable.Create(graph, animations.Length);
				weights = new float[animations.Length];
				for (int i = 0; i < animations.Length; i++)
				{
					DiveAssets.Clips.TryGetValue(animations[i].clip, out var value);
					AnimationClipPlayable val2 = (((Object)(object)value != (Object)null) ? AnimationClipPlayable.Create(graph, value) : AnimationClipPlayable.Create(graph, new AnimationClip()));
					((AnimationClipPlayable)(ref val2)).SetApplyFootIK(false);
					((PlayableGraph)(ref graph)).Connect<AnimationClipPlayable, AnimationMixerPlayable>(val2, 0, mixer, i);
					PlayableExtensions.SetInputWeight<AnimationMixerPlayable>(mixer, i, 0f);
					playables.Add(val2);
					index[animations[i].id] = i;
				}
				PlayableOutputExtensions.SetSourcePlayable<AnimationPlayableOutput, AnimationMixerPlayable>(val, mixer);
				((PlayableGraph)(ref graph)).Play();
			}
		}

		public void Play(string id, bool restart)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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 (index.ContainsKey(id) && (!(current == id) || restart))
			{
				current = id;
				AnimationClipPlayable val = playables[index[id]];
				Sheets.AnimationsRow animationsRow = Sheets.Animations[index[id]];
				if (restart || !animationsRow.loop)
				{
					PlayableExtensions.SetTime<AnimationClipPlayable>(val, 0.0);
				}
			}
		}

		public void PlayOnce(string id, float seconds)
		{
			oneShot = id;
			oneShotUntil = Time.time + seconds;
			Play(id, restart: true);
		}

		private void SetForm(bool s, bool force = false)
		{
			if (s == seraph && !force)
			{
				return;
			}
			seraph = s;
			bool flag = (Object)(object)seraphModel != (Object)null;
			foreach (GameObject normalPart in normalParts)
			{
				if (Object.op_Implicit((Object)(object)normalPart))
				{
					normalPart.SetActive(false);
				}
			}
			foreach (GameObject seraphPart in seraphParts)
			{
				if (Object.op_Implicit((Object)(object)seraphPart))
				{
					seraphPart.SetActive(!(s && flag));
				}
			}
			if (flag)
			{
				seraphModel.SetActive(s);
			}
		}

		private string Choose()
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			if (displayMode)
			{
				return "select";
			}
			if ((Object)(object)body == (Object)null)
			{
				return "idle";
			}
			EntityState val = (Object.op_Implicit((Object)(object)weaponMachine) ? weaponMachine.state : null);
			EntityState obj = (Object.op_Implicit((Object)(object)bodyMachine) ? bodyMachine.state : null);
			EntityState val2 = (Object.op_Implicit((Object)(object)seraphMachine) ? seraphMachine.state : null);
			SetForm(val2 is SeraphTransform);
			TrackElement(val);
			if (obj is HunterDash)
			{
				return "dash";
			}
			if (val2 is SeraphTransform seraphTransform && ((EntityState)seraphTransform).fixedAge < 0.6f)
			{
				return "transform";
			}
			if (seraph)
			{
				return "seraph_hover";
			}
			bool flag = val is FireBuster || val is ChargeElemental || val is FireElemental;
			CharacterMotor characterMotor = body.characterMotor;
			bool flag2 = (Object)(object)characterMotor == (Object)null || characterMotor.isGrounded;
			Vector3 val3 = (Object.op_Implicit((Object)(object)characterMotor) ? characterMotor.velocity : Vector3.zero);
			Vector2 val4 = new Vector2(val3.x, val3.z);
			bool flag3 = ((Vector2)(ref val4)).sqrMagnitude > 0.5f;
			if (val is FireElemental)
			{
				return "charge_release";
			}
			WallKick wallKick = (Object.op_Implicit((Object)(object)this.wallKick) ? this.wallKick : (this.wallKick = ((Component)body).GetComponent<WallKick>()));
			if (Object.op_Implicit((Object)(object)wallKick) && Time.time - wallKick.LastKickTime < 0.35f)
			{
				return "walljump";
			}
			if (Object.op_Implicit((Object)(object)wallKick) && wallKick.Sliding)
			{
				if (!(val is FireBuster) && !(val is ChargeElemental))
				{
					return "wallslide";
				}
				return "wallslide_shoot";
			}
			if (!flag2)
			{
				if (!flag)
				{
					if (!(val3.y > 0f))
					{
						return "fall";
					}
					return "jump";
				}
				return "air_shoot";
			}
			if (flag3)
			{
				if (!flag)
				{
					return "run";
				}
				return "run_shoot";
			}
			if (!flag)
			{
				return "idle";
			}
			return "stand_shoot";
		}

		private void Update()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_0174: 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)
			if (Object.op_Implicit((Object)(object)seraphModel) && seraph)
			{
				seraphModel.transform.localPosition = seraphBase + Vector3.up * (Mathf.Sin(Time.time * 2.2f) * 0.12f);
			}
			if (!((PlayableGraph)(ref graph)).IsValid())
			{
				return;
			}
			string id = ((oneShot != null && Time.time < oneShotUntil) ? oneShot : Choose());
			if (Time.time >= oneShotUntil)
			{
				oneShot = null;
			}
			Play(id, restart: false);
			int value;
			int num = (index.TryGetValue(current ?? "idle", out value) ? value : 0);
			float num2 = Time.deltaTime / 0.12f;
			for (int i = 0; i < weights.Length; i++)
			{
				weights[i] = Mathf.MoveTowards(weights[i], (i == num) ? 1f : 0f, num2);
				PlayableExtensions.SetInputWeight<AnimationMixerPlayable>(mixer, i, weights[i]);
				if (Sheets.Animations[i].loop && weights[i] > 0f)
				{
					AnimationClipPlayable val = playables[i];
					AnimationClip animationClip = ((AnimationClipPlayable)(ref val)).GetAnimationClip();
					if ((Object)(object)animationClip != (Object)null && animationClip.length > 0f && PlayableExtensions.GetTime<AnimationClipPlayable>(val) > (double)animationClip.length)
					{
						PlayableExtensions.SetTime<AnimationClipPlayable>(val, PlayableExtensions.GetTime<AnimationClipPlayable>(val) % (double)animationClip.length);
					}
				}
			}
		}

		private void TrackElement(object weaponState)
		{
			if (weaponState is FireElemental && weaponState != lastShotState)
			{
				lastShotState = weaponState;
				shotsSeen++;
				SetScheme(Elements[shotsSeen % Elements.Length]);
			}
			if (wasSeraph && !seraph)
			{
				shotsSeen = 0;
				SetScheme("base");
			}
			wasSeraph = seraph;
		}

		private void SetScheme(string id)
		{
			if (scheme == id)
			{
				return;
			}
			scheme = id;
			if (!schemeMats.TryGetValue(id, out var value))
			{
				Sheets.ColorsRow colorsRow = Array.Find(Sheets.Colors, (Sheets.ColorsRow r) => r.id == id);
				if (colorsRow == null || !DiveAssets.Textures.TryGetValue(colorsRow.texture, out var value2))
				{
					return;
				}
				value = Content.MakeMaterial((Texture)(object)value2);
				schemeMats[id] = value;
			}
			CharacterModel componentInParent = ((Component)this).GetComponentInParent<CharacterModel>();
			RendererInfo[] array = (Object.op_Implicit((Object)(object)componentInParent) ? componentInParent.baseRendererInfos : null);
			SkinnedMeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				((Renderer)val).sharedMaterial = value;
				if (array == null)
				{
					continue;
				}
				for (int num2 = 0; num2 < array.Length; num2++)
				{
					if ((Object)(object)array[num2].renderer == (Object)(object)val)
					{
						array[num2].defaultMaterial = value;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				componentInParent.baseRendererInfos = array;
				componentInParent.materialsDirty = true;
			}
		}

		private void OnDestroy()
		{
			if (((PlayableGraph)(ref graph)).IsValid())
			{
				((PlayableGraph)(ref graph)).Destroy();
			}
		}
	}
	public static class DiveAssets
	{
		public const string DiveFolderName = "MEGA_MAN_X_DiVE_Offline";

		private const string DataRel = "Game_Data/StreamingAssets/DownloadData";

		private static readonly byte[] Plain = new byte[10] { 85, 110, 105, 116, 121, 70, 83, 0, 0, 0 };

		private static readonly string[] ModelDependencies = new string[1] { "7f10356f83e8e72f6f04ef166bb03282" };

		public static string DiveDir;

		public static string DataDir;

		public static bool Loaded;

		public static string Error;

		public static GameObject ModelPrefab;

		public static readonly Dictionary<string, AnimationClip> Clips = new Dictionary<string, AnimationClip>();

		public static readonly Dictionary<string, Sprite> Sprites = new Dictionary<string, Sprite>();

		public static readonly Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();

		private static readonly Dictionary<string, AssetBundle> bundles = new Dictionary<string, AssetBundle>();

		public static string LocalDataDir => Path.Combine(Path.GetDirectoryName(typeof(DiveAssets).Assembly.Location), "DiveData");

		public static string FindDiveDir(string configured)
		{
			List<string> candidates = new List<string>();
			add(Environment.GetEnvironmentVariable("COPYX_DIVE_DIR"));
			try
			{
				string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CopyXSurvivor", "paths.cfg");
				if (File.Exists(path))
				{
					string[] array = File.ReadAllLines(path);
					foreach (string text in array)
					{
						if (text.StartsWith("dive="))
						{
							add(text.Substring(5));
						}
					}
				}
			}
			catch
			{
			}
			add(configured);
			try
			{
				DirectoryInfo directoryInfo = Directory.GetParent(Application.dataPath)?.Parent;
				if (directoryInfo != null)
				{
					add(Path.Combine(directoryInfo.FullName, "MEGA_MAN_X_DiVE_Offline"));
				}
				string[] array = new string[3]
				{
					directoryInfo?.Parent?.Parent?.FullName,
					"C:\\Program Files (x86)\\Steam",
					"C:\\Program Files\\Steam"
				};
				foreach (string text2 in array)
				{
					if (text2 == null)
					{
						continue;
					}
					string path2 = Path.Combine(text2, "steamapps", "libraryfolders.vdf");
					if (!File.Exists(path2))
					{
						continue;
					}
					string[] array2 = File.ReadAllLines(path2);
					for (int j = 0; j < array2.Length; j++)
					{
						string text3 = array2[j].Trim();
						if (text3.StartsWith("\"path\""))
						{
							string[] array3 = text3.Split('"');
							if (array3.Length >= 4)
							{
								add(Path.Combine(array3[3].Replace("\\\\", "\\"), "steamapps", "common", "MEGA_MAN_X_DiVE_Offline"));
							}
						}
					}
				}
			}
			catch
			{
			}
			foreach (string item in candidates)
			{
				if (Directory.Exists(Path.Combine(item, "Game_Data/StreamingAssets/DownloadData")))
				{
					return item;
				}
			}
			if (Directory.Exists(LocalDataDir) && File.Exists(Path.Combine(LocalDataDir, "2096caa746641aee6cf07030418d1b46")))
			{
				return LocalDataDir;
			}
			return null;
			void add(string p)
			{
				if (!string.IsNullOrWhiteSpace(p))
				{
					candidates.Add(p.Trim().Trim('"'));
				}
			}
		}

		private static byte[] Decode(string path)
		{
			byte[] array = File.ReadAllBytes(path);
			if (array.Length > 7 && array[0] == 85 && array[1] == 110 && array[2] == 105 && array[3] == 116 && array[4] == 121)
			{
				return array;
			}
			byte[] array2 = new byte[10];
			for (int i = 0; i < 10; i++)
			{
				array2[i] = (byte)(array[i] ^ Plain[i]);
			}
			for (int j = 0; j < array.Length; j++)
			{
				array[j] ^= array2[j % 10];
			}
			return array;
		}

		private static AssetBundle Open(string file)
		{
			if (bundles.TryGetValue(file, out var value))
			{
				return value;
			}
			string path = Path.Combine(DataDir, file);
			if (!File.Exists(path))
			{
				throw new FileNotFoundException("DiVE file missing: " + file);
			}
			value = AssetBundle.LoadFromMemory(Decode(path));
			if ((Object)(object)value == (Object)null)
			{
				throw new Exception("could not open DiVE file " + file);
			}
			bundles[file] = value;
			return value;
		}

		public static bool Load(string dir)
		{
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			DiveDir = dir;
			DataDir = ((dir == LocalDataDir) ? dir : Path.Combine(dir, "Game_Data/StreamingAssets/DownloadData"));
			try
			{
				string[] modelDependencies = ModelDependencies;
				foreach (string text in modelDependencies)
				{
					try
					{
						Open(text);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("dependency " + text + ": " + ex.Message));
					}
				}
				Sheets.DiveSourcesRow diveSourcesRow = Src("model");
				AssetBundle obj = Open(diveSourcesRow.bundleFile);
				ModelPrefab = obj.LoadAsset<GameObject>(diveSourcesRow.asset);
				if ((Object)(object)ModelPrefab == (Object)null)
				{
					throw new Exception("Copy X model not found in DiVE files");
				}
				Texture2D[] array = obj.LoadAllAssets<Texture2D>();
				foreach (Texture2D val in array)
				{
					Textures[((Object)val).name] = val;
				}
				modelDependencies = new string[2] { "male_buster", "copyx_motion" };
				for (int i = 0; i < modelDependencies.Length; i++)
				{
					AnimationClip[] array2 = Open(Src(modelDependencies[i]).bundleFile).LoadAllAssets<AnimationClip>();
					foreach (AnimationClip val2 in array2)
					{
						Clips[((Object)val2).name] = val2;
					}
				}
				modelDependencies = new string[3] { "portrait", "passive_icon", "showcase" };
				foreach (string text2 in modelDependencies)
				{
					Sheets.DiveSourcesRow s = Src(text2);
					try
					{
						Sprite val3 = ((IEnumerable<Sprite>)Open(s.bundleFile).LoadAllAssets<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite x) => ((Object)x).name == s.asset));
						if ((Object)(object)val3 != (Object)null)
						{
							Sprites[text2] = val3;
						}
						else
						{
							Plugin.Log.LogWarning((object)("icon " + s.asset + " not found"));
						}
					}
					catch (Exception ex2)
					{
						Plugin.Log.LogWarning((object)("icon " + text2 + ": " + ex2.Message));
					}
				}
				try
				{
					Sheets.DiveSourcesRow burst = Src("burst");
					Texture2D val4 = ((IEnumerable<Texture2D>)Open(burst.bundleFile).LoadAllAssets<Texture2D>()).FirstOrDefault((Func<Texture2D, bool>)((Texture2D x) => ((Object)x).name == burst.asset));
					if ((Object)(object)val4 != (Object)null)
					{
						Texture2D val5 = OnBlack(val4);
						Sprites["burst"] = Sprite.Create(val5, new Rect(0f, 0f, (float)((Texture)val5).width, (float)((Texture)val5).height), new Vector2(0.5f, 0.5f));
					}
				}
				catch (Exception ex3)
				{
					Plugin.Log.LogWarning((object)("burst icon: " + ex3.Message));
				}
				Sheets.AnimationsRow[] animations = Sheets.Animations;
				foreach (Sheets.AnimationsRow animationsRow in animations)
				{
					if (!Clips.ContainsKey(animationsRow.clip))
					{
						Plugin.Log.LogWarning((object)("animation missing in DiVE files: " + animationsRow.clip));
					}
				}
				Loaded = true;
				Plugin.Log.LogInfo((object)$"DiVE assets loaded from {dir}: model {((Object)ModelPrefab).name}, {Clips.Count} clips, {Textures.Count} textures, {Sprites.Count} icons");
				return true;
			}
			catch (Exception ex4)
			{
				Error = ex4.Message;
				Plugin.Log.LogError((object)("Could not read Copy X from MEGA MAN X DiVE Offline: " + ex4));
				return false;
			}
			static Sheets.DiveSourcesRow Src(string id)
			{
				return Sheets.Dive_sources.First((Sheets.DiveSourcesRow r) => r.id == id);
			}
		}

		public static Texture2D OnBlack(Texture2D src)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)src).width, ((Texture)src).height, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit((Texture)(object)src, temporary);
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(((Texture)src).width, ((Texture)src).height, (TextureFormat)4, false);
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)src).width, (float)((Texture)src).height), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			Color32[] pixels = val.GetPixels32();
			int width = ((Texture)src).width;
			int height = ((Texture)src).height;
			int num = width;
			int num2 = height;
			int num3 = -1;
			int num4 = -1;
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					Color32 val2 = pixels[i * width + j];
					float num5 = (float)(int)val2.a / 255f;
					byte b = (byte)((float)(int)val2.r * num5);
					byte b2 = (byte)((float)(int)val2.g * num5);
					byte b3 = (byte)((float)(int)val2.b * num5);
					pixels[i * width + j] = new Color32(b, b2, b3, byte.MaxValue);
					if (b + b2 + b3 > 40)
					{
						if (j < num)
						{
							num = j;
						}
						if (j > num3)
						{
							num3 = j;
						}
						if (i < num2)
						{
							num2 = i;
						}
						if (i > num4)
						{
							num4 = i;
						}
					}
				}
			}
			if (num3 < 0)
			{
				num = 0;
				num2 = 0;
				num3 = width - 1;
				num4 = height - 1;
			}
			int num6 = Mathf.CeilToInt((float)Mathf.Max(num3 - num, num4 - num2) * 1.12f) + 1;
			int num7 = (num + num3) / 2;
			int num8 = (num2 + num4) / 2;
			Texture2D val3 = new Texture2D(num6, num6, (TextureFormat)4, false);
			Color32[] array = (Color32[])(object)new Color32[num6 * num6];
			for (int k = 0; k < num6; k++)
			{
				for (int l = 0; l < num6; l++)
				{
					int num9 = num7 - num6 / 2 + l;
					int num10 = num8 - num6 / 2 + k;
					array[k * num6 + l] = (Color32)((num9 >= 0 && num10 >= 0 && num9 < width && num10 < height) ? pixels[num10 * width + num9] : new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
				}
			}
			val3.SetPixels32(array);
			val3.Apply();
			Object.Destroy((Object)(object)val);
			return val3;
		}

		public static Texture2D SpriteToTexture(Sprite s)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			if ((Object)(object)s == (Object)null || (Object)(object)s.texture == (Object)null)
			{
				return null;
			}
			Vector2[] uv = s.uv;
			float num = 1f;
			float num2 = 1f;
			float num3 = 0f;
			float num4 = 0f;
			Vector2[] array = uv;
			foreach (Vector2 val in array)
			{
				num = Mathf.Min(num, val.x);
				num2 = Mathf.Min(num2, val.y);
				num3 = Mathf.Max(num3, val.x);
				num4 = Mathf.Max(num4, val.y);
			}
			Texture2D texture = s.texture;
			int num5 = Mathf.Max(8, Mathf.RoundToInt((num3 - num) * (float)((Texture)texture).width));
			int num6 = Mathf.Max(8, Mathf.RoundToInt((num4 - num2) * (float)((Texture)texture).height));
			RenderTexture temporary = RenderTexture.GetTemporary(num5, num6, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit((Texture)(object)texture, temporary, new Vector2(num3 - num, num4 - num2), new Vector2(num, num2));
			RenderTexture.active = temporary;
			Texture2D val2 = new Texture2D(num5, num6, (TextureFormat)4, false);
			val2.ReadPixels(new Rect(0f, 0f, (float)num5, (float)num6), 0, 0);
			val2.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val2;
		}
	}
	[HarmonyPatch(typeof(SkillIcon), "LateUpdate")]
	internal static class ElementBadge
	{
		private static readonly Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();

		private static Sprite Badge(string elementId)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00b6: 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)
			if (sprites.TryGetValue(elementId, out var value))
			{
				return value;
			}
			value = null;
			Sheets.ColorsRow colorsRow = Array.Find(Sheets.Colors, (Sheets.ColorsRow r) => r.id == elementId);
			if (colorsRow != null && colorsRow.badge != "-")
			{
				string path = Path.Combine(Path.GetDirectoryName(typeof(ElementBadge).Assembly.Location), colorsRow.badge);
				if (File.Exists(path))
				{
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					ImageConversion.LoadImage(val, File.ReadAllBytes(path));
					value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
				}
			}
			sprites[elementId] = value;
			return value;
		}

		private static void Postfix(SkillIcon __instance)
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			GenericSkill targetSkill = __instance.targetSkill;
			Transform val = ((Component)__instance).transform.Find("CopyXElementBadge");
			SkillDef value;
			bool flag = Object.op_Implicit((Object)(object)targetSkill) && Content.SkillDefs.TryGetValue("ElementalCharge", out value) && (Object)(object)targetSkill.skillDef == (Object)(object)value;
			CopyXVisual copyXVisual = null;
			if (flag)
			{
				Transform val2 = ((Object.op_Implicit((Object)(object)targetSkill.characterBody) && Object.op_Implicit((Object)(object)targetSkill.characterBody.modelLocator)) ? targetSkill.characterBody.modelLocator.modelTransform : null);
				copyXVisual = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponentInChildren<CopyXVisual>() : null);
				flag = (Object)(object)copyXVisual != (Object)null;
			}
			if (!flag)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					((Component)val).gameObject.SetActive(false);
				}
				return;
			}
			Image component;
			if ((Object)(object)val == (Object)null)
			{
				GameObject val3 = new GameObject("CopyXElementBadge", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				RectTransform val4 = (RectTransform)val3.transform;
				((Transform)val4).SetParent(((Component)__instance).transform, false);
				Vector2 val5 = default(Vector2);
				((Vector2)(ref val5))..ctor(1f, 1f);
				val4.anchorMax = val5;
				val4.anchorMin = val5;
				val4.pivot = new Vector2(0.75f, 0.75f);
				Rect rect = ((RectTransform)((Component)__instance).transform).rect;
				float width = ((Rect)(ref rect)).width;
				val4.sizeDelta = Vector2.one * Mathf.Max(18f, width * 0.42f);
				val4.anchoredPosition = Vector2.zero;
				component = val3.GetComponent<Image>();
				((Graphic)component).raycastTarget = false;
				component.preserveAspect = true;
				val = (Transform)val4;
			}
			else
			{
				component = ((Component)val).GetComponent<Image>();
			}
			((Component)val).gameObject.SetActive(true);
			val.SetAsLastSibling();
			Sprite val6 = Badge(copyXVisual.NextElementId);
			if ((Object)(object)component.sprite != (Object)(object)val6)
			{
				component.sprite = val6;
			}
		}
	}
	public static class Sheets
	{
		public sealed class AnimationsRow
		{
			public string id;

			public string clip;

			public string source;

			public bool loop;

			public string when;
		}

		public sealed class AttacksRow
		{
			public string id;

			public string skill;

			public string kind;

			public float damageCoef;

			public float procCoef;

			public float interval;

			public float force;

			public float radius;

			public string damageType;

			public string projectile;

			public string effect;

			public string sound;
		}

		public sealed class ChargeRow
		{
			public string id;

			public float minCoef;

			public float maxCoef;

			public float maxSeconds;

			public string levelSeconds;

			public float orbMinSize;

			public float orbMaxSize;

			public float lightRange;

			public string shotSizes;
		}

		public sealed class ColorsRow
		{
			public string id;

			public string texture;

			public string when;

			public string glow;

			public string badge;
		}

		public sealed class DiveSourcesRow
		{
			public string id;

			public string bundleFile;

			public string asset;

			public string use;
		}

		public sealed class HooksRow
		{
			public string id;

			public string what;

			public string how;

			public string network;
		}

		public sealed class MovementRow
		{
			public string id;

			public float reach;

			public float kickAway;

			public float kickUpMultiplier;

			public float slideFallSpeed;

			public float cooldown;

			public bool faceAway;

			public float coyoteTime;

			public float inputBuffer;

			public float maxWallTilt;

			public float slideFxInterval;

			public float holdTowardDot;
		}

		public sealed class ProjectilesRow
		{
			public string id;

			public string baseProjectile;

			public float speed;

			public float lifetime;

			public string coreColor;

			public string glowColor;

			public float size;

			public float light;

			public float trailTime;
		}

		public sealed class SkillsRow
		{
			public string id;

			public string slot;

			public string name;

			public string desc;

			public string state;

			public string stateMachine;

			public float cooldown;

			public float stocks;

			public string interrupt;

			public bool mustKeyPress;

			public bool isCombatSkill;

			public string icon;

			public string form;

			public string iconFile;

			public bool showInSelect;

			public string overview;
		}

		public sealed class SurvivorRow
		{
			public string id;

			public string name;

			public string bodyName;

			public float baseHealth;

			public float levelHealth;

			public float baseRegen;

			public float baseArmor;

			public float baseDamage;

			public float levelDamage;

			public float baseMoveSpeed;

			public float baseJumpCount;

			public float sortPosition;

			public string color;

			public string portraitSource;

			public string blurb;
		}

		public static readonly AnimationsRow[] Animations = new AnimationsRow[15]
		{
			new AnimationsRow
			{
				id = "idle",
				clip = "buster_stand_loop",
				source = "male_buster",
				loop = true,
				when = "grounded, still"
			},
			new AnimationsRow
			{
				id = "run",
				clip = "buster_run_loop",
				source = "male_buster",
				loop = true,
				when = "grounded, moving"
			},
			new AnimationsRow
			{
				id = "run_shoot",
				clip = "buster_run_atk_mid_loop",
				source = "male_buster",
				loop = true,
				when = "grounded, moving, firing"
			},
			new AnimationsRow
			{
				id = "stand_shoot",
				clip = "buster_stand_atk_mid",
				source = "male_buster",
				loop = false,
				when = "grounded, still, firing"
			},
			new AnimationsRow
			{
				id = "jump",
				clip = "buster_jump_loop",
				source = "male_buster",
				loop = true,
				when = "airborne, rising"
			},
			new AnimationsRow
			{
				id = "fall",
				clip = "buster_fall_loop",
				source = "male_buster",
				loop = true,
				when = "airborne, falling"
			},
			new AnimationsRow
			{
				id = "air_shoot",
				clip = "buster_jump_atk_mid",
				source = "male_buster",
				loop = false,
				when = "airborne, firing"
			},
			new AnimationsRow
			{
				id = "dash",
				clip = "buster_dash_loop",
				source = "male_buster",
				loop = true,
				when = "HunterDash"
			},
			new AnimationsRow
			{
				id = "charge_release",
				clip = "buster_stand_charge_atk",
				source = "male_buster",
				loop = false,
				when = "ElementalCharge release"
			},
			new AnimationsRow
			{
				id = "seraph_hover",
				clip = "ch035_skill_02_loop",
				source = "copyx_motion",
				loop = true,
				when = "seraph form"
			},
			new AnimationsRow
			{
				id = "transform",
				clip = "ch035_skill_02_start",
				source = "copyx_motion",
				loop = false,
				when = "SeraphTransform"
			},
			new AnimationsRow
			{
				id = "select",
				clip = "ch035_ui_debut_loop",
				source = "copyx_motion",
				loop = true,
				when = "character select"
			},
			new AnimationsRow
			{
				id = "wallslide",
				clip = "buster_wallgrab_loop",
				source = "male_buster",
				loop = true,
				when = "sliding down a wall"
			},
			new AnimationsRow
			{
				id = "walljump",
				clip = "buster_walljump_start",
				source = "male_buster",
				loop = false,
				when = "just kicked off a wall"
			},
			new AnimationsRow
			{
				id = "wallslide_shoot",
				clip = "buster_wallgrab_atk_mid",
				source = "male_buster",
				loop = false,
				when = "shooting while sliding down a wall"
			}
		};

		public static readonly AttacksRow[] Attacks = new AttacksRow[6]
		{
			new AttacksRow
			{
				id = "buster",
				skill = "CopyBuster",
				kind = "projectile",
				damageCoef = 0.8f,
				procCoef = 1f,
				interval = 0.2f,
				force = 100f,
				radius = 0.4f,
				damageType = "Generic",
				projectile = "copyx:BusterShot",
				effect = "RoR2/Base/Commando/HitsparkCommando.prefab",
				sound = "Play_commando_M1"
			},
			new AttacksRow
			{
				id = "charge_fire",
				skill = "ElementalCharge",
				kind = "projectile",
				damageCoef = 15f,
				procCoef = 1f,
				interval = 0.4f,
				force = 600f,
				radius = 0f,
				damageType = "IgniteOnHit",
				projectile = "RoR2/Base/Mage/MageFireboltBasic.prefab",
				effect = "RoR2/Base/Commando/MuzzleflashFMJ.prefab",
				sound = "Play_mage_m1_shoot"
			},
			new AttacksRow
			{
				id = "charge_ice",
				skill = "ElementalCharge",
				kind = "projectile",
				damageCoef = 15f,
				procCoef = 1f,
				interval = 0.4f,
				force = 600f,
				radius = 0f,
				damageType = "Freeze2s",
				projectile = "RoR2/Base/Mage/MageIceBombProjectile.prefab",
				effect = "RoR2/Base/Commando/MuzzleflashFMJ.prefab",
				sound = "Play_mage_m2_iceSpear_shoot"
			},
			new AttacksRow
			{
				id = "charge_thunder",
				skill = "ElementalCharge",
				kind = "projectile",
				damageCoef = 15f,
				procCoef = 1f,
				interval = 0.4f,
				force = 600f,
				radius = 0f,
				damageType = "Shock5s",
				projectile = "RoR2/Base/Mage/MageLightningboltBasic.prefab",
				effect = "RoR2/Base/Commando/MuzzleflashFMJ.prefab",
				sound = "Play_mage_m1_shoot"
			},
			new AttacksRow
			{
				id = "orb",
				skill = "LightOrbs",
				kind = "projectile",
				damageCoef = 2.5f,
				procCoef = 1f,
				interval = 0.45f,
				force = 300f,
				radius = 0f,
				damageType = "Generic",
				projectile = "RoR2/Base/Mage/MageLightningBombProjectile.prefab",
				effect = "-",
				sound = "Play_mage_m2_shoot"
			},
			new AttacksRow
			{
				id = "beam",
				skill = "LightRain",
				kind = "blast",
				damageCoef = 4f,
				procCoef = 1f,
				interval = 0.12f,
				force = 800f,
				radius = 5f,
				damageType = "Generic",
				projectile = "-",
				effect = "RoR2/Base/Lightning/LightningStrikeImpact.prefab",
				sound = "Play_item_proc_lightningOnKill"
			}
		};

		public static readonly ChargeRow[] Charge = new ChargeRow[1]
		{
			new ChargeRow
			{
				id = "ElementalCharge",
				minCoef = 2f,
				maxCoef = 15f,
				maxSeconds = 5f,
				levelSeconds = "1.5,3.5,5",
				orbMinSize = 0.15f,
				orbMaxSize = 0.9f,
				lightRange = 6f,
				shotSizes = "1,1.5,2,2.75,3.5"
			}
		};

		public static readonly ColorsRow[] Colors = new ColorsRow[4]
		{
			new ColorsRow
			{
				id = "base",
				texture = "ch_035_000",
				when = "start, and after the Seraph form ends",
				glow = "#FFE15A",
				badge = "-"
			},
			new ColorsRow
			{
				id = "charge_fire",
				texture = "ch_035_002",
				when = "next charge shot is Fire",
				glow = "#FF6A2A",
				badge = "Icons/badge_fire.png"
			},
			new ColorsRow
			{
				id = "charge_ice",
				texture = "ch_035_004",
				when = "next charge shot is Ice",
				glow = "#6FE3FF",
				badge = "Icons/badge_ice.png"
			},
			new ColorsRow
			{
				id = "charge_thunder",
				texture = "ch_035_003",
				when = "next charge shot is Thunder",
				glow = "#8CFF5A",
				badge = "Icons/badge_thunder.png"
			}
		};

		public static readonly DiveSourcesRow[] Dive_sources = new DiveSourcesRow[7]
		{
			new DiveSourcesRow
			{
				id = "model",
				bundleFile = "2096caa746641aee6cf07030418d1b46",
				asset = "assets/main/art/newmodel/character/ch035_copyx (m)/ch035_000_u_s.prefab",
				use = "body model; Unchange_* = normal form, Changed_* = Seraph form"
			},
			new DiveSourcesRow
			{
				id = "male_buster",
				bundleFile = "813ab852e08a55f836ac5a30d516ba75",
				asset = "*",
				use = "movement and shooting animations"
			},
			new DiveSourcesRow
			{
				id = "copyx_motion",
				bundleFile = "5073a1c52a38d35dd23fdefd8c109958",
				asset = "*",
				use = "Copy X's own skill and pose animations"
			},
			new DiveSourcesRow
			{
				id = "portrait",
				bundleFile = "61ae74328e0b4b8961594726df49fde8",
				asset = "icon_ch_035_000",
				use = "survivor portrait and skill icons"
			},
			new DiveSourcesRow
			{
				id = "passive_icon",
				bundleFile = "c64ae7ef8fa2421cab9b609ac0c516c5",
				asset = "icon_passive_035",
				use = "Seraph skill icons"
			},
			new DiveSourcesRow
			{
				id = "showcase",
				bundleFile = "974be4caca11fe032d0aaf5e4bae9384",
				asset = "showcase_skill_035",
				use = "charge shot icon"
			},
			new DiveSourcesRow
			{
				id = "burst",
				bundleFile = "76e692eb9290ffd3a682612381c40ce3",
				asset = "z8060",
				use = "Copy Buster icon (DiVE's own burst art; the creator's picture is this same art)"
			}
		};

		public static readonly HooksRow[] Hooks = new HooksRow[10]
		{
			new HooksRow
			{
				id = "content",
				what = "register body, survivor, skills, states",
				how = "ContentManager.collectContentPackProviders",
				network = "cloned body gets its own NetworkIdentity assetId"
			},
			new HooksRow
			{
				id = "language",
				what = "names and descriptions",
				how = "Harmony postfix on Language.GetLocalizedStringByToken",
				network = "none"
			},
			new HooksRow
			{
				id = "visual",
				what = "show DiVE Copy X instead of Commando",
				how = "CopyXVisual on the model, Playables graph plays DiVE clips",
				network = "each client builds it locally"
			},
			new HooksRow
			{
				id = "forms",
				what = "armored look always; Seraph model during the special",
				how = "CopyXVisual reads the Seraph state machine's state",
				network = "the Seraph state machine is networked"
			},
			new HooksRow
			{
				id = "flight",
				what = "fly during Seraph",
				how = "SeraphTransform state: no gravity, Jump rises, sinks slowly otherwise",
				network = "runs where the body has authority"
			},
			new HooksRow
			{
				id = "divepath",
				what = "find the player's DiVE folder",
				how = "env COPYX_DIVE_DIR, then %LOCALAPPDATA%/CopyXSurvivor/paths.cfg, then BepInEx config, then Steam libraries",
				network = "none"
			},
			new HooksRow
			{
				id = "testmode",
				what = "Melty test checks",
				how = "MeltyTest writes pass/fail lines",
				network = "none"
			},
			new HooksRow
			{
				id = "seraphmodel",
				what = "Seraph form model made for this mod",
				how = "Seraph/seraph.obj + seraph.png beside the mod, shown by CopyXVisual during SeraphTransform; base look is the armored Changed_* parts",
				network = "each client shows it from the Seraph state"
			},
			new HooksRow
			{
				id = "wallkick",
				what = "wall kick and wall slide",
				how = "WallKick component on the body: sphere casts for a wall, Jump kicks off it, holding into it slows the fall",
				network = "runs where the body has authority; the motor's movement is networked by the game"
			},
			new HooksRow
			{
				id = "elementbadge",
				what = "next element badge on the M2 slot",
				how = "Harmony postfix on RoR2.UI.SkillIcon.LateUpdate adds a corner Image for Copy X's secondary",
				network = "local HUD only"
			}
		};

		public static readonly MovementRow[] Movement = new MovementRow[1]
		{
			new MovementRow
			{
				id = "WallKick",
				reach = 1.25f,
				kickAway = 12f,
				kickUpMultiplier = 1.1f,
				slideFallSpeed = -2.5f,
				cooldown = 0.25f,
				faceAway = true,
				coyoteTime = 0.2f,
				inputBuffer = 0.18f,
				maxWallTilt = 0.6f,
				slideFxInterval = 0.12f,
				holdTowardDot = 0.3f
			}
		};

		public static readonly ProjectilesRow[] Projectiles = new ProjectilesRow[1]
		{
			new ProjectilesRow
			{
				id = "BusterShot",
				baseProjectile = "RoR2/Base/Mage/MageFireboltBasic.prefab",
				speed = 120f,
				lifetime = 1.6f,
				coreColor = "#FFFFF0",
				glowColor = "#FFD21E",
				size = 0.42f,
				light = 4f,
				trailTime = 0.09f
			}
		};

		public static readonly SkillsRow[] Skills = new SkillsRow[6]
		{
			new SkillsRow
			{
				id = "CopyBuster",
				slot = "primary",
				name = "Copy Buster",
				desc = "Rapid-fire buster shots for <style=cIsDamage>80% damage</style>.",
				state = "FireBuster",
				stateMachine = "Weapon",
				cooldown = 0f,
				stocks = 1f,
				interrupt = "Any",
				mustKeyPress = false,
				isCombatSkill = true,
				icon = "burst",
				form = "base",
				iconFile = "-",
				showInSelect = true,
				overview = "Fire rapid buster shots."
			},
			new SkillsRow
			{
				id = "ElementalCharge",
				slot = "secondary",
				name = "Elemental Charge Shot",
				desc = "Hold to charge your buster for up to 5 seconds; power grows exponentially and the shot gets bigger, from <style=cIsDamage>200%</style> up to <style=cIsDamage>1500% damage</style>. Each shot cycles <style=cIsDamage>Fire</style> (ignite), <style=cIsUtility>Ice</style> (freeze) and <style=cIsDamage>Thunder</style> (shock).",
				state = "ChargeElemental",
				stateMachine = "Weapon",
				cooldown = 4f,
				stocks = 1f,
				interrupt = "Skill",
				mustKeyPress = true,
				isCombatSkill = true,
				icon = "showcase",
				form = "base",
				iconFile = "Icons/ElementalCharge.png",
				showInSelect = true,
				overview = "Hold to charge your buster."
			},
			new SkillsRow
			{
				id = "HunterDash",
				slot = "utility",
				name = "Hunter Dash",
				desc = "<style=cIsUtility>Dash</style> a short distance in the direction you are moving, on the ground or in the air.",
				state = "HunterDash",
				stateMachine = "Body",
				cooldown = 3f,
				stocks = 2f,
				interrupt = "PrioritySkill",
				mustKeyPress = true,
				isCombatSkill = false,
				icon = "portrait",
				form = "base",
				iconFile = "Icons/HunterDash.png",
				showInSelect = true,
				overview = "Dash a short distance in the direction you are moving, on the ground or in the air."
			},
			new SkillsRow
			{
				id = "SeraphAscension",
				slot = "special",
				name = "Seraph Ascension",
				desc = "Become <style=cIsUtility>Seraph Copy X</style> for 8 seconds: <style=cIsUtility>fly</style> (hold Jump to rise), and your skills become <style=cIsDamage>Light Orbs</style> and <style=cIsDamage>Light Rain</style>. Cooldown 18s.",
				state = "StartSeraph",
				stateMachine = "Body",
				cooldown = 18f,
				stocks = 1f,
				interrupt = "Frozen",
				mustKeyPress = true,
				isCombatSkill = true,
				icon = "passive_icon",
				form = "base",
				iconFile = "Icons/SeraphAscension.png",
				showInSelect = true,
				overview = "Become Seraph Copy X."
			},
			new SkillsRow
			{
				id = "LightOrbs",
				slot = "primary",
				name = "Light Orbs",
				desc = "<style=cIsUtility>Seraph form.</style> Fire large orbs of light about twice a second; each bursts for <style=cIsDamage>250% damage</style>.",
				state = "FireLightOrb",
				stateMachine = "Weapon",
				cooldown = 0f,
				stocks = 1f,
				interrupt = "Any",
				mustKeyPress = false,
				isCombatSkill = true,
				icon = "passive_icon",
				form = "seraph",
				iconFile = "Icons/LightOrbs.png",
				showInSelect = true,
				overview = "Fire large orbs of light."
			},
			new SkillsRow
			{
				id = "LightRain",
				slot = "secondary",
				name = "Light Rain",
				desc = "<style=cIsUtility>Seraph form.</style> Call down beams of light on up to <style=cIsDamage>6</style> enemies ahead, each striking a 5m area for <style=cIsDamage>400% damage</style>. Cooldown 2.5s.",
				state = "LightRain",
				stateMachine = "Weapon",
				cooldown = 2.5f,
				stocks = 1f,
				interrupt = "Skill",
				mustKeyPress = true,
				isCombatSkill = true,
				icon = "passive_icon",
				form = "seraph",
				iconFile = "Icons/LightRain.png",
				showInSelect = true,
				overview = "Call down beams of light on the enemies ahead."
			}
		};

		public static readonly SurvivorRow[] Survivor = new SurvivorRow[1]
		{
			new SurvivorRow
			{
				id = "copyx",
				name = "Copy X",
				bodyName = "CopyXBody",
				baseHealth = 110f,
				levelHealth = 33f,
				baseRegen = 1f,
				baseArmor = 0f,
				baseDamage = 12f,
				levelDamage = 2.4f,
				baseMoveSpeed = 7.5f,
				baseJumpCount = 1f,
				sortPosition = 100.5f,
				color = "#6FA8FF",
				portraitSource = "portrait",
				blurb = "Copy X is the final boss in Mega Man Zero, the ruler of Neo Arcadia, he's the copy of the legendary hero \"X\" and this fact is not known to the citizens of Neo Arcadia."
			}
		};
	}
	public class MeltyTest : MonoBehaviour
	{
		public const string Slug = "copy-x-survivor";

		private static string checksPath;

		private static readonly HashSet<string> reported = new HashSet<string>();

		private static readonly List<string> early = new List<string>();

		private static bool? active;

		private static bool Active
		{
			get
			{
				if (active.HasValue)
				{
					return active.Value;
				}
				active = false;
				try
				{
					string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Melty", "test", "copy-x-survivor.json");
					if (File.Exists(path))
					{
						Match match = Regex.Match(File.ReadAllText(path), "\"checks\"\\s*:\\s*\"((?:[^\"\\\\]|\\\\.)*)\"");
						if (match.Success)
						{
							checksPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileName(Regex.Unescape(match.Groups[1].Value)));
							active = true;
						}
					}
				}
				catch
				{
				}
				return active.Value;
			}
		}

		public static void Report(string check, bool ok, string why)
		{
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)("[test] " + (ok ? "pass" : "fail") + " " + check + (ok ? "" : (": " + why))));
			}
			if (!Active || reported.Contains(check))
			{
				return;
			}
			reported.Add(check);
			try
			{
				File.AppendAllText(checksPath, (ok ? ("pass " + check) : ("fail " + check + ": " + (why ?? "failed"))) + "\n");
			}
			catch
			{
			}
		}

		private void Start()
		{
			if (Active)
			{
				((MonoBehaviour)this).StartCoroutine(Run());
			}
		}

		private static void Cmd(string c)
		{
			Plugin.Log.LogInfo((object)("[test] console: " + c));
			Console.instance.SubmitCmd((NetworkUser)null, c, false);
		}

		private IEnumerator Run()
		{
			float t0 = Time.realtimeSinceStartup;
			while ((Object)(object)Console.instance == (Object)null || SurvivorCatalog.survivorCount == 0 || LocalUserManager.readOnlyLocalUsersList.Count == 0)
			{
				if (Time.realtimeSinceStartup - t0 > 240f)
				{
					Report("survivor-registered", ok: false, "the game never reached the title screen with a profile");
					yield break;
				}
				yield return (object)new WaitForSecondsRealtime(1f);
			}
			SurvivorDef val = SurvivorCatalog.FindSurvivorDefFromBody(Content.BodyPrefab);
			Report("survivor-registered", (Object)(object)val != (Object)null, "Copy X is not in the survivor list");
			if ((Object)(object)val == (Object)null)
			{
				yield break;
			}
			yield return (object)new WaitForSecondsRealtime(3f);
			Cmd("transition_command \"gamemode ClassicRun; host 0;\"");
			t0 = Time.realtimeSinceStartup;
			while ((Object)(object)PreGameController.instance == (Object)null)
			{
				if (Time.realtimeSinceStartup - t0 > 60f)
				{
					Report("copyx-spawned", ok: false, "could not open a run lobby");
					yield break;
				}
				yield return (object)new WaitForSecondsRealtime(0.5f);
			}
			yield return (object)new WaitForSecondsRealtime(2f);
			BodyIndex bodyIndex = BodyCatalog.FindBodyIndex(Content.BodyPrefab);
			foreach (NetworkUser readOnlyLocalPlayers in NetworkUser.readOnlyLocalPlayersList)
			{
				readOnlyLocalPlayers.CmdSetBodyPreference(bodyIndex);
			}
			yield return (object)new WaitForSecondsRealtime(10f);
			Cmd("pregame_start_run");
			t0 = Time.realtimeSinceStartup;
			CharacterBody body = null;
			while ((Object)(object)body == (Object)null)
			{
				if (Time.realtimeSinceStartup - t0 > 120f)
				{
					Report("copyx-spawned", ok: false, "no Copy X body appeared in the run");
					yield break;
				}
				LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
				CharacterBody val2 = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
				if ((Object)(object)val2 != (Object)null && val2.bodyIndex == bodyIndex)
				{
					body = val2;
				}
				yield return (object)new WaitForSecondsRealtime(0.5f);
			}
			for (float t1 = 0f; t1 < 20f; t1 += 0.5f)
			{
				if (!((Object)(object)body.currentVehicle != (Object)null))
				{
					break;
				}
				if (t1 >= 4f)
				{
					try
					{
						body.currentVehicle.EjectPassenger(((Component)body).gameObject);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("[test] eject: " + ex.Message));
					}
				}
				yield return (object)new WaitForSeconds(0.5f);
			}
			ModelLocator modelLocator = body.modelLocator;
			object obj;
			if (modelLocator == null)
			{
				obj = null;
			}
			else
			{
				Transform modelTransform = modelLocator.modelTransform;
				obj = ((modelTransform != null) ? ((Component)modelTransform).GetComponentInChildren<CopyXVisual>(true) : null);
			}
			CopyXVisual vis = (CopyXVisual)obj;
			int num = 0;
			for (float t1 = 0f; t1 < 15f; t1 += 0.5f)
			{
				if (num != 0)
				{
					break;
				}
				yield return (object)new WaitForSeconds(0.5f);
				num = 0;
				if (!Object.op_Implicit((Object)(object)vis))
				{
					continue;
				}
				SkinnedMeshRenderer[] componentsInChildren = ((Component)vis).GetComponentsInChildren<SkinnedMeshRenderer>();
				foreach (SkinnedMeshRenderer val3 in componentsInChildren)
				{
					if (((Renderer)val3).enabled && ((Component)val3).gameObject.activeInHierarchy && Object.op_Implicit((Object)(object)val3.sharedMesh))
					{
						num++;
					}
				}
			}
			DumpModel(body);
			Report("copyx-spawned", (Object)(object)vis != (Object)null && num > 0, "Copy X's model is not showing (" + num + " parts visible)");
			yield return (object)new WaitForSeconds(1f);
			Report("animations-playing", (Object)(object)vis != (Object)null && vis.CurrentAnim != null && DiveAssets.Clips.Count > 20, "DiVE animations are not playing");
			EntityStateMachine weapon = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Weapon");
			EntityStateMachine bodyM = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Body");
			EntityStateMachine seraph = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Seraph");
			bool ok = true;
			string why = null;
			for (int j = 0; j < 12; j++)
			{
				weapon.SetNextState((EntityState)(object)new FireBuster());
				yield return (object)new WaitForSeconds(0.2f);
			}
			weapon.SetNextState((EntityState)(object)new FireElemental
			{
				charge = 1f
			});
			yield return (object)new WaitForSeconds(0.6f);
			bool num2 = ok;
			ElementTracker component = ((Component)body).GetComponent<ElementTracker>();
			ok = num2 & (component != null && component.next > 0);
			if (!ok)
			{
				why = "the elemental charge shot did not fire";
			}
			if ((Object)(object)BusterShot.Prefab == (Object)null)
			{
				ok = false;
				why = "the buster shot was not built";
			}
			if ((Object)(object)ChargedShots.Projectile("charge_fire", 1f) == (Object)null)
			{
				ok = false;
				why = "the charged shot sizes were not built";
			}
			if (ok && Object.op_Implicit((Object)(object)vis) && vis.Scheme != "charge_ice")
			{
				ok = false;
				why = "after a Fire shot his colors should show Ice next, but show " + vis.Scheme;
			}
			bodyM.SetNextState((EntityState)(object)new HunterDash());
			yield return (object)new WaitForSeconds(0.5f);
			Report("skills-fire", ok, why);
			seraph.SetNextState((EntityState)(object)new SeraphTransform());
			yield return (object)new WaitForSeconds(1.5f);
			bool flag = Object.op_Implicit((Object)(object)vis) && vis.IsSeraph;
			bool flag2 = Object.op_Implicit((Object)(object)body.characterMotor) && !body.characterMotor.useGravity;
			bool flag3 = (Object)(object)body.skillLocator.primary.skillDef == (Object)(object)Content.SkillDefs["LightOrbs"] && (Object)(object)body.skillLocator.secondary.skillDef == (Object)(object)Content.SkillDefs["LightRain"];
			Report("seraph-form", flag && flag2 && flag3, $"seraph form {flag}, flying {flag2}, light skills {flag3}");
			weapon.SetNextState((EntityState)(object)new FireLightOrb());
			yield return (object)new WaitForSeconds(0.7f);
			weapon.SetNextState((EntityState)(object)new LightRain());
			yield return (object)new WaitForSeconds(SeraphTransform_Left(seraph));
			bool ok2 = Object.op_Implicit((Object)(object)vis) && !vis.IsSeraph && (Object)(object)body.skillLocator.primary.skillDef == (Object)(object)Content.SkillDefs["CopyBuster"] && vis.Scheme == "base";
			Report("seraph-ends", ok2, "Copy X did not return to his normal form");
		}

		public static void DumpModel(CharacterBody body)
		{
			//IL_0041: 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_0165: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			Transform val = (Object.op_Implicit((Object)(object)body.modelLocator) ? body.modelLocator.modelTransform : null);
			Plugin.Log.LogInfo((object)("[diag] model " + (Object.op_Implicit((Object)(object)val) ? (((Object)val).name + " scale " + ((object)val.lossyScale/*cast due to .constrained prefix*/).ToString()) : "none")));
			if (Object.op_Implicit((Object)(object)val))
			{
				Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val2 in componentsInChildren)
				{
					SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)(object)((val2 is SkinnedMeshRenderer) ? val2 : null);
					Material sharedMaterial = val2.sharedMaterial;
					ManualLogSource log = Plugin.Log;
					object[] obj = new object[9]
					{
						((object)val2).GetType().Name,
						((Object)val2).name,
						val2.enabled,
						((Component)val2).gameObject.activeInHierarchy,
						Object.op_Implicit((Object)(object)val3) ? (Object.op_Implicit((Object)(object)val3.sharedMesh) ? (((Object)val3.sharedMesh).name + "/" + val3.sharedMesh.vertexCount) : "null") : "-",
						(Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.rootBone)) ? ((Object)val3.rootBone).name : "-",
						null,
						null,
						null
					};
					Bounds bounds = val2.bounds;
					obj[6] = ((Bounds)(ref bounds)).size;
					obj[7] = (Object.op_Implicit((Object)(object)sharedMaterial) ? (((Object)sharedMaterial).name + "/" + (Object.op_Implicit((Object)(object)sharedMaterial.shader) ? ((Object)sharedMaterial.shader).name : "noshader")) : "null");
					obj[8] = ((Component)val2).transform.position;
					log.LogInfo((object)string.Format("[diag] {0} {1} enabled={2} active={3} mesh={4} root={5} bounds={6} mat={7} pos={8}", obj));
				}
				CharacterModel component = ((Component)val).GetComponent<CharacterModel>();
				if (Object.op_Implicit((Object)(object)component))
				{
					Plugin.Log.LogInfo((object)("[diag] baseRendererInfos " + component.baseRendererInfos.Length + " first " + ((component.baseRendererInfos.Length != 0 && Object.op_Implicit((Object)(object)component.baseRendererInfos[0].renderer)) ? ((Object)component.baseRendererInfos[0].renderer).name : "-")));
				}
			}
		}

		private static float SeraphTransform_Left(EntityStateMachine m)
		{
			if (!(m.state is SeraphTransform seraphTransform))
			{
				return 1f;
			}
			return Mathf.Max(0.5f, 8f - ((EntityState)seraphTransform).fixedAge + 1f);
		}
	}
	[BepInPlugin("melty.copyxsurvivor", "Copy X Survivor", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static CollectContentPackProvidersDelegate <>9__8_0;

			internal void <Awake>b__8_0(AddContentPackProviderDelegate add)
			{
				add.Invoke((IContentPackProvider)(object)new Content());
			}
		}

		public const string GUID = "melty.copyxsurvivor";

		public const string Version = "1.0.0";

		public static ManualLogSource Log;

		public static ConfigEntry<string> DiveFolder;

		public static ConfigEntry<float> ModelYaw;

		public static ConfigEntry<float> ModelScale;

		public static ConfigEntry<float> SeraphYaw;

		public static ConfigEntry<float> SeraphScale;

		private void Awake()
		{
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			DiveFolder = ((BaseUnityPlugin)this).Config.Bind<string>("General", "DiveFolder", "", "Folder of your MEGA MAN X DiVE Offline install. Leave empty to find it automatically.");
			ModelYaw = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "Yaw", 0f, "Turn Copy X's model (degrees).");
			ModelScale = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "Scale", 1.05f, "Size of Copy X's model.");
			SeraphYaw = ((BaseUnityPlugin)this).Config.Bind<float>("Seraph", "Yaw", 0f, "Turn the Seraph form's model (degrees).");
			SeraphScale = ((BaseUnityPlugin)this).Config.Bind<float>("Seraph", "Scale", 1f, "Size of the Seraph form's model.");
			SeraphModel.Load();
			string text = DiveAssets.FindDiveDir(DiveFolder.Value);
			if (text == null)
			{
				Log.LogError((object)"MEGA MAN X DiVE Offline was not found. Copy X reads his model from your own copy of the game: install it, or set DiveFolder in the config.");
				MeltyTest.Report("dive-assets-loaded", ok: false, "MEGA MAN X DiVE Offline not found");
				return;
			}
			if (!DiveAssets.Load(text))
			{
				MeltyTest.Report("dive-assets-loaded", ok: false, DiveAssets.Error);
				return;
			}
			MeltyTest.Report("dive-assets-loaded", ok: true, null);
			object obj = <>c.<>9__8_0;
			if (obj == null)
			{
				CollectContentPackProvidersDelegate val = delegate(AddContentPackProviderDelegate add)
				{
					add.Invoke((IContentPackProvider)(object)new Content());
				};
				<>c.<>9__8_0 = val;
				obj = (object)val;
			}
			ContentManager.collectContentPackProviders += (CollectContentPackProvidersDelegate)obj;
			new Harmony("melty.copyxsurvivor").PatchAll(typeof(Plugin).Assembly);
			((Component)this).gameObject.AddComponent<MeltyTest>();
		}
	}
	[HarmonyPatch(typeof(Language), "GetLocalizedStringByToken")]
	internal static class LanguagePatch
	{
		private static void Postfix(string token, ref string __result)
		{
			if (token != null && (__result == token || string.IsNullOrEmpty(__result)) && Content.Tokens.TryGetValue(token, out var value))
			{
				__result = value;
			}
		}
	}
	[HarmonyPatch(typeof(Language), "TokenIsRegistered")]
	internal static class LanguageRegisteredPatch
	{
		private static void Postfix(string token, ref bool __result)
		{
			if (!__result && token != null && Content.Tokens.ContainsKey(token))
			{
				__result = true;
			}
		}
	}
	public static class SeraphModel
	{
		public static Mesh Mesh;

		public static Texture2D Texture;

		public static string Folder => Path.Combine(Path.GetDirectoryName(typeof(SeraphModel).Assembly.Location), "Seraph");

		public static void Load()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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)
			//IL_0068: Expected O, but got Unknown
			try
			{
				string text = Path.Combine(Folder, "seraph.obj");
				string path = Path.Combine(Folder, "seraph.png");
				if (!File.Exists(text))
				{
					Plugin.Log.LogWarning((object)("Seraph model not found: " + text));
					return;
				}
				Mesh = ParseObj(File.ReadAllLines(text));
				if (File.Exists(path))
				{
					Texture = new Texture2D(2, 2, (TextureFormat)4, true);
					ImageConversion.LoadImage(Texture, File.ReadAllBytes(path));
					((Texture)Texture).wrapMode = (TextureWrapMode)1;
				}
				ManualLogSource log = Plugin.Log;
				object arg = Mesh.vertexCount;
				Bounds bounds = Mesh.bounds;
				log.LogInfo((object)$"Seraph model loaded: {arg} vertices, bounds {((Bounds)(ref bounds)).size}");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Seraph model: " + ex));
			}
		}

		private static Mesh ParseObj(string[] lines)
		{
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Vector3> list3 = new List<Vector3>();
			List<Vector2> list4 = new List<Vector2>();
			List<int> list5 = new List<int>();