Decompiled source of YharimPaladin v1.0.6

YharimPaladin.dll

Decompiled 12 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using PaladinMod.Modules;
using RoR2;
using RoR2.Projectile;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("YharimPaladin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("YharimPaladin")]
[assembly: AssemblyTitle("YharimPaladin")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace YharimPaladin
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.fergerdeter.YharimPaladin", "YharimPaladin", "1.0.6")]
	public class YharimPaladinPlugin : BaseUnityPlugin
	{
		public enum EffectColor
		{
			Flame,
			Red,
			Yellow
		}

		public struct ExtraBone
		{
			public string name;

			public string parent;

			public Matrix4x4 rest;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static RegisterEffectsEvent <0>__RegisterPaladinEffects;

			public static Action <1>__SetLanguageTokens;
		}

		public const string Guid = "com.fergerdeter.YharimPaladin";

		private const string BodyName = "RobPaladinBody";

		private const string NameToken = "FERGERDETER_SKIN_YHARIMPALADIN_NAME";

		private const string HGStandard = "RoR2/Base/Shaders/HGStandard.shader";

		private static ConfigEntry<bool> highPoly;

		private static ConfigEntry<bool> hideCape;

		private static ConfigEntry<bool> hairSway;

		private static ConfigEntry<float> emissionPower;

		private static ConfigEntry<EffectColor> effectColor;

		private static GameObject prefabHolder;

		private static Texture2D tintRamp;

		private void Awake()
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			highPoly = ((BaseUnityPlugin)this).Config.Bind<bool>("Model", "HighPoly", false, "Полная модель (~106k треугольников тело + 30k меч) вместо упрощённой (~22k + 2.5k).");
			hideCape = ((BaseUnityPlugin)this).Config.Bind<bool>("Model", "HideCape", true, "Скрыть плащ Паладина (у Ярима сзади волосы).");
			hairSway = ((BaseUnityPlugin)this).Config.Bind<bool>("Model", "HairSway", true, "Грива развевается (своя цепочка костей с физикой). false — грива жёстко следует за головой.");
			emissionPower = ((BaseUnityPlugin)this).Config.Bind<float>("Material", "EmissionPower", 2.4f, "Яркость свечения (_EmPower в HGStandard).");
			effectColor = ((BaseUnityPlugin)this).Config.Bind<EffectColor>("Effects", "EffectColor", EffectColor.Flame, "Цвет эффектов атак: Flame — огненный красно-оранжевый, Red — красный, Yellow — солнечный жёлтый.");
			object obj = <>O.<0>__RegisterPaladinEffects;
			if (obj == null)
			{
				RegisterEffectsEvent val = RegisterPaladinEffects;
				<>O.<0>__RegisterPaladinEffects = val;
				obj = (object)val;
			}
			Effects.OnRegisterEffects += (RegisterEffectsEvent)obj;
			Language.onCurrentLanguageChanged += SetLanguageTokens;
			if (Language.currentLanguage != null)
			{
				SetLanguageTokens();
			}
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)AddSkin);
		}

		private static void RegisterPaladinEffects()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			PaladinSkinInfo val = new PaladinSkinInfo
			{
				skinNameToken = "FERGERDETER_SKIN_YHARIMPALADIN_NAME",
				swingSoundString = "PaladinSwing",
				isWeaponBlunt = false
			};
			switch (effectColor.Value)
			{
			case EffectColor.Red:
				val.passiveEffectType = (PassiveEffect)8;
				val.hitEffect = Asset.hitFXRed;
				val.swingEffect = Asset.swordSwingRed;
				val.spinSlashEffect = Asset.spinningSlashFXRed;
				val.empoweredSpinSlashEffect = Asset.spinningSlashEmpoweredFXRed;
				val.CSSEffect = (PaladinCSSEffect)7;
				val.eyeTrailColor = new Color(1f, 0.15f, 0.1f);
				break;
			case EffectColor.Yellow:
				val.passiveEffectType = (PassiveEffect)4;
				val.hitEffect = Asset.hitFXYellow;
				val.swingEffect = Asset.swordSwingYellow;
				val.spinSlashEffect = Asset.spinningSlashFXYellow;
				val.empoweredSpinSlashEffect = Asset.spinningSlashEmpoweredFXYellow;
				val.CSSEffect = (PaladinCSSEffect)4;
				val.eyeTrailColor = new Color(1f, 0.85f, 0.3f);
				break;
			default:
				val.passiveEffectType = (PassiveEffect)10;
				val.hitEffect = Asset.hitFXRed;
				val.swingEffect = Asset.swordSwingFlame;
				val.spinSlashEffect = Asset.spinningSlashFXFlame;
				val.empoweredSpinSlashEffect = Asset.spinningSlashEmpoweredFXFlame;
				val.CSSEffect = (PaladinCSSEffect)10;
				val.eyeTrailColor = new Color(1f, 0.45f, 0.1f);
				break;
			}
			val.swordBeamProjectileColor = EffectTint();
			Effects.AddSkinInfo(val);
		}

		private static Color EffectTint()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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)
			return (Color)(effectColor.Value switch
			{
				EffectColor.Red => new Color(1f, 0.1f, 0.05f), 
				EffectColor.Yellow => new Color(1f, 0.8f, 0.2f), 
				_ => new Color(1f, 0.35f, 0.05f), 
			});
		}

		private ProjectileGhostReplacement[] CreateGhostReplacements()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_00ae: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			List<ProjectileGhostReplacement> list = new List<ProjectileGhostReplacement>();
			Color tint = EffectTint();
			GameObject swordBeamProjectile = Projectiles.swordBeamProjectile;
			if (Object.op_Implicit((Object)(object)swordBeamProjectile))
			{
				PaladinSkinInfo skinInfo = Effects.GetSkinInfo("FERGERDETER_SKIN_YHARIMPALADIN_NAME");
				GameObject projectileGhostReplacementPrefab = ((skinInfo.skinNameToken == "FERGERDETER_SKIN_YHARIMPALADIN_NAME" && Object.op_Implicit((Object)(object)skinInfo.swordBeamProjectileGhost)) ? skinInfo.swordBeamProjectileGhost : RecolorClone(swordBeamProjectile.GetComponent<ProjectileController>().ghostPrefab, tint));
				list.Add(new ProjectileGhostReplacement
				{
					projectilePrefab = swordBeamProjectile,
					projectileGhostReplacementPrefab = projectileGhostReplacementPrefab
				});
			}
			GameObject shockwave = Projectiles.shockwave;
			GameObject val = (Object.op_Implicit((Object)(object)shockwave) ? shockwave.GetComponent<ProjectileController>().ghostPrefab : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				list.Add(new ProjectileGhostReplacement
				{
					projectilePrefab = shockwave,
					projectileGhostReplacementPrefab = RecolorClone(val, tint)
				});
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Замены снарядов: " + string.Join(", ", list.Select((ProjectileGhostReplacement r) => ((Object)r.projectilePrefab).name))));
			return list.ToArray();
		}

		private static GameObject RecolorClone(GameObject src, Color tint)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0046: 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_0187: 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)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_01e1: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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)
			if (!Object.op_Implicit((Object)(object)src))
			{
				return null;
			}
			if (!Object.op_Implicit((Object)(object)prefabHolder))
			{
				prefabHolder = new GameObject("YharimPaladinPrefabs");
				prefabHolder.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)prefabHolder);
			}
			if (!Object.op_Implicit((Object)(object)tintRamp))
			{
				tintRamp = MakeRamp(tint);
			}
			GameObject val = Object.Instantiate<GameObject>(src, prefabHolder.transform);
			((Object)val).name = ((Object)src).name + "Yharim";
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				Material[] sharedMaterials = val2.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (!Object.op_Implicit((Object)(object)sharedMaterials[j]))
					{
						continue;
					}
					Material val3 = new Material(sharedMaterials[j]);
					string[] array = new string[2] { "_TintColor", "_Color" };
					foreach (string text in array)
					{
						if (val3.HasProperty(text))
						{
							float a = val3.GetColor(text).a;
							val3.SetColor(text, new Color(tint.r, tint.g, tint.b, a));
						}
					}
					if (val3.HasProperty("_RemapTex"))
					{
						val3.SetTexture("_RemapTex", (Texture)(object)tintRamp);
					}
					sharedMaterials[j] = val3;
				}
				val2.sharedMaterials = sharedMaterials;
			}
			ParticleSystem[] componentsInChildren2 = val.GetComponentsInChildren<ParticleSystem>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				MainModule main = componentsInChildren2[i].main;
				MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
				float a2 = ((MinMaxGradient)(ref startColor)).color.a;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(tint.r, tint.g, tint.b, a2));
			}
			Light[] componentsInChildren3 = val.GetComponentsInChildren<Light>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				componentsInChildren3[i].color = tint;
			}
			return val;
		}

		private static Texture2D MakeRamp(Color tint)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(256, 4, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				name = "YharimRamp"
			};
			Color val2 = Color.Lerp(tint, new Color(1f, 0.95f, 0.8f), 0.6f);
			for (int i = 0; i < 256; i++)
			{
				float num = (float)i / 255f;
				Color val3 = ((num < 0.5f) ? Color.Lerp(tint * 0.25f, tint, num * 2f) : Color.Lerp(tint, val2, (num - 0.5f) * 2f));
				val3.a = num;
				for (int j = 0; j < 4; j++)
				{
					val.SetPixel(i, j, val3);
				}
			}
			val.Apply();
			return val;
		}

		private static void SetLanguageTokens()
		{
			Language currentLanguage = Language.currentLanguage;
			if (currentLanguage != null)
			{
				currentLanguage.SetStringByToken("FERGERDETER_SKIN_YHARIMPALADIN_NAME", (currentLanguage.name == "ru") ? "Ярим" : "Yharim");
			}
			if (currentLanguage != Language.english)
			{
				Language english = Language.english;
				if (english != null)
				{
					english.SetStringByToken("FERGERDETER_SKIN_YHARIMPALADIN_NAME", "Yharim");
				}
			}
		}

		private void AddSkin()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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_01c9: 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_01f7: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = BodyCatalog.FindBodyPrefab("RobPaladinBody");
				if (!Object.op_Implicit((Object)(object)val))
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"RobPaladinBody не найден, скин не добавлен");
					return;
				}
				GameObject gameObject = ((Component)val.GetComponent<ModelLocator>().modelTransform).gameObject;
				ModelSkinController component = gameObject.GetComponent<ModelSkinController>();
				CharacterModel component2 = gameObject.GetComponent<CharacterModel>();
				Renderer[] renderers = component2.baseRendererInfos.Select((RendererInfo i) => i.renderer).ToArray();
				SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)Find("meshPaladinDefault", 5);
				Renderer renderer = Find("meshPaladinDefault_Sword", 0);
				Renderer val3 = Find("meshPaladinDefault_Cape", 1);
				Matrix4x4[] bindposes = val2.sharedMesh.bindposes;
				if (bindposes.Length != 135 || val2.bones.Length != 135)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)$"Ожидалось 135 костей, у Паладина {val2.bones.Length} (bindposes {bindposes.Length})");
				}
				string text = (highPoly.Value ? "full" : "low");
				ExtraBone[] extras;
				Mesh val4 = LoadMesh("YharimBody_" + text + ".yhm", "YharimBody", bindposes, useExtras: true, out extras);
				ExtraBone[] extras2;
				Mesh val5 = LoadMesh("YharimSword_" + text + ".yhm", "YharimSword", bindposes, useExtras: false, out extras2);
				SetupHairRig(gameObject, val4, bindposes, extras);
				if (Object.op_Implicit((Object)(object)Prefabs.paladinDisplayPrefab))
				{
					SetupHairRig(Prefabs.paladinDisplayPrefab, val4, bindposes, extras);
				}
				Material material = CreateMaterial();
				SkinDefParams val6 = ScriptableObject.CreateInstance<SkinDefParams>();
				((Object)val6).name = "YharimPaladinParams";
				val6.rendererInfos = (RendererInfo[])(object)new RendererInfo[2]
				{
					RendererInfo((Renderer)(object)val2, material),
					RendererInfo(renderer, material)
				};
				val6.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[2]
				{
					new MeshReplacement
					{
						renderer = (Renderer)(object)val2,
						mesh = val4
					},
					new MeshReplacement
					{
						renderer = renderer,
						mesh = val5
					}
				};
				val6.gameObjectActivations = (GameObjectActivation[])((!hideCape.Value) ? ((Array)Array.Empty<GameObjectActivation>()) : ((Array)new GameObjectActivation[1]
				{
					new GameObjectActivation
					{
						gameObject = ((Component)val3).gameObject,
						shouldActivate = false
					}
				}));
				val6.projectileGhostReplacements = CreateGhostReplacements();
				SkinDef val7 = ScriptableObject.CreateInstance<SkinDef>();
				((Object)val7).name = "YharimPaladin";
				val7.nameToken = "FERGERDETER_SKIN_YHARIMPALADIN_NAME";
				val7.icon = LoadSprite("icon_skin.png");
				val7.rootObject = gameObject;
				val7.baseSkins = (SkinDef[])((component.skins.Length == 0) ? ((Array)Array.Empty<SkinDef>()) : ((Array)new SkinDef[1] { component.skins[0] }));
				val7.skinDefParams = val6;
				Array.Resize(ref component.skins, component.skins.Length + 1);
				component.skins[component.skins.Length - 1] = val7;
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Скин Ярима добавлен ({text}: тело {val4.vertexCount} верш., меч {val5.vertexCount} верш.)");
				Renderer Find(string goName, int fallback)
				{
					return ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => Object.op_Implicit((Object)(object)r) && ((Object)((Component)r).gameObject).name == goName)) ?? renderers[fallback];
				}
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Не удалось добавить скин Ярима: {arg}");
			}
		}

		private static RendererInfo RendererInfo(Renderer renderer, Material material)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			return new RendererInfo
			{
				renderer = renderer,
				defaultMaterial = material,
				defaultShadowCastingMode = (ShadowCastingMode)2,
				ignoreOverlays = false
			};
		}

		private static Material CreateMaterial()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			Material val = new Material(Addressables.LoadAssetAsync<Shader>((object)"RoR2/Base/Shaders/HGStandard.shader").WaitForCompletion())
			{
				name = "YharimMat"
			};
			val.SetTexture("_MainTex", (Texture)(object)LoadColorTexture("yharim_atlas.png"));
			val.SetColor("_Color", Color.white);
			val.SetTexture("_EmTex", (Texture)(object)LoadColorTexture("yharim_emission.png"));
			val.SetColor("_EmColor", Color.white);
			val.SetFloat("_EmPower", emissionPower.Value);
			val.SetFloat("_Cull", 0f);
			return val;
		}

		private static Stream Resource(string name)
		{
			return Assembly.GetExecutingAssembly().GetManifestResourceStream("YharimPaladin." + name) ?? throw new FileNotFoundException("Нет ресурса " + name);
		}

		private static Texture2D LoadTexture(string name)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0038: Expected O, but got Unknown
			//IL_003a: Expected O, but got Unknown
			using Stream stream = Resource(name);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, false)
			{
				name = name,
				wrapMode = (TextureWrapMode)1
			};
			ImageConversion.LoadImage(val, memoryStream.ToArray());
			return val;
		}

		private static Texture2D LoadColorTexture(string name)
		{
			//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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			Texture2D val = LoadTexture(name);
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				pixels[i] = new Color(Mathf.GammaToLinearSpace(pixels[i].r), Mathf.GammaToLinearSpace(pixels[i].g), Mathf.GammaToLinearSpace(pixels[i].b), pixels[i].a);
			}
			Texture2D val2 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true, true)
			{
				name = name,
				wrapMode = (TextureWrapMode)1
			};
			val2.SetPixels(pixels);
			val2.Apply(true);
			Object.Destroy((Object)(object)val);
			return val2;
		}

		private static Sprite LoadSprite(string name)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadTexture(name);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		private static Mesh LoadMesh(string resource, string name, Matrix4x4[] bindposes, bool useExtras, out ExtraBone[] extras)
		{
			//IL_009f: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Expected O, but got Unknown
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			using GZipStream input = new GZipStream(Resource(resource), CompressionMode.Decompress);
			using BinaryReader binaryReader = new BinaryReader(input);
			string text = new string(binaryReader.ReadChars(4));
			if (text != "YHM1" && text != "YHM2")
			{
				throw new InvalidDataException(resource + ": неверный формат");
			}
			int num = binaryReader.ReadInt32();
			int num2 = binaryReader.ReadInt32();
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			BoneWeight[] array4 = (BoneWeight[])(object)new BoneWeight[num];
			int[] array5 = new int[num2];
			for (int i = 0; i < num; i++)
			{
				array[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int j = 0; j < num; j++)
			{
				array2[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int k = 0; k < num; k++)
			{
				array3[k] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int l = 0; l < num; l++)
			{
				((BoneWeight)(ref array4[l])).boneIndex0 = binaryReader.ReadByte();
				((BoneWeight)(ref array4[l])).boneIndex1 = binaryReader.ReadByte();
				((BoneWeight)(ref array4[l])).boneIndex2 = binaryReader.ReadByte();
				((BoneWeight)(ref array4[l])).boneIndex3 = binaryReader.ReadByte();
			}
			for (int m = 0; m < num; m++)
			{
				((BoneWeight)(ref array4[m])).weight0 = binaryReader.ReadSingle();
				((BoneWeight)(ref array4[m])).weight1 = binaryReader.ReadSingle();
				((BoneWeight)(ref array4[m])).weight2 = binaryReader.ReadSingle();
				((BoneWeight)(ref array4[m])).weight3 = binaryReader.ReadSingle();
			}
			for (int n = 0; n < num2; n++)
			{
				array5[n] = binaryReader.ReadInt32();
			}
			extras = Array.Empty<ExtraBone>();
			if (text == "YHM2")
			{
				extras = new ExtraBone[binaryReader.ReadInt32()];
				for (int num3 = 0; num3 < extras.Length; num3++)
				{
					extras[num3].name = new string(binaryReader.ReadChars(binaryReader.ReadByte()));
					extras[num3].parent = new string(binaryReader.ReadChars(binaryReader.ReadByte()));
					Matrix4x4 rest = default(Matrix4x4);
					for (int num4 = 0; num4 < 16; num4++)
					{
						((Matrix4x4)(ref rest))[num4 / 4, num4 % 4] = binaryReader.ReadSingle();
					}
					extras[num3].rest = rest;
				}
			}
			if (useExtras && extras.Length != 0)
			{
				bindposes = bindposes.Concat(extras.Select((ExtraBone e) => ((Matrix4x4)(ref e.rest)).inverse)).ToArray();
			}
			Mesh val = new Mesh
			{
				name = name,
				indexFormat = (IndexFormat)(num > 65535),
				vertices = array,
				normals = array2,
				uv = array3,
				boneWeights = array4,
				bindposes = bindposes,
				triangles = array5
			};
			val.RecalculateBounds();
			val.RecalculateTangents();
			return val;
		}

		private static void SetupHairRig(GameObject modelRoot, Mesh bodyMesh, Matrix4x4[] baseBindposes, ExtraBone[] extras)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			SkinnedMeshRenderer val = ((IEnumerable<SkinnedMeshRenderer>)modelRoot.GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer r) => ((Object)r).name == "meshPaladinDefault"));
			if (!Object.op_Implicit((Object)(object)val) || extras.Length == 0)
			{
				return;
			}
			Transform[] baseBones = val.bones;
			int num = Array.FindIndex(baseBones, (Transform b) => Object.op_Implicit((Object)(object)b) && ((Object)b).name == "head");
			if (num < 0)
			{
				return;
			}
			Dictionary<string, (Transform, Matrix4x4)> dictionary = new Dictionary<string, (Transform, Matrix4x4)>();
			Transform[] array = (Transform[])(object)new Transform[extras.Length];
			for (int num2 = 0; num2 < extras.Length; num2++)
			{
				ExtraBone extraBone = extras[num2];
				Transform val2;
				Matrix4x4 val3;
				if (dictionary.TryGetValue(extraBone.parent, out var value))
				{
					val2 = value.Item1;
					val3 = ((Matrix4x4)(ref value.Item2)).inverse * extraBone.rest;
				}
				else
				{
					val2 = Bone(extraBone.parent) ?? baseBones[num];
					val3 = baseBindposes[Array.IndexOf(baseBones, val2)] * extraBone.rest;
				}
				Transform transform = new GameObject(extraBone.name).transform;
				transform.SetParent(val2, false);
				transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val3)).GetColumn(3));
				transform.localRotation = ((Matrix4x4)(ref val3)).rotation;
				transform.localScale = ((Matrix4x4)(ref val3)).lossyScale;
				dictionary[extraBone.name] = (transform, extraBone.rest);
				array[num2] = transform;
			}
			DynamicBone val4 = null;
			if (hairSway.Value)
			{
				val4 = ((Component)array[0]).gameObject.AddComponent<DynamicBone>();
				val4.m_Root = array[0];
				val4.m_UpdateRate = 60f;
				val4.m_Damping = 0.2f;
				val4.m_Elasticity = 0.06f;
				val4.m_Stiffness = 0.25f;
				val4.m_Inert = 0.45f;
				val4.m_Radius = 0.06f;
				val4.m_Gravity = new Vector3(0f, -0.02f, 0f);
				val4.m_Colliders = new List<DynamicBoneCollider>();
				(string, float)[] array2 = new(string, float)[2]
				{
					("spine.003", 0.3f),
					("spine.001", 0.28f)
				};
				for (int num3 = 0; num3 < array2.Length; num3++)
				{
					(string, float) tuple = array2[num3];
					string item = tuple.Item1;
					float item2 = tuple.Item2;
					Transform val5 = Bone(item);
					if (Object.op_Implicit((Object)(object)val5))
					{
						DynamicBoneCollider val6 = ((Component)val5).gameObject.AddComponent<DynamicBoneCollider>();
						val6.m_Radius = item2;
						val4.m_Colliders.Add(val6);
					}
				}
				((Behaviour)val4).enabled = false;
			}
			YharimHairRig yharimHairRig = modelRoot.AddComponent<YharimHairRig>();
			yharimHairRig.smr = val;
			yharimHairRig.baseBones = baseBones;
			yharimHairRig.hairBones = array;
			yharimHairRig.ourMesh = bodyMesh;
			yharimHairRig.dynamicBone = val4;
			Transform Bone(string n)
			{
				return ((IEnumerable<Transform>)baseBones).FirstOrDefault((Func<Transform, bool>)((Transform b) => Object.op_Implicit((Object)(object)b) && ((Object)b).name == n));
			}
		}
	}
	public class YharimHairRig : MonoBehaviour
	{
		public SkinnedMeshRenderer smr;

		public Transform[] baseBones;

		public Transform[] hairBones;

		public Mesh ourMesh;

		public DynamicBone dynamicBone;

		private bool applied;

		private void OnEnable()
		{
			Sync();
		}

		private void LateUpdate()
		{
			Sync();
		}

		private void Sync()
		{
			if (!Object.op_Implicit((Object)(object)smr))
			{
				return;
			}
			bool flag = Object.op_Implicit((Object)(object)ourMesh) && (Object)(object)smr.sharedMesh == (Object)(object)ourMesh;
			if (flag != applied)
			{
				smr.bones = (flag ? baseBones.Concat(hairBones).ToArray() : baseBones);
				if (Object.op_Implicit((Object)(object)dynamicBone))
				{
					((Behaviour)dynamicBone).enabled = flag;
				}
				applied = flag;
			}
		}
	}
}