Decompiled source of NemesisAmpExpanded v1.1.6

BepInEx/plugins/NemesisAmpExpanded/NemesisAmpExpanded.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AmpMod.SkillStates.Nemesis_Amp.Orbs;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using HarmonyLib;
using RoR2;
using RoR2.ContentManagement;
using RoR2.Orbs;
using RoR2.Projectile;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NemAmpMitrhixFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NemAmpMitrhixFix")]
[assembly: AssemblyTitle("NemAmpMitrhixFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NemAmpMithrixFix;

[DefaultExecutionOrder(10000)]
internal sealed class CrimsonBodyController : MonoBehaviour
{
	private CharacterModel model;

	private readonly List<Renderer> targets = new List<Renderer>();

	private readonly Dictionary<Renderer, Texture> mainTextures = new Dictionary<Renderer, Texture>();

	private readonly Dictionary<Renderer, Texture> emissionTextures = new Dictionary<Renderer, Texture>();

	private readonly Dictionary<Renderer, Color> mainColors = new Dictionary<Renderer, Color>();

	private readonly Dictionary<Renderer, Color> emissionColors = new Dictionary<Renderer, Color>();

	private readonly MaterialPropertyBlock block = new MaterialPropertyBlock();

	private bool initialized;

	internal unsafe void Initialize(CharacterModel targetModel)
	{
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		model = targetModel;
		targets.Clear();
		mainTextures.Clear();
		emissionTextures.Clear();
		mainColors.Clear();
		emissionColors.Clear();
		if (!Object.op_Implicit((Object)(object)model))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON BODY: CharacterModel was NULL.");
			return;
		}
		Renderer[] componentsInChildren = ((Component)model).GetComponentsInChildren<Renderer>(true);
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val) || (((Object)val).name != "Suit" && ((Object)val).name != "Cape"))
			{
				continue;
			}
			Material sharedMaterial = val.sharedMaterial;
			if (!Object.op_Implicit((Object)(object)sharedMaterial))
			{
				Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON BODY: " + ((Object)val).name + " had no material."));
				continue;
			}
			targets.Add(val);
			if (sharedMaterial.HasProperty("_MainTex"))
			{
				Texture texture = sharedMaterial.GetTexture("_MainTex");
				mainTextures[val] = texture;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON BODY: " + ((Object)val).name + " captured _MainTex=" + (Object.op_Implicit((Object)(object)texture) ? ((Object)texture).name : "NULL")));
			}
			if (sharedMaterial.HasProperty("_EmTex"))
			{
				Texture texture2 = sharedMaterial.GetTexture("_EmTex");
				emissionTextures[val] = texture2;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON BODY: " + ((Object)val).name + " captured _EmTex=" + (Object.op_Implicit((Object)(object)texture2) ? ((Object)texture2).name : "NULL")));
			}
			if (sharedMaterial.HasProperty("_Color"))
			{
				Color color = sharedMaterial.GetColor("_Color");
				mainColors[val] = color;
				string name = ((Object)val).name;
				Color val2 = color;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON BODY: " + name + " captured _Color=" + ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString()));
			}
			if (sharedMaterial.HasProperty("_EmColor"))
			{
				Color color2 = sharedMaterial.GetColor("_EmColor");
				emissionColors[val] = color2;
				string name2 = ((Object)val).name;
				Color val2 = color2;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON BODY: " + name2 + " captured _EmColor=" + ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString()));
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON BODY: Registered renderer=" + ((Object)val).name + ", material=" + ((Object)sharedMaterial).name));
		}
		initialized = true;
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON BODY: Initialized with " + targets.Count + " renderer(s)."));
	}

	private void LateUpdate()
	{
		//IL_00c0: 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)
		if (!initialized || !Object.op_Implicit((Object)(object)model))
		{
			return;
		}
		foreach (Renderer target in targets)
		{
			if (Object.op_Implicit((Object)(object)target))
			{
				block.Clear();
				target.GetPropertyBlock(block);
				if (mainTextures.TryGetValue(target, out var value) && Object.op_Implicit((Object)(object)value))
				{
					block.SetTexture("_MainTex", value);
				}
				if (mainColors.TryGetValue(target, out var value2))
				{
					block.SetColor("_Color", value2);
				}
				if (emissionTextures.TryGetValue(target, out var value3) && Object.op_Implicit((Object)(object)value3))
				{
					block.SetTexture("_EmTex", value3);
				}
				if (emissionColors.TryGetValue(target, out var value4))
				{
					block.SetColor("_EmColor", value4);
				}
				target.SetPropertyBlock(block);
			}
		}
	}
}
[HarmonyPatch]
internal static class CrimsonNemAmp
{
	private const string LogPrefix = "[NemAmpPersistentCharge] CRIMSON DEBUG: ";

	private const string ColorControllerTypeName = "AmpMod.SkillStates.Nemesis_Amp.Components.NemLightningColorController";

	private const string MasterySkinToken = "NT_NEMAMP_BODY_MASTERY_SKIN_NAME";

	private const float RangeMinimumAlpha = 1f;

	private const float RangeMinimumBrightness = 7f;

	private static readonly Dictionary<int, Texture2D> crimsonBodyTextureCache = new Dictionary<int, Texture2D>();

	private static Texture2D diagnosticBodyTexture;

	private static Texture2D GetDiagnosticBodyTexture()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)diagnosticBodyTexture))
		{
			return diagnosticBodyTexture;
		}
		diagnosticBodyTexture = new Texture2D(4, 4, (TextureFormat)4, false);
		Color32[] array = (Color32[])(object)new Color32[16];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue);
		}
		diagnosticBodyTexture.SetPixels32(array);
		diagnosticBodyTexture.Apply(false, false);
		((Object)diagnosticBodyTexture).name = "CRIMSON_DIAGNOSTIC_SOLID_RED";
		((Texture)diagnosticBodyTexture).filterMode = (FilterMode)0;
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR TEST: Created solid red diagnostic texture.");
		return diagnosticBodyTexture;
	}

	private static void RunNuclearBodyDiagnostic(CharacterModel model)
	{
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Expected O, but got Unknown
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)model))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR TEST FAILED: model NULL.");
			return;
		}
		Texture2D val = GetDiagnosticBodyTexture();
		Renderer[] componentsInChildren = ((Component)model).GetComponentsInChildren<Renderer>(true);
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: ========================================");
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR TEST START");
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: ========================================");
		Renderer[] array = componentsInChildren;
		foreach (Renderer val2 in array)
		{
			if (!Object.op_Implicit((Object)(object)val2) || (((Object)val2).name != "Suit" && ((Object)val2).name != "Cape"))
			{
				continue;
			}
			Material[] sharedMaterials = val2.sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			foreach (Material val3 in sharedMaterials)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR TARGET: renderer=" + ((Object)val2).name + ", material=" + ((Object)val3).name));
					if (val3.HasProperty("_MainTex"))
					{
						Texture texture = val3.GetTexture("_MainTex");
						val3.SetTexture("_MainTex", (Texture)(object)val);
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR _MainTex: " + ((Object)val2).name + " " + (Object.op_Implicit((Object)(object)texture) ? ((Object)texture).name : "NULL") + " -> " + ((Object)val).name));
					}
					if (val3.HasProperty("_Color"))
					{
						val3.SetColor("_Color", Color.white);
					}
					if (val3.HasProperty("_EmTex"))
					{
						val3.SetTexture("_EmTex", (Texture)null);
					}
					if (val3.HasProperty("_EmColor"))
					{
						val3.SetColor("_EmColor", Color.black);
					}
				}
			}
			MaterialPropertyBlock val4 = new MaterialPropertyBlock();
			val2.GetPropertyBlock(val4);
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR PROPERTY BLOCK: renderer=" + ((Object)val2).name + ", wasEmpty=" + val4.isEmpty));
			val2.SetPropertyBlock((MaterialPropertyBlock)null);
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR PROPERTY BLOCK CLEARED: " + ((Object)val2).name));
		}
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY NUCLEAR TEST COMPLETE");
	}

	private static MethodBase TargetMethod()
	{
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: TARGET 1: Looking for NemLightningColorController.");
		Type type = AccessTools.TypeByName("AmpMod.SkillStates.Nemesis_Amp.Components.NemLightningColorController");
		if (type == null)
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: TARGET FAILED: NemLightningColorController not found.");
			return null;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: TARGET 2: Found controller: " + type.FullName));
		MethodInfo methodInfo = AccessTools.Method(type, "Start", (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: TARGET FAILED: Start() not found.");
			return null;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: TARGET 3: Found Start(): " + methodInfo));
		return methodInfo;
	}

	private static void Prefix(object __instance, out SkinDef __state)
	{
		__state = null;
		Component val = (Component)((__instance is Component) ? __instance : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		CharacterBody component = val.GetComponent<CharacterBody>();
		if (!Object.op_Implicit((Object)(object)component))
		{
			return;
		}
		CharacterModel val2 = null;
		ModelLocator component2 = ((Component)component).GetComponent<ModelLocator>();
		if (Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component2.modelTransform))
		{
			val2 = ((Component)component2.modelTransform).GetComponent<CharacterModel>();
		}
		if (!Object.op_Implicit((Object)(object)val2))
		{
			val2 = val.GetComponentInChildren<CharacterModel>(true);
		}
		if (!Object.op_Implicit((Object)(object)val2))
		{
			return;
		}
		ModelSkinController component3 = ((Component)val2).GetComponent<ModelSkinController>();
		if (!Object.op_Implicit((Object)(object)component3) || component3.skins == null)
		{
			return;
		}
		int skinIndex = (int)component.skinIndex;
		if (skinIndex >= 0 && skinIndex < component3.skins.Length)
		{
			SkinDef val3 = component3.skins[skinIndex];
			if (CrimsonSkin.IsCrimsonSkin(val3))
			{
				__state = val3;
				CrimsonSkin.BeginRuntimeMasquerade(val3);
				__state = val3;
				Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: CRIMSON SKIN SHIM: Temporarily presenting Crimson as mastery so Amp initializes blue VFX.");
				val3.nameToken = "NT_NEMAMP_BODY_MASTERY_SKIN_NAME";
			}
		}
	}

	private static void Postfix(object __instance, SkinDef __state)
	{
		try
		{
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 1: Postfix entered.");
			Component val = (Component)((__instance is Component) ? __instance : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 2 FAILED: __instance was not a Component.");
				return;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 2: Controller=" + ((object)val).GetType().FullName));
			CharacterBody component = val.GetComponent<CharacterBody>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 3 FAILED: CharacterBody NULL.");
				return;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 3: body=" + ((Object)component).name + ", skinIndex=" + component.skinIndex));
			CharacterModel characterModel = GetCharacterModel(component, val);
			if (!Object.op_Implicit((Object)(object)characterModel))
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 4 FAILED: CharacterModel NULL.");
				return;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 4: model=" + ((Object)characterModel).name));
			ModelSkinController component2 = ((Component)characterModel).GetComponent<ModelSkinController>();
			if (!Object.op_Implicit((Object)(object)component2) || component2.skins == null)
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 5 FAILED: ModelSkinController unavailable.");
				return;
			}
			int skinIndex = (int)component.skinIndex;
			if (skinIndex < 0 || skinIndex >= component2.skins.Length)
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 6 FAILED: skinIndex out of range.");
				return;
			}
			SkinDef val2 = component2.skins[skinIndex];
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 6: Active skin=" + (Object.op_Implicit((Object)(object)val2) ? val2.nameToken : "NULL")));
			if (!Object.op_Implicit((Object)(object)val2) || !CrimsonSkin.IsCrimsonSkin(val2))
			{
				Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 7 STOP: Not Crimson skin.");
				return;
			}
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 7: Mastery/Crimson test skin confirmed.");
			Assembly assembly = ((object)val).GetType().Assembly;
			if (assembly == null)
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 8 FAILED: Amp assembly NULL.");
				return;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 8: Amp assembly=" + assembly.FullName));
			Texture ampAsset = CrimsonNemAmp.GetAmpAsset<Texture>(assembly, "texRampRedLightning", logFailure: false);
			if (Object.op_Implicit((Object)(object)characterModel))
			{
				ChildLocator component3 = ((Component)characterModel).GetComponent<ChildLocator>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					Transform val3 = component3.FindChild("BuffLightningBlue");
					if (Object.op_Implicit((Object)(object)val3))
					{
						RecolorObjectHierarchyRed(((Component)val3).gameObject, ampAsset, "Model.BuffLightningBlue");
						Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: GATHERING STORM: Recolored BuffLightningBlue for Crimson.");
					}
					else
					{
						Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: GATHERING STORM WARNING: BuffLightningBlue child not found.");
					}
				}
			}
			if (Object.op_Implicit((Object)(object)ampAsset))
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 9: Red ramp=" + ((Object)ampAsset).name));
			}
			else
			{
				Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STEP 9 WARNING: No red lightning ramp found. Color-property recoloring will still run.");
			}
			HashSet<int> hashSet = new HashSet<int>();
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 1 START: Controller visual fields.");
			RecolorControllerFields(val, __instance, ampAsset, hashSet);
			RecolorNemAmpSpawnController(component, ampAsset, hashSet);
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 1 COMPLETE.");
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 2 START: Red Onslaught strike.");
			GameObject ampAsset2 = CrimsonNemAmp.GetAmpAsset<GameObject>(assembly, "lightningStrikePrefabRed", logFailure: true);
			if (Object.op_Implicit((Object)(object)ampAsset2))
			{
				SetControllerGameObjectField(val, __instance, "specialBoltVFX", ampAsset2);
			}
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 2 COMPLETE.");
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 3 START: Extra Amp assets.");
			string[] array = new string[9] { "spawnDustEffect", "spawnSecondaryExplosionEffectBlue", "bladeExpireEffectBlue", "bladeProjectileGhostBlue", "lightningStakeGhostBlue", "lightningBallExplosionEffectBlue", "stormRangeIndicatorBlue", "plasmaCrosshair", "passiveMeter" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				GameObject ampAsset3 = CrimsonNemAmp.GetAmpAsset<GameObject>(assembly, text, logFailure: false);
				if (!Object.op_Implicit((Object)(object)ampAsset3))
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: EXTRA SKIP: " + text + " not found / NULL."));
					continue;
				}
				if (hashSet.Contains(((Object)ampAsset3).GetInstanceID()))
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: EXTRA SKIP: " + text + " already processed."));
					continue;
				}
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: EXTRA RECOLOR: " + text + " -> " + ((Object)ampAsset3).name));
				RecolorObjectHierarchyRed(ampAsset3, ampAsset, text);
				hashSet.Add(((Object)ampAsset3).GetInstanceID());
				if (text == "stormRangeIndicatorBlue")
				{
					BoostRangeIndicatorVisibility(ampAsset3);
				}
			}
			GameObject val4 = FindLoadedGameObjectByName("OmniImpactVFXLightningBlue");
			if (Object.op_Implicit((Object)(object)val4))
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: EXTRA LOADED OBJECT: " + ((Object)val4).name));
				RecolorObjectHierarchyRed(val4, ampAsset, "OmniImpactVFXLightningBlue");
			}
			else
			{
				Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: EXTRA LOADED OBJECT SKIP: OmniImpactVFXLightningBlue not found.");
			}
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 3 COMPLETE.");
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 3B START: Aggressive Static Field recolor.");
			GameObject ampAsset4 = CrimsonNemAmp.GetAmpAsset<GameObject>(assembly, "fieldProjectilePrefabBlue", logFailure: false);
			if (!Object.op_Implicit((Object)(object)ampAsset4))
			{
				ampAsset4 = CrimsonNemAmp.GetAmpAsset<GameObject>(assembly, "staticFieldPrefabBlue", logFailure: false);
			}
			if (Object.op_Implicit((Object)(object)ampAsset4))
			{
				AggressiveEffectRecolor(ampAsset4, ampAsset, "STATIC FIELD");
				OverrideStaticFieldTeamMaterials(ampAsset4);
			}
			else
			{
				FieldInfo fieldInfo = AccessTools.Field(((object)val).GetType(), "fieldPrefab");
				GameObject val5 = (GameObject)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if (Object.op_Implicit((Object)(object)val5))
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 3B: Using controller.fieldPrefab fallback=" + ((Object)val5).name));
					AggressiveEffectRecolor(val5, ampAsset, "STATIC FIELD CONTROLLER FALLBACK");
					OverrideStaticFieldTeamMaterials(val5);
				}
				else
				{
					Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 3B FAILED: Could not locate Static Field prefab.");
				}
			}
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 3B COMPLETE.");
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 4 START: Character body.");
			MonoBehaviour val6 = (MonoBehaviour)(object)((val is MonoBehaviour) ? val : null);
			if (Object.op_Implicit((Object)(object)val6))
			{
				Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY: Starting delayed Crimson live-body setup.");
				val6.StartCoroutine(InitializeCrimsonBodyRuntime(characterModel, ampAsset));
			}
			else
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY: Could not start delayed setup. Controller was not MonoBehaviour.");
				RecolorCharacterModelRed(characterModel, ampAsset);
				CrimsonBodyController crimsonBodyController = ((Component)characterModel).GetComponent<CrimsonBodyController>();
				if (!Object.op_Implicit((Object)(object)crimsonBodyController))
				{
					crimsonBodyController = ((Component)characterModel).gameObject.AddComponent<CrimsonBodyController>();
				}
				crimsonBodyController.Initialize(characterModel);
			}
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: PASS 4 COMPLETE.");
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON FULL PASS COMPLETE. Audit the character and report anything still blue/purple, invisible, too bright, or otherwise cursed.");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: UNHANDLED EXCEPTION:");
			Debug.LogError((object)ex);
		}
	}

	private static IEnumerator InitializeCrimsonBodyRuntime(CharacterModel model, Texture redRamp)
	{
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY RUNTIME: Waiting for initial skin application.");
		yield return null;
		yield return (object)new WaitForEndOfFrame();
		if (!Object.op_Implicit((Object)(object)model))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY RUNTIME FAILED: model destroyed.");
			yield break;
		}
		if (!CrimsonSkin.ApplyPreparedCrimsonToLiveModel(model))
		{
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY RUNTIME: Prepared material application failed. Using old runtime recolor fallback.");
			RecolorCharacterModelRed(model, redRamp);
		}
		CrimsonBodyController bodyController = ((Component)model).GetComponent<CrimsonBodyController>();
		if (!Object.op_Implicit((Object)(object)bodyController))
		{
			bodyController = ((Component)model).gameObject.AddComponent<CrimsonBodyController>();
		}
		bodyController.Initialize(model);
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY RUNTIME: First Crimson body application complete.");
		yield return (object)new WaitForSeconds(0.25f);
		if (Object.op_Implicit((Object)(object)model))
		{
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY RUNTIME: Late reapply result=" + CrimsonSkin.ApplyPreparedCrimsonToLiveModel(model)));
			bodyController.Initialize(model);
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY RUNTIME: Crimson body setup COMPLETE.");
		}
	}

	private static IEnumerator DelayedBodyAudit(CharacterModel model, Texture redRamp)
	{
		yield return null;
		AuditAndRepairBody(model, redRamp, "NEXT FRAME");
		yield return (object)new WaitForSeconds(0.25f);
		AuditAndRepairBody(model, redRamp, "0.25 SECONDS");
		yield return (object)new WaitForSeconds(0.75f);
		AuditAndRepairBody(model, redRamp, "1.00 SECOND");
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY DELAYED AUDIT COMPLETE.");
	}

	private unsafe static void AuditAndRepairBody(CharacterModel model, Texture redRamp, string stage)
	{
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Invalid comparison between Unknown and I4
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Invalid comparison between Unknown and I4
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)model))
		{
			Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY AUDIT " + stage + ": model NULL."));
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: ========== BODY AUDIT " + stage + " =========="));
		Renderer[] componentsInChildren = ((Component)model).GetComponentsInChildren<Renderer>(true);
		bool flag = false;
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val) || (((Object)val).name != "Suit" && ((Object)val).name != "Cape"))
			{
				continue;
			}
			Material sharedMaterial = val.sharedMaterial;
			if (!Object.op_Implicit((Object)(object)sharedMaterial))
			{
				Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY AUDIT " + stage + ": " + ((Object)val).name + " material=NULL."));
				continue;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY AUDIT " + stage + ": renderer=" + ((Object)val).name + ", material=" + ((Object)sharedMaterial).name + ", shader=" + (Object.op_Implicit((Object)(object)sharedMaterial.shader) ? ((Object)sharedMaterial.shader).name : "NULL")));
			if (sharedMaterial.HasProperty("_Color"))
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY AUDIT " + stage + ": " + ((Object)val).name + " _Color=" + ((object)sharedMaterial.GetColor("_Color")/*cast due to .constrained prefix*/).ToString()));
			}
			if (sharedMaterial.HasProperty("_EmColor"))
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY AUDIT " + stage + ": " + ((Object)val).name + " _EmColor=" + ((object)sharedMaterial.GetColor("_EmColor")/*cast due to .constrained prefix*/).ToString()));
			}
			Shader shader = sharedMaterial.shader;
			if (Object.op_Implicit((Object)(object)shader))
			{
				int propertyCount = shader.GetPropertyCount();
				for (int j = 0; j < propertyCount; j++)
				{
					string propertyName = shader.GetPropertyName(j);
					ShaderPropertyType propertyType = shader.GetPropertyType(j);
					if ((int)propertyType == 4)
					{
						Texture texture = sharedMaterial.GetTexture(propertyName);
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY TEXTURE " + stage + ": " + ((Object)val).name + "." + propertyName + "=" + (Object.op_Implicit((Object)(object)texture) ? ((Object)texture).name : "NULL")));
					}
					else if ((int)propertyType == 0)
					{
						Color color = sharedMaterial.GetColor(propertyName);
						string[] obj = new string[8]
						{
							"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY SHADER COLOR ",
							stage,
							": ",
							((Object)val).name,
							".",
							propertyName,
							"=",
							null
						};
						Color val2 = color;
						obj[7] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString();
						Debug.LogWarning((object)string.Concat(obj));
					}
				}
			}
			if (((Object)sharedMaterial).name.IndexOf("_CrimsonBodyRuntime", StringComparison.OrdinalIgnoreCase) < 0)
			{
				flag = true;
				Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY REVERSION DETECTED " + stage + ": " + ((Object)val).name + " reverted to " + ((Object)sharedMaterial).name));
			}
			else
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY MATERIAL STILL CRIMSON " + stage + ": " + ((Object)val).name));
			}
		}
		if (flag)
		{
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY AUDIT " + stage + ": Reversion found. Reapplying crimson body."));
			RecolorCharacterModelRed(model, redRamp);
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: ========== BODY AUDIT END " + stage + " =========="));
	}

	private static void RecolorNemAmpSpawnController(CharacterBody body, Texture redRamp, HashSet<int> processedObjects)
	{
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: SPAWN CONTROLLER: Looking for NemAmpSpawnVFXController.");
		Type type = AccessTools.TypeByName("AmpMod.SkillStates.Nemesis_Amp.Components.NemAmpSpawnVFXController");
		if (type == null)
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: SPAWN CONTROLLER FAILED: NemAmpSpawnVFXController type not found.");
			return;
		}
		Component component = ((Component)body).GetComponent(type);
		if (!Object.op_Implicit((Object)(object)component))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: SPAWN CONTROLLER FAILED: Component was not present on the body.");
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: SPAWN CONTROLLER FOUND: " + ((object)component).GetType().FullName));
		FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		FieldInfo[] array = fields;
		foreach (FieldInfo fieldInfo in array)
		{
			if (typeof(GameObject).IsAssignableFrom(fieldInfo.FieldType))
			{
				object? value = fieldInfo.GetValue(component);
				GameObject val = (GameObject)((value is GameObject) ? value : null);
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: SPAWN CONTROLLER FIELD: " + fieldInfo.Name + "=" + (Object.op_Implicit((Object)(object)val) ? ((Object)val).name : "NULL")));
			}
		}
		RecolorControllerFields(component, component, redRamp, processedObjects);
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: SPAWN CONTROLLER: Recolor pass complete.");
	}

	private static void OverrideStaticFieldTeamMaterials(GameObject root)
	{
		if (!Object.op_Implicit((Object)(object)root))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL FAILED: root was NULL.");
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL START: " + ((Object)root).name));
		MeshRenderer[] componentsInChildren = root.GetComponentsInChildren<MeshRenderer>(true);
		Material val = null;
		MeshRenderer[] array = componentsInChildren;
		foreach (MeshRenderer val2 in array)
		{
			if (!Object.op_Implicit((Object)(object)val2))
			{
				continue;
			}
			Material[] sharedMaterials = ((Renderer)val2).sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			Material[] array2 = sharedMaterials;
			foreach (Material val3 in array2)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					bool flag = ((Object)val2).name.IndexOf("Mesh", StringComparison.OrdinalIgnoreCase) >= 0;
					bool flag2 = ((Object)val3).name.IndexOf("FieldSphere", StringComparison.OrdinalIgnoreCase) >= 0;
					if (flag && flag2)
					{
						val = val3;
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL: Found crimson dome material=" + ((Object)val3).name + ", renderer=" + ((Object)val2).name));
						break;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				break;
			}
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL FAILED: Could not find recolored FieldSphere material.");
			return;
		}
		Component[] componentsInChildren2 = root.GetComponentsInChildren<Component>(true);
		int num = 0;
		int num2 = 0;
		Component[] array3 = componentsInChildren2;
		foreach (Component val4 in array3)
		{
			if (!Object.op_Implicit((Object)(object)val4))
			{
				continue;
			}
			Type type = ((object)val4).GetType();
			if (type.FullName != "RoR2.TeamAreaIndicator" && type.Name != "TeamAreaIndicator")
			{
				continue;
			}
			num++;
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL: Found TeamAreaIndicator at " + ((Object)val4.gameObject).name + ", type=" + type.FullName));
			FieldInfo fieldInfo = AccessTools.Field(type, "teamMaterialPairs");
			if (fieldInfo == null)
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL: teamMaterialPairs field not found.");
				continue;
			}
			if (!(fieldInfo.GetValue(val4) is Array array4))
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL: teamMaterialPairs was NULL.");
				continue;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL: pairCount=" + array4.Length));
			for (int l = 0; l < array4.Length; l++)
			{
				object value = array4.GetValue(l);
				if (value == null)
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL: pair[" + l + "] was NULL."));
					continue;
				}
				Type type2 = value.GetType();
				FieldInfo fieldInfo2 = AccessTools.Field(type2, "teamIndex");
				FieldInfo fieldInfo3 = AccessTools.Field(type2, "sharedMaterial");
				if (fieldInfo3 == null)
				{
					Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL: pair[" + l + "] has no sharedMaterial field. PairType=" + type2.FullName));
					continue;
				}
				object? value2 = fieldInfo3.GetValue(value);
				Material val5 = (Material)((value2 is Material) ? value2 : null);
				string text = ((fieldInfo2 != null) ? Convert.ToString(fieldInfo2.GetValue(value)) : "UNKNOWN");
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL BEFORE: pair=" + l + ", team=" + text + ", material=" + (Object.op_Implicit((Object)(object)val5) ? ((Object)val5).name : "NULL")));
				fieldInfo3.SetValue(value, val);
				array4.SetValue(value, l);
				num2++;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL AFTER: pair=" + l + ", team=" + text + ", material=" + ((Object)val).name));
			}
			fieldInfo.SetValue(val4, array4);
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC TEAM MATERIAL COMPLETE: indicatorCount=" + num + ", replacedPairs=" + num2));
	}

	private unsafe static void DumpVisualHierarchy(GameObject root, string label)
	{
		//IL_0413: Unknown result type (might be due to invalid IL or missing references)
		//IL_0418: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_041d: Unknown result type (might be due to invalid IL or missing references)
		//IL_041f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0423: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Expected I4, but got Unknown
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_044d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Unknown result type (might be due to invalid IL or missing references)
		//IL_047a: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)root))
		{
			Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: VISUAL DUMP FAILED: " + label + " root=NULL."));
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: ========== VISUAL DUMP START: " + label + " / " + ((Object)root).name + " =========="));
		Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": rendererCount=" + componentsInChildren.Length));
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": RENDERER object=" + GetTransformPath(root.transform, ((Component)val).transform) + ", type=" + ((object)val).GetType().FullName));
			MeshRenderer val2 = (MeshRenderer)(object)((val is MeshRenderer) ? val : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				MeshFilter component = ((Component)val2).GetComponent<MeshFilter>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh))
				{
					string[] obj = new string[6]
					{
						"[NemAmpPersistentCharge] CRIMSON DEBUG: ",
						label,
						": MESH=",
						((Object)component.sharedMesh).name,
						", bounds=",
						null
					};
					Bounds bounds = component.sharedMesh.bounds;
					obj[5] = ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString();
					Debug.LogWarning((object)string.Concat(obj));
				}
			}
			LineRenderer val3 = (LineRenderer)(object)((val is LineRenderer) ? val : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": LINE widthMultiplier=" + val3.widthMultiplier + ", positionCount=" + val3.positionCount + ", loop=" + val3.loop));
			}
			ParticleSystemRenderer val4 = (ParticleSystemRenderer)(object)((val is ParticleSystemRenderer) ? val : null);
			if (Object.op_Implicit((Object)(object)val4))
			{
				ParticleSystem component2 = ((Component)val4).GetComponent<ParticleSystem>();
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": PARTICLE renderer=" + ((Object)val).name + ", renderMode=" + ((object)val4.renderMode/*cast due to .constrained prefix*/).ToString() + ", particle=" + (Object.op_Implicit((Object)(object)component2) ? ((Object)component2).name : "NULL")));
			}
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials == null)
			{
				continue;
			}
			for (int j = 0; j < sharedMaterials.Length; j++)
			{
				Material val5 = sharedMaterials[j];
				if (!Object.op_Implicit((Object)(object)val5))
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": MATERIAL slot=" + j + " NULL"));
					continue;
				}
				Shader shader = val5.shader;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": MATERIAL object=" + GetTransformPath(root.transform, ((Component)val).transform) + ", slot=" + j + ", name=" + ((Object)val5).name + ", shader=" + (Object.op_Implicit((Object)(object)shader) ? ((Object)shader).name : "NULL") + ", renderQueue=" + val5.renderQueue));
				if (!Object.op_Implicit((Object)(object)shader))
				{
					continue;
				}
				int propertyCount = shader.GetPropertyCount();
				for (int k = 0; k < propertyCount; k++)
				{
					string propertyName = shader.GetPropertyName(k);
					ShaderPropertyType propertyType = shader.GetPropertyType(k);
					try
					{
						ShaderPropertyType val6 = propertyType;
						ShaderPropertyType val7 = val6;
						switch ((int)val7)
						{
						case 0:
						{
							Color color = val5.GetColor(propertyName);
							string[] obj2 = new string[6] { "[NemAmpPersistentCharge] CRIMSON DEBUG: ", label, ":   COLOR ", propertyName, "=", null };
							Color val8 = color;
							obj2[5] = ((object)(*(Color*)(&val8))/*cast due to .constrained prefix*/).ToString();
							Debug.LogWarning((object)string.Concat(obj2));
							break;
						}
						case 4:
						{
							Texture texture = val5.GetTexture(propertyName);
							Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ":   TEX " + propertyName + "=" + (Object.op_Implicit((Object)(object)texture) ? ((Object)texture).name : "NULL")));
							break;
						}
						case 2:
						case 3:
						{
							float num = val5.GetFloat(propertyName);
							Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ":   FLOAT " + propertyName + "=" + num));
							break;
						}
						case 1:
							break;
						}
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": property dump failed " + propertyName + " -> " + ex.Message));
					}
				}
			}
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: ========== VISUAL DUMP END: " + label + " =========="));
	}

	private static string GetTransformPath(Transform root, Transform child)
	{
		if (!Object.op_Implicit((Object)(object)child))
		{
			return "NULL";
		}
		string text = ((Object)child).name;
		Transform parent = child.parent;
		while (Object.op_Implicit((Object)(object)parent) && (Object)(object)parent != (Object)(object)root)
		{
			text = ((Object)parent).name + "/" + text;
			parent = parent.parent;
		}
		return text;
	}

	private static void ForceStormRangeIndicatorRed(GameObject root, Assembly ampAssembly)
	{
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Invalid comparison between Unknown and I4
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)root))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING FAILED: root was NULL.");
			return;
		}
		Material ampAsset = CrimsonNemAmp.GetAmpAsset<Material>(ampAssembly, "matLightningLongRed", logFailure: true);
		if (!Object.op_Implicit((Object)(object)ampAsset))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING FAILED: matLightningLongRed unavailable.");
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING START: root=" + ((Object)root).name));
		Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
		int num = 0;
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			Material[] array2 = (Material[])(object)new Material[sharedMaterials.Length];
			for (int j = 0; j < sharedMaterials.Length; j++)
			{
				Material val2 = new Material(ampAsset);
				((Object)val2).name = "CrimsonStormRange_" + ((Object)val).name + "_" + j;
				ForceStrongRedMaterial(val2, 5.5f, 1f);
				array2[j] = val2;
				num++;
			}
			val.sharedMaterials = array2;
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING MATERIAL REPLACED: renderer=" + ((Object)val).name + ", slots=" + array2.Length));
			LineRenderer val3 = (LineRenderer)(object)((val is LineRenderer) ? val : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				float widthMultiplier = val3.widthMultiplier;
				val3.widthMultiplier = Mathf.Max(widthMultiplier * 3f, 0.14f);
				val3.startColor = new Color(4f, 0.02f, 0.02f, 1f);
				val3.endColor = new Color(4f, 0.02f, 0.02f, 1f);
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING LINE: " + ((Object)val).name + " width " + widthMultiplier + " -> " + val3.widthMultiplier));
			}
			ParticleSystemRenderer val4 = (ParticleSystemRenderer)(object)((val is ParticleSystemRenderer) ? val : null);
			if (!Object.op_Implicit((Object)(object)val4))
			{
				continue;
			}
			ParticleSystem component = ((Component)val4).GetComponent<ParticleSystem>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				continue;
			}
			try
			{
				MainModule main = component.main;
				MinMaxCurve startSize = ((MainModule)(ref main)).startSize;
				if ((int)((MinMaxCurve)(ref startSize)).mode == 0)
				{
					float constant = ((MinMaxCurve)(ref startSize)).constant;
					((MainModule)(ref main)).startSize = new MinMaxCurve(constant * 1.8f);
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING PARTICLE SIZE: " + ((Object)component).name + " " + constant + " -> " + constant * 1.8f));
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING PARTICLE WARNING: " + ex.Message));
			}
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STORM RING COMPLETE: materialSlotsReplaced=" + num));
	}

	private static bool ContainsAnyIgnoreCase(string value, params string[] terms)
	{
		if (string.IsNullOrEmpty(value))
		{
			return false;
		}
		foreach (string value2 in terms)
		{
			if (value.IndexOf(value2, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private unsafe static void ForceStrongRedMaterial(Material material, float minimumBrightness, float minimumAlpha)
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: 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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)material))
		{
			return;
		}
		string[] array = new string[10] { "_Color", "_TintColor", "_EmissionColor", "_EmColor", "_EmColor0", "_EmColor1", "_MainColor", "_CloudColor", "_FresnelColor", "_RimColor" };
		string[] array2 = array;
		Color val = default(Color);
		foreach (string text in array2)
		{
			if (material.HasProperty(text))
			{
				Color color = material.GetColor(text);
				float num = Mathf.Max(minimumBrightness, ((Color)(ref color)).maxColorComponent);
				((Color)(ref val))..ctor(num, num * 0.015f, num * 0.02f, Mathf.Max(color.a, minimumAlpha));
				material.SetColor(text, val);
				string[] obj = new string[8]
				{
					"[NemAmpPersistentCharge] CRIMSON DEBUG: FORCE RED MATERIAL: ",
					((Object)material).name,
					".",
					text,
					" ",
					null,
					null,
					null
				};
				Color val2 = color;
				obj[5] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString();
				obj[6] = " -> ";
				val2 = val;
				obj[7] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString();
				Debug.LogWarning((object)string.Concat(obj));
			}
		}
	}

	private static void ForceStaticFieldDomeRed(GameObject root, Assembly ampAssembly)
	{
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)root))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC DOME FAILED: root was NULL.");
			return;
		}
		Material ampAsset = CrimsonNemAmp.GetAmpAsset<Material>(ampAssembly, "matLightningSphereRed", logFailure: true);
		if (!Object.op_Implicit((Object)(object)ampAsset))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC DOME FAILED: matLightningSphereRed unavailable.");
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC DOME START: root=" + ((Object)root).name + ", redMaterial=" + ((Object)ampAsset).name));
		Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
		int num = 0;
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val) || val is TrailRenderer || val is LineRenderer)
			{
				continue;
			}
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC DOME CANDIDATE: renderer=" + ((Object)val).name + ", rendererType=" + ((object)val).GetType().Name));
			bool flag = ContainsAnyIgnoreCase(((Object)val).name, "sphere", "dome", "shell", "bubble", "field");
			Material[] array2 = (Material[])(object)new Material[sharedMaterials.Length];
			bool flag2 = false;
			for (int j = 0; j < sharedMaterials.Length; j++)
			{
				Material val2 = (array2[j] = sharedMaterials[j]);
				if (Object.op_Implicit((Object)(object)val2))
				{
					string text = (Object.op_Implicit((Object)(object)val2.shader) ? ((Object)val2.shader).name : "");
					bool flag3 = ContainsAnyIgnoreCase(((Object)val2).name, "sphere", "dome", "shell", "bubble", "field", "blue");
					bool flag4 = text.IndexOf("intersectioncloud", StringComparison.OrdinalIgnoreCase) >= 0;
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC DOME MATERIAL: renderer=" + ((Object)val).name + ", material=" + ((Object)val2).name + ", shader=" + text + ", rendererNameMatch=" + flag + ", materialNameMatch=" + flag3 + ", intersectionShader=" + flag4));
					if (flag4 || flag3 || flag)
					{
						Material val3 = new Material(ampAsset);
						((Object)val3).name = "CrimsonStaticFieldSphere_" + ((Object)val).name + "_" + j;
						ForceStrongRedMaterial(val3, 2.75f, 0.9f);
						array2[j] = val3;
						flag2 = true;
						num++;
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC DOME REPLACED: " + ((Object)val).name + " slot=" + j + " " + ((Object)val2).name + " -> " + ((Object)val3).name));
					}
				}
			}
			if (flag2)
			{
				val.sharedMaterials = array2;
			}
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: STATIC DOME COMPLETE: replacements=" + num));
	}

	private static CharacterModel GetCharacterModel(CharacterBody body, Component controller)
	{
		CharacterModel val = null;
		ModelLocator component = ((Component)body).GetComponent<ModelLocator>();
		if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.modelTransform))
		{
			val = ((Component)component.modelTransform).GetComponent<CharacterModel>();
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			val = controller.GetComponentInChildren<CharacterModel>(true);
		}
		return val;
	}

	private unsafe static void AggressiveEffectRecolor(GameObject root, Texture redRamp, string label)
	{
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Invalid comparison between Unknown and I4
		//IL_0169: 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_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Invalid comparison between Unknown and I4
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: 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_0212: 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_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_042d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0432: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_044d: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)root))
		{
			Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": aggressive recolor root was NULL."));
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": AGGRESSIVE RECOLOR START root=" + ((Object)root).name));
		Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": rendererCount=" + componentsInChildren.Length));
		Renderer[] array = componentsInChildren;
		Color val3 = default(Color);
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials == null)
			{
				continue;
			}
			Material[] array2 = sharedMaterials;
			foreach (Material val2 in array2)
			{
				if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.shader))
				{
					continue;
				}
				Shader shader = val2.shader;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": MATERIAL renderer=" + ((Object)val).name + ", mat=" + ((Object)val2).name + ", shader=" + ((Object)shader).name));
				int propertyCount = shader.GetPropertyCount();
				for (int k = 0; k < propertyCount; k++)
				{
					string propertyName = shader.GetPropertyName(k);
					ShaderPropertyType propertyType = shader.GetPropertyType(k);
					if ((int)propertyType == 0)
					{
						try
						{
							Color color = val2.GetColor(propertyName);
							float num = Mathf.Max(2.5f, ((Color)(ref color)).maxColorComponent);
							((Color)(ref val3))..ctor(num, num * 0.015f, num * 0.02f, Mathf.Max(color.a, 0.8f));
							val2.SetColor(propertyName, val3);
							string[] obj = new string[10]
							{
								"[NemAmpPersistentCharge] CRIMSON DEBUG: ",
								label,
								": COLOR ",
								((Object)val2).name,
								".",
								propertyName,
								" ",
								null,
								null,
								null
							};
							Color val4 = color;
							obj[7] = ((object)(*(Color*)(&val4))/*cast due to .constrained prefix*/).ToString();
							obj[8] = " -> ";
							val4 = val3;
							obj[9] = ((object)(*(Color*)(&val4))/*cast due to .constrained prefix*/).ToString();
							Debug.LogWarning((object)string.Concat(obj));
						}
						catch (Exception ex)
						{
							Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": COLOR WARNING " + propertyName + " -> " + ex.Message));
						}
					}
					if ((int)propertyType != 4 || !Object.op_Implicit((Object)(object)redRamp))
					{
						continue;
					}
					string text = propertyName.ToLowerInvariant();
					if (text.Contains("remap") || text.Contains("ramp"))
					{
						try
						{
							Texture texture = val2.GetTexture(propertyName);
							val2.SetTexture(propertyName, redRamp);
							Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": TEXTURE " + ((Object)val2).name + "." + propertyName + " " + (Object.op_Implicit((Object)(object)texture) ? ((Object)texture).name : "NULL") + " -> " + ((Object)redRamp).name));
						}
						catch (Exception ex2)
						{
							Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": TEXTURE WARNING " + propertyName + " -> " + ex2.Message));
						}
					}
				}
			}
		}
		ParticleSystem[] componentsInChildren2 = root.GetComponentsInChildren<ParticleSystem>(true);
		ParticleSystem[] array3 = componentsInChildren2;
		foreach (ParticleSystem val5 in array3)
		{
			if (!Object.op_Implicit((Object)(object)val5))
			{
				continue;
			}
			try
			{
				ColorOverLifetimeModule colorOverLifetime = val5.colorOverLifetime;
				if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					MinMaxGradient color2 = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
					Gradient val6 = BuildStrongRedGradient(color2);
					if (val6 != null)
					{
						((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val6);
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": ColorOverLifetime recolored on " + ((Object)val5).name));
					}
				}
			}
			catch (Exception ex3)
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": ColorOverLifetime WARNING " + ((Object)val5).name + " -> " + ex3.Message));
			}
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: " + label + ": AGGRESSIVE RECOLOR COMPLETE."));
	}

	private static Gradient BuildStrongRedGradient(MinMaxGradient source)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		Gradient val = new Gradient();
		GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(new Color(2.5f, 0.025f, 0.03f, 1f), 0f),
			new GradientColorKey(new Color(1.6f, 0.01f, 0.015f, 1f), 1f)
		};
		GradientAlphaKey[] array2 = (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(0f, 1f)
		};
		val.SetKeys(array, array2);
		return val;
	}

	private static void RecolorControllerFields(Component controller, object instance, Texture redRamp, HashSet<int> processedObjects)
	{
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Expected O, but got Unknown
		FieldInfo[] fields = ((object)controller).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER SWEEP: " + fields.Length + " field(s) found."));
		FieldInfo[] array = fields;
		foreach (FieldInfo fieldInfo in array)
		{
			try
			{
				if (typeof(GameObject).IsAssignableFrom(fieldInfo.FieldType))
				{
					if (fieldInfo.Name == "specialBoltVFX")
					{
						Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER SKIP: specialBoltVFX reserved for red strike replacement.");
						continue;
					}
					object? value = fieldInfo.GetValue(instance);
					GameObject val = (GameObject)((value is GameObject) ? value : null);
					if (!Object.op_Implicit((Object)(object)val))
					{
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER NULL: " + fieldInfo.Name));
						continue;
					}
					int instanceID = ((Object)val).GetInstanceID();
					if (processedObjects.Contains(instanceID))
					{
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER DUPLICATE: " + fieldInfo.Name + " -> " + ((Object)val).name));
						continue;
					}
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER RECOLOR: " + fieldInfo.Name + " -> " + ((Object)val).name));
					RecolorObjectHierarchyRed(val, redRamp, "Controller." + fieldInfo.Name);
					processedObjects.Add(instanceID);
				}
				else if (typeof(Material).IsAssignableFrom(fieldInfo.FieldType))
				{
					object? value2 = fieldInfo.GetValue(instance);
					Material val2 = (Material)((value2 is Material) ? value2 : null);
					if (!Object.op_Implicit((Object)(object)val2))
					{
						Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER MATERIAL NULL: " + fieldInfo.Name));
						continue;
					}
					Material val3 = new Material(val2);
					((Object)val3).name = ((Object)val2).name + "_CrimsonBodyRuntime";
					RecolorBodyMaterial(val3, redRamp);
					fieldInfo.SetValue(instance, val3);
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER MATERIAL: " + fieldInfo.Name + " " + ((Object)val2).name + " -> " + ((Object)val3).name));
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CONTROLLER FIELD WARNING: " + fieldInfo.Name + " -> " + ex.Message));
			}
		}
	}

	internal unsafe static void RecolorNemAmpBodyTextures(Material material, string rendererName)
	{
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: 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)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)material))
		{
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY TEXTURE RECOLOR START: renderer=" + rendererName + ", material=" + ((Object)material).name));
		if (material.HasProperty("_MainTex"))
		{
			Texture texture = material.GetTexture("_MainTex");
			if (Object.op_Implicit((Object)(object)texture))
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY MAIN TEXTURE BEFORE: " + rendererName + " = " + ((Object)texture).name));
				Texture2D val = CreateCrimsonTexture(texture, rendererName + "_Main");
				if (Object.op_Implicit((Object)(object)val))
				{
					material.SetTexture("_MainTex", (Texture)(object)val);
					if (material.HasProperty("_Color"))
					{
						material.SetColor("_Color", Color.white);
					}
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY MAIN TEXTURE AFTER: " + rendererName + " = " + ((Object)val).name));
				}
			}
		}
		if (material.HasProperty("_EmTex"))
		{
			Texture texture2 = material.GetTexture("_EmTex");
			if (Object.op_Implicit((Object)(object)texture2))
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY EMISSION TEXTURE BEFORE: " + rendererName + " = " + ((Object)texture2).name));
				Texture2D val2 = CreateCrimsonTexture(texture2, rendererName + "_Emission");
				if (Object.op_Implicit((Object)(object)val2))
				{
					material.SetTexture("_EmTex", (Texture)(object)val2);
					if (material.HasProperty("_EmColor"))
					{
						material.SetColor("_EmColor", new Color(2.6f, 0.05f, 0.065f, 1f));
					}
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY EMISSION TEXTURE AFTER: " + rendererName + " = " + ((Object)val2).name));
				}
			}
		}
		if (rendererName == "Cape" && material.HasProperty("_EmColor"))
		{
			Color color = material.GetColor("_EmColor");
			material.SetColor("_EmColor", Color.black);
			Color val3 = color;
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY CAPE EMISSION: " + ((object)(*(Color*)(&val3))/*cast due to .constrained prefix*/).ToString() + " -> " + ((object)Color.black/*cast due to .constrained prefix*/).ToString()));
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY TEXTURE RECOLOR COMPLETE: " + rendererName));
	}

	private static Texture2D CreateCrimsonTexture(Texture source, string label)
	{
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: 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_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)source))
		{
			Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CRIMSON TEXTURE FAILED: " + label + " source=NULL."));
			return null;
		}
		int instanceID = ((Object)source).GetInstanceID();
		if (crimsonBodyTextureCache.TryGetValue(instanceID, out var value) && Object.op_Implicit((Object)(object)value))
		{
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CRIMSON TEXTURE CACHE HIT: " + ((Object)source).name));
			return value;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CRIMSON TEXTURE START: " + label + ", source=" + ((Object)source).name + ", size=" + source.width + "x" + source.height));
		RenderTexture temporary = RenderTexture.GetTemporary(source.width, source.height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
		RenderTexture active = RenderTexture.active;
		Texture2D val = null;
		try
		{
			Graphics.Blit(source, temporary);
			RenderTexture.active = temporary;
			Texture2D val2 = (Texture2D)(object)((source is Texture2D) ? source : null);
			bool flag = val2 != null && ((Texture)val2).mipmapCount > 1;
			val = new Texture2D(source.width, source.height, (TextureFormat)4, flag);
			val.ReadPixels(new Rect(0f, 0f, (float)source.width, (float)source.height), 0, 0);
			val.Apply(false, false);
			Color32[] pixels = val.GetPixels32();
			int num = 0;
			float num2 = default(float);
			float num3 = default(float);
			float num4 = default(float);
			for (int i = 0; i < pixels.Length; i++)
			{
				Color32 val3 = pixels[i];
				Color val4 = Color32.op_Implicit(val3);
				Color.RGBToHSV(val4, ref num2, ref num3, ref num4);
				if (num3 >= 0.12f && num2 >= 0.45f && num2 <= 0.9f)
				{
					float num5 = 0.995f;
					Color val5 = Color.HSVToRGB(num5, num3, num4);
					val5.a = val4.a;
					pixels[i] = Color32.op_Implicit(val5);
					num++;
				}
			}
			val.SetPixels32(pixels);
			val.Apply(flag, false);
			((Object)val).name = ((Object)source).name + "_CrimsonRuntime";
			Texture2D val6 = (Texture2D)(object)((source is Texture2D) ? source : null);
			if (val6 != null)
			{
				((Texture)val).filterMode = ((Texture)val6).filterMode;
				((Texture)val).wrapMode = ((Texture)val6).wrapMode;
				((Texture)val).anisoLevel = ((Texture)val6).anisoLevel;
			}
			crimsonBodyTextureCache[instanceID] = val;
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CRIMSON TEXTURE COMPLETE: " + ((Object)source).name + " -> " + ((Object)val).name + ", changedPixels=" + num + "/" + pixels.Length));
			return val;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: CRIMSON TEXTURE FAILED: " + ((Object)source).name));
			Debug.LogError((object)ex);
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val);
			}
			return null;
		}
		finally
		{
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
		}
	}

	private static bool SetControllerGameObjectField(Component controller, object instance, string fieldName, GameObject value)
	{
		FieldInfo fieldInfo = AccessTools.Field(((object)controller).GetType(), fieldName);
		if (fieldInfo == null)
		{
			Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: FIELD FAILED: " + fieldName + " not found."));
			return false;
		}
		object? value2 = fieldInfo.GetValue(instance);
		GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: FIELD BEFORE: " + fieldName + "=" + (Object.op_Implicit((Object)(object)val) ? ((Object)val).name : "NULL")));
		fieldInfo.SetValue(instance, value);
		object? value3 = fieldInfo.GetValue(instance);
		GameObject val2 = (GameObject)((value3 is GameObject) ? value3 : null);
		bool result = (Object)(object)val2 == (Object)(object)value;
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: FIELD AFTER: " + fieldName + "=" + (Object.op_Implicit((Object)(object)val2) ? ((Object)val2).name : "NULL") + ", success=" + result));
		return result;
	}

	internal static void RecolorObjectHierarchyRed(GameObject root, Texture redRamp, string label)
	{
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Invalid comparison between Unknown and I4
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Invalid comparison between Unknown and I4
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_049a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)root))
		{
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RECOLOR START: " + label + " root=" + ((Object)root).name));
		Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RECOLOR: " + label + " rendererCount=" + componentsInChildren.Length));
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			Material[] array2 = (Material[])(object)new Material[sharedMaterials.Length];
			for (int j = 0; j < sharedMaterials.Length; j++)
			{
				Material val2 = sharedMaterials[j];
				if (!Object.op_Implicit((Object)(object)val2))
				{
					array2[j] = null;
					continue;
				}
				Material val3 = new Material(val2);
				((Object)val3).name = ((Object)val2).name + "_CrimsonRuntime";
				RecolorMaterialRed(val3, redRamp, strongEffectColor: true);
				array2[j] = val3;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RECOLOR MATERIAL: " + label + " renderer=" + ((Object)val).name + ", " + ((Object)val2).name + " -> " + ((Object)val3).name));
			}
			val.sharedMaterials = array2;
			ParticleSystemRenderer val4 = (ParticleSystemRenderer)(object)((val is ParticleSystemRenderer) ? val : null);
			if (Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)val4.trailMaterial))
			{
				Material trailMaterial = val4.trailMaterial;
				Material val5 = new Material(trailMaterial);
				((Object)val5).name = ((Object)trailMaterial).name + "_CrimsonTrailRuntime";
				RecolorMaterialRed(val5, redRamp, strongEffectColor: true);
				val4.trailMaterial = val5;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RECOLOR TRAIL MATERIAL: " + label + " renderer=" + ((Object)val).name));
			}
		}
		ParticleSystem[] componentsInChildren2 = root.GetComponentsInChildren<ParticleSystem>(true);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RECOLOR: " + label + " particleCount=" + componentsInChildren2.Length));
		ParticleSystem[] array3 = componentsInChildren2;
		foreach (ParticleSystem val6 in array3)
		{
			if (!Object.op_Implicit((Object)(object)val6))
			{
				continue;
			}
			try
			{
				MainModule main = val6.main;
				MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
				if ((int)((MinMaxGradient)(ref startColor)).mode == 0)
				{
					((MainModule)(ref main)).startColor = new MinMaxGradient(ToCrimson(((MinMaxGradient)(ref startColor)).color, minimumBrightness: false));
					continue;
				}
				if ((int)((MinMaxGradient)(ref startColor)).mode == 2)
				{
					((MainModule)(ref main)).startColor = new MinMaxGradient(ToCrimson(((MinMaxGradient)(ref startColor)).colorMin, minimumBrightness: false), ToCrimson(((MinMaxGradient)(ref startColor)).colorMax, minimumBrightness: false));
					continue;
				}
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: PARTICLE GRADIENT PRESERVED: " + label + " particle=" + ((Object)val6).name + ", mode=" + ((object)((MinMaxGradient)(ref startColor)).mode/*cast due to .constrained prefix*/).ToString()));
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: PARTICLE WARNING: " + ((Object)val6).name + " -> " + ex.Message));
			}
		}
		TrailRenderer[] componentsInChildren3 = root.GetComponentsInChildren<TrailRenderer>(true);
		TrailRenderer[] array4 = componentsInChildren3;
		foreach (TrailRenderer val7 in array4)
		{
			if (Object.op_Implicit((Object)(object)val7))
			{
				val7.colorGradient = RecolorGradientRed(val7.colorGradient);
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: TRAIL GRADIENT: " + label + " trail=" + ((Object)val7).name));
			}
		}
		LineRenderer[] componentsInChildren4 = root.GetComponentsInChildren<LineRenderer>(true);
		LineRenderer[] array5 = componentsInChildren4;
		foreach (LineRenderer val8 in array5)
		{
			if (Object.op_Implicit((Object)(object)val8))
			{
				val8.colorGradient = RecolorGradientRed(val8.colorGradient);
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: LINE GRADIENT: " + label + " line=" + ((Object)val8).name));
			}
		}
		Light[] componentsInChildren5 = root.GetComponentsInChildren<Light>(true);
		Light[] array6 = componentsInChildren5;
		foreach (Light val9 in array6)
		{
			if (Object.op_Implicit((Object)(object)val9))
			{
				val9.color = new Color(1f, 0.015f, 0.015f, 1f);
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: LIGHT: " + label + " light=" + ((Object)val9).name));
			}
		}
		RecolorUiImagesByReflection(root, label);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RECOLOR COMPLETE: " + label));
	}

	private unsafe static void RecolorCharacterModelRed(CharacterModel model, Texture redRamp)
	{
		//IL_05be: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0608: Unknown result type (might be due to invalid IL or missing references)
		//IL_060a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0626: Unknown result type (might be due to invalid IL or missing references)
		//IL_062b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)model))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY FAILED: CharacterModel was NULL.");
			return;
		}
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: ==========================================");
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY PASS START: " + ((Object)model).name));
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: ==========================================");
		Renderer[] componentsInChildren = ((Component)model).GetComponentsInChildren<Renderer>(true);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY: rendererCount=" + componentsInChildren.Length));
		Dictionary<Renderer, Material> dictionary = new Dictionary<Renderer, Material>();
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Material[] sharedMaterials = val.sharedMaterials;
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY RENDERER: " + ((Object)val).name + ", type=" + ((object)val).GetType().FullName + ", materialSlots=" + ((sharedMaterials != null) ? sharedMaterials.Length : 0)));
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			Material[] array2 = (Material[])(object)new Material[sharedMaterials.Length];
			for (int j = 0; j < sharedMaterials.Length; j++)
			{
				Material val2 = sharedMaterials[j];
				if (!Object.op_Implicit((Object)(object)val2))
				{
					array2[j] = null;
					continue;
				}
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY BEFORE: renderer=" + ((Object)val).name + ", slot=" + j + ", material=" + ((Object)val2).name + ", shader=" + (Object.op_Implicit((Object)(object)val2.shader) ? ((Object)val2.shader).name : "NULL")));
				Material val3 = new Material(val2);
				((Object)val3).name = ((Object)val2).name + "_CrimsonBodyRuntime";
				RecolorBodyMaterial(val3, redRamp);
				if (((Object)val).name == "Suit" || ((Object)val).name == "Cape")
				{
					RecolorNemAmpBodyTextures(val3, ((Object)val).name);
				}
				array2[j] = val3;
				if (j == 0 && !dictionary.ContainsKey(val))
				{
					dictionary.Add(val, val3);
				}
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY AFTER: renderer=" + ((Object)val).name + ", slot=" + j + ", material=" + ((Object)val3).name));
			}
			val.sharedMaterials = array2;
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY ASSIGNED LIVE MATERIALS: " + ((Object)val).name));
		}
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY BASE INFO: Looking for baseRendererInfos.");
		FieldInfo fieldInfo = AccessTools.Field(((object)model).GetType(), "baseRendererInfos");
		if (fieldInfo == null)
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY BASE INFO FAILED: baseRendererInfos field not found.");
		}
		else if (!(fieldInfo.GetValue(model) is Array array3))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY BASE INFO FAILED: baseRendererInfos was NULL.");
		}
		else
		{
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY BASE INFO: entryCount=" + array3.Length));
			int num = 0;
			for (int k = 0; k < array3.Length; k++)
			{
				object value = array3.GetValue(k);
				if (value == null)
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY INFO[" + k + "] was NULL."));
					continue;
				}
				Type type = value.GetType();
				FieldInfo fieldInfo2 = AccessTools.Field(type, "renderer");
				FieldInfo fieldInfo3 = AccessTools.Field(type, "defaultMaterial");
				if (fieldInfo2 == null || fieldInfo3 == null)
				{
					Debug.LogError((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY INFO[" + k + "] FAILED: fields missing. type=" + type.FullName));
					continue;
				}
				object? value2 = fieldInfo2.GetValue(value);
				Renderer val4 = (Renderer)((value2 is Renderer) ? value2 : null);
				object? value3 = fieldInfo3.GetValue(value);
				Material val5 = (Material)((value3 is Material) ? value3 : null);
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY INFO BEFORE [" + k + "]: renderer=" + (Object.op_Implicit((Object)(object)val4) ? ((Object)val4).name : "NULL") + ", defaultMaterial=" + (Object.op_Implicit((Object)(object)val5) ? ((Object)val5).name : "NULL")));
				if (!Object.op_Implicit((Object)(object)val4) || !dictionary.TryGetValue(val4, out var value4))
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY INFO[" + k + "]: no matching crimson renderer material."));
					continue;
				}
				fieldInfo3.SetValue(value, value4);
				array3.SetValue(value, k);
				num++;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY INFO AFTER [" + k + "]: renderer=" + ((Object)val4).name + ", defaultMaterial=" + ((Object)value4).name));
			}
			fieldInfo.SetValue(model, array3);
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY BASE INFO COMPLETE: patched=" + num));
		}
		Light[] componentsInChildren2 = ((Component)model).GetComponentsInChildren<Light>(true);
		Light[] array4 = componentsInChildren2;
		foreach (Light val6 in array4)
		{
			if (Object.op_Implicit((Object)(object)val6))
			{
				Color color = val6.color;
				val6.color = new Color(1f, 0.02f, 0.02f, 1f);
				string[] obj = new string[6]
				{
					"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY LIGHT: ",
					((Object)val6).name,
					" ",
					null,
					null,
					null
				};
				Color val7 = color;
				obj[3] = ((object)(*(Color*)(&val7))/*cast due to .constrained prefix*/).ToString();
				obj[4] = " -> ";
				obj[5] = ((object)val6.color/*cast due to .constrained prefix*/).ToString();
				Debug.LogWarning((object)string.Concat(obj));
			}
		}
		MethodInfo methodInfo = AccessTools.Method(((object)model).GetType(), "UpdateMaterials", Type.EmptyTypes, (Type[])null);
		if (methodInfo != null)
		{
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY: Calling CharacterModel.UpdateMaterials().");
			try
			{
				methodInfo.Invoke(model, null);
				Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY: UpdateMaterials() completed.");
			}
			catch (Exception ex)
			{
				Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY: UpdateMaterials() threw:");
				Debug.LogError((object)ex);
			}
		}
		else
		{
			Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY: No zero-argument UpdateMaterials() found.");
		}
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY READBACK START.");
		Renderer[] array5 = componentsInChildren;
		foreach (Renderer val8 in array5)
		{
			if (!Object.op_Implicit((Object)(object)val8))
			{
				continue;
			}
			Material[] sharedMaterials2 = val8.sharedMaterials;
			if (sharedMaterials2 != null)
			{
				for (int n = 0; n < sharedMaterials2.Length; n++)
				{
					Material val9 = sharedMaterials2[n];
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY READBACK: renderer=" + ((Object)val8).name + ", slot=" + n + ", material=" + (Object.op_Implicit((Object)(object)val9) ? ((Object)val9).name : "NULL")));
				}
			}
		}
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: ==========================================");
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY PASS COMPLETE.");
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: ==========================================");
	}

	internal unsafe static void RecolorBodyMaterial(Material material, Texture redRamp)
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: 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)
		if (!Object.op_Implicit((Object)(object)material))
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)redRamp) && material.HasProperty("_RemapTex"))
		{
			material.SetTexture("_RemapTex", redRamp);
		}
		if (material.HasProperty("_Color"))
		{
			Color color = material.GetColor("_Color");
			material.SetColor("_Color", new Color(0.72f, 0.035f, 0.045f, color.a));
			string[] obj = new string[6]
			{
				"[NemAmpPersistentCharge] CRIMSON DEBUG: BODY COLOR: ",
				((Object)material).name,
				" _Color ",
				null,
				null,
				null
			};
			Color val = color;
			obj[3] = ((object)(*(Color*)(&val))/*cast due to .constrained prefix*/).ToString();
			obj[4] = " -> ";
			obj[5] = ((object)material.GetColor("_Color")/*cast due to .constrained prefix*/).ToString();
			Debug.LogWarning((object)string.Concat(obj));
		}
		string[] array = new string[6] { "_EmissionColor", "_EmColor", "_EmColor0", "_EmColor1", "_FresnelColor", "_RimColor" };
		string[] array2 = array;
		foreach (string text in array2)
		{
			if (material.HasProperty(text))
			{
				Color color2 = material.GetColor(text);
				float num = Mathf.Max(2f, ((Color)(ref color2)).maxColorComponent);
				material.SetColor(text, new Color(num, num * 0.02f, num * 0.025f, color2.a));
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: BODY EMISSION: " + ((Object)material).name + "." + text));
			}
		}
	}

	private unsafe static void RecolorMaterialRed(Material material, Texture redRamp, bool strongEffectColor)
	{
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: 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_0154: 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_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)material))
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)redRamp) && material.HasProperty("_RemapTex"))
		{
			material.SetTexture("_RemapTex", redRamp);
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: MATERIAL REMAP: " + ((Object)material).name));
		}
		string[] array = new string[10] { "_Color", "_TintColor", "_EmissionColor", "_EmColor", "_EmColor0", "_EmColor1", "_MainColor", "_CloudColor", "_FresnelColor", "_RimColor" };
		string[] array2 = array;
		Color val = default(Color);
		foreach (string text in array2)
		{
			if (material.HasProperty(text))
			{
				Color color = material.GetColor(text);
				float num = Mathf.Max(strongEffectColor ? 1.35f : 1f, ((Color)(ref color)).maxColorComponent);
				((Color)(ref val))..ctor(num, num * 0.025f, num * 0.03f, color.a);
				material.SetColor(text, val);
				string[] obj = new string[8]
				{
					"[NemAmpPersistentCharge] CRIMSON DEBUG: MATERIAL COLOR: ",
					((Object)material).name,
					".",
					text,
					" ",
					null,
					null,
					null
				};
				Color val2 = color;
				obj[5] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString();
				obj[6] = " -> ";
				val2 = val;
				obj[7] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString();
				Debug.LogWarning((object)string.Concat(obj));
			}
		}
	}

	private unsafe static void BoostRangeIndicatorVisibility(GameObject root)
	{
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: 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)
		if (!Object.op_Implicit((Object)(object)root))
		{
			Debug.LogError((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE BOOST FAILED: root was NULL.");
			return;
		}
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE BOOST START: " + ((Object)root).name));
		MeshRenderer[] componentsInChildren = root.GetComponentsInChildren<MeshRenderer>(true);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE BOOST: MeshRenderer count=" + componentsInChildren.Length));
		MeshRenderer[] array = componentsInChildren;
		Color val3 = default(Color);
		foreach (MeshRenderer val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			Material[] array2 = sharedMaterials;
			foreach (Material val2 in array2)
			{
				if (!Object.op_Implicit((Object)(object)val2))
				{
					continue;
				}
				if (((Object)val).name.IndexOf("Radius", StringComparison.OrdinalIgnoreCase) < 0 && ((Object)val2).name.IndexOf("StormRange", StringComparison.OrdinalIgnoreCase) < 0)
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE BOOST SKIP: renderer=" + ((Object)val).name + ", material=" + ((Object)val2).name));
					continue;
				}
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE BOOST TARGET FOUND: renderer=" + ((Object)val).name + ", material=" + ((Object)val2).name + ", oldQueue=" + val2.renderQueue + ", oldSortingOrder=" + ((Renderer)val).sortingOrder));
				if (val2.HasProperty("_TintColor"))
				{
					Color color = val2.GetColor("_TintColor");
					((Color)(ref val3))..ctor(Mathf.Max(7f, color.r), 0.12f, 0.12f, 1f);
					val2.SetColor("_TintColor", val3);
					Color val4 = color;
					string? text = ((object)(*(Color*)(&val4))/*cast due to .constrained prefix*/).ToString();
					val4 = val3;
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE _TintColor: " + text + " -> " + ((object)(*(Color*)(&val4))/*cast due to .constrained prefix*/).ToString()));
				}
				SetRangeFloat(val2, "_Boost", 3.25f);
				SetRangeFloat(val2, "_AlphaBoost", 2f);
				SetRangeFloat(val2, "_IntersectionStrength", 1.35f);
				SetRangeFloat(val2, "_ExternalAlpha", 1f);
				SetRangeFloat(val2, "_SoftPower", 0.85f);
				int renderQueue = val2.renderQueue;
				int sortingOrder = ((Renderer)val).sortingOrder;
				val2.renderQueue = 3500;
				((Renderer)val).sortingOrder = 50;
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE ORDER: queue " + renderQueue + " -> " + val2.renderQueue + ", sortingOrder " + sortingOrder + " -> " + ((Renderer)val).sortingOrder));
				Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE FINAL: Boost=" + ReadRangeFloat(val2, "_Boost") + ", AlphaBoost=" + ReadRangeFloat(val2, "_AlphaBoost") + ", IntersectionStrength=" + ReadRangeFloat(val2, "_IntersectionStrength")));
			}
		}
		Debug.LogWarning((object)"[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE BOOST COMPLETE.");
	}

	private static void SetRangeFloat(Material material, string property, float value)
	{
		if (!Object.op_Implicit((Object)(object)material) || !material.HasProperty(property))
		{
			Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE PROPERTY MISSING: " + property));
			return;
		}
		float num = material.GetFloat(property);
		material.SetFloat(property, value);
		Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: RANGE FLOAT: " + property + " " + num + " -> " + value));
	}

	private static string ReadRangeFloat(Material material, string property)
	{
		if (!Object.op_Implicit((Object)(object)material) || !material.HasProperty(property))
		{
			return "MISSING";
		}
		return material.GetFloat(property).ToString("0.###");
	}

	private static Color ToCrimson(Color source, bool minimumBrightness)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		float num = ((Color)(ref source)).maxColorComponent;
		if (minimumBrightness)
		{
			num = Mathf.Max(1f, num);
		}
		if (num <= 0.001f)
		{
			return source;
		}
		return new Color(num, num * 0.025f, num * 0.03f, source.a);
	}

	private static Gradient RecolorGradientRed(Gradient original)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_003b: 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_0053: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		if (original == null)
		{
			return original;
		}
		Gradient val = new Gradient();
		GradientColorKey[] colorKeys = original.colorKeys;
		GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[colorKeys.Length];
		for (int i = 0; i < colorKeys.Length; i++)
		{
			array[i] = new GradientColorKey(ToCrimson(colorKeys[i].color, minimumBrightness: false), colorKeys[i].time);
		}
		GradientAlphaKey[] alphaKeys = original.alphaKeys;
		GradientAlphaKey[] array2 = (GradientAlphaKey[])(object)new GradientAlphaKey[alphaKeys.Length];
		for (int j = 0; j < alphaKeys.Length; j++)
		{
			array2[j] = new GradientAlphaKey(alphaKeys[j].alpha, alphaKeys[j].time);
		}
		val.SetKeys(array, array2);
		return val;
	}

	private unsafe static void RecolorUiImagesByReflection(GameObject root, string label)
	{
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: 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_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true);
		Component[] array = componentsInChildren;
		Color val3 = default(Color);
		foreach (Component val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Type type = ((object)val).GetType();
			string fullName = type.FullName;
			if (fullName != "UnityEngine.UI.Image" && fullName != "UnityEngine.UI.RawImage")
			{
				continue;
			}
			PropertyInfo property = type.GetProperty("color", BindingFlags.Instance | BindingFlags.Public);
			if (!(property == null) && !(property.PropertyType != typeof(Color)) && property.CanRead && property.CanWrite)
			{
				try
				{
					Color val2 = (Color)property.GetValue(val, null);
					((Color)(ref val3))..ctor(Mathf.Max(1f, ((Color)(ref val2)).maxColorComponent), 0.025f, 0.03f, val2.a);
					property.SetValue(val, val3, null);
					string[] obj = new string[8]
					{
						"[NemAmpPersistentCharge] CRIMSON DEBUG: UI IMAGE: ",
						label,
						" object=",
						((Object)val).name,
						" ",
						null,
						null,
						null
					};
					Color val4 = val2;
					obj[5] = ((object)(*(Color*)(&val4))/*cast due to .constrained prefix*/).ToString();
					obj[6] = " -> ";
					val4 = val3;
					obj[7] = ((object)(*(Color*)(&val4))/*cast due to .constrained prefix*/).ToString();
					Debug.LogWarning((object)string.Concat(obj));
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[NemAmpPersistentCharge] CRIMSON DEBUG: UI IMAGE WARNING: " +