Decompiled source of Kasane Teto Railgunner v1.0.0

TetoRailgunner.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.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 TetoRailgunner
{
	internal static class Assets
	{
		private static Stream Open(string name)
		{
			return typeof(Assets).Assembly.GetManifestResourceStream(name) ?? throw new FileNotFoundException("Embedded resource missing: " + name);
		}

		public static Dictionary<string, Matrix4x4> ReadBindposes(string name)
		{
			//IL_0027: 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)
			using BinaryReader binaryReader = new BinaryReader(Open(name));
			Dictionary<string, Matrix4x4> dictionary = new Dictionary<string, Matrix4x4>();
			int num = binaryReader.ReadInt32();
			for (int i = 0; i < num; i++)
			{
				string key = ReadString(binaryReader);
				Matrix4x4 value = default(Matrix4x4);
				for (int j = 0; j < 16; j++)
				{
					((Matrix4x4)(ref value))[j / 4, j % 4] = binaryReader.ReadSingle();
				}
				dictionary[key] = value;
			}
			return dictionary;
		}

		public static Mesh ReadSkinnedMesh(string name, SkinnedMeshRenderer target, Dictionary<string, Matrix4x4> bindposes)
		{
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Expected O, but got Unknown
			using BinaryReader binaryReader = new BinaryReader(Open(name));
			if (new string(binaryReader.ReadChars(4)) != "HKM1")
			{
				throw new InvalidDataException(name);
			}
			int num = binaryReader.ReadInt32();
			string[] array = new string[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = ReadString(binaryReader);
			}
			Transform[] bones = target.bones;
			Dictionary<string, int> byName = new Dictionary<string, int>();
			for (int j = 0; j < bones.Length; j++)
			{
				if (Object.op_Implicit((Object)(object)bones[j]) && !byName.ContainsKey(((Object)bones[j]).name))
				{
					byName[((Object)bones[j]).name] = j;
				}
			}
			Matrix4x4 value;
			int[] array2 = array.Select(delegate(string b)
			{
				if (!byName.TryGetValue(b, out value))
				{
					throw new Exception(name + ": bone " + b + " not on " + ((Object)target).name);
				}
				return value;
			}).ToArray();
			int num2 = binaryReader.ReadInt32();
			Vector3[] array3 = (Vector3[])(object)new Vector3[num2];
			Vector3[] array4 = (Vector3[])(object)new Vector3[num2];
			Vector2[] array5 = (Vector2[])(object)new Vector2[num2];
			for (int num3 = 0; num3 < num2; num3++)
			{
				array3[num3] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int num4 = 0; num4 < num2; num4++)
			{
				array4[num4] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int num5 = 0; num5 < num2; num5++)
			{
				array5[num5] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			int[] array6 = new int[num2 * 4];
			for (int num6 = 0; num6 < array6.Length; num6++)
			{
				array6[num6] = array2[binaryReader.ReadInt32()];
			}
			BoneWeight[] array7 = (BoneWeight[])(object)new BoneWeight[num2];
			for (int num7 = 0; num7 < num2; num7++)
			{
				float weight = binaryReader.ReadSingle();
				float weight2 = binaryReader.ReadSingle();
				float weight3 = binaryReader.ReadSingle();
				float weight4 = binaryReader.ReadSingle();
				int num8 = num7;
				BoneWeight val = default(BoneWeight);
				((BoneWeight)(ref val)).boneIndex0 = array6[num7 * 4];
				((BoneWeight)(ref val)).boneIndex1 = array6[num7 * 4 + 1];
				((BoneWeight)(ref val)).boneIndex2 = array6[num7 * 4 + 2];
				((BoneWeight)(ref val)).boneIndex3 = array6[num7 * 4 + 3];
				((BoneWeight)(ref val)).weight0 = weight;
				((BoneWeight)(ref val)).weight1 = weight2;
				((BoneWeight)(ref val)).weight2 = weight3;
				((BoneWeight)(ref val)).weight3 = weight4;
				array7[num8] = val;
			}
			int num9 = binaryReader.ReadInt32();
			int[] array8 = new int[num9];
			for (int num10 = 0; num10 < num9; num10++)
			{
				array8[num10] = binaryReader.ReadInt32();
			}
			Mesh val2 = new Mesh
			{
				name = Path.GetFileNameWithoutExtension(name)
			};
			if (num2 > 65535)
			{
				val2.indexFormat = (IndexFormat)1;
			}
			val2.vertices = array3;
			val2.normals = array4;
			val2.uv = array5;
			val2.SetIndices(array8, (MeshTopology)0, 0);
			val2.boneWeights = array7;
			val2.bindposes = bones.Select((Transform b) => (!Object.op_Implicit((Object)(object)b) || !bindposes.TryGetValue(((Object)b).name, out value)) ? Matrix4x4.identity : value).ToArray();
			val2.RecalculateTangents();
			val2.RecalculateBounds();
			return val2;
		}

		public static Texture2D ReadTexture(string name, bool alpha)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			using Stream stream = Open(name);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)(alpha ? 4 : 3), true)
			{
				name = Path.GetFileNameWithoutExtension(name)
			};
			ImageConversion.LoadImage(val, memoryStream.ToArray());
			val.Compress(true);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 4;
			val.Apply(false, true);
			return val;
		}

		public static Material MakeMaterial(Material template, string name, Texture2D tex, bool cutout, float specular, float exponent)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(template)
			{
				name = name
			};
			val.SetTexture("_MainTex", (Texture)(object)tex);
			val.SetColor("_Color", Color.white);
			val.SetTexture("_NormalTex", (Texture)null);
			val.SetFloat("_NormalStrength", 0f);
			val.SetColor("_EmColor", Color.black);
			val.SetTexture("_EmTex", (Texture)null);
			val.SetFloat("_EmPower", 0f);
			val.SetFloat("_SpecularStrength", specular);
			val.SetFloat("_SpecularExponent", exponent);
			val.SetFloat("_FEON", 0f);
			val.DisableKeyword("FRESNEL_EMISSION");
			val.SetFloat("_LimbRemovalOn", 0f);
			val.DisableKeyword("LIMBREMOVAL");
			val.SetFloat("_EnableCutout", cutout ? 1f : 0f);
			if (cutout)
			{
				val.EnableKeyword("CUTOUT");
			}
			else
			{
				val.DisableKeyword("CUTOUT");
			}
			return val;
		}

		private static string ReadString(BinaryReader r)
		{
			return Encoding.UTF8.GetString(r.ReadBytes(r.ReadInt32()));
		}
	}
	[DefaultExecutionOrder(10000)]
	public class TetoController : MonoBehaviour
	{
		internal static SkinDef skin;

		private ModelSkinController skins;

		private CharacterModel model;

		private Renderer[] lightRenderers = (Renderer[])(object)new Renderer[0];

		private Light[] lights = (Light[])(object)new Light[0];

		private bool lightsHidden;

		private void Awake()
		{
			skins = ((Component)this).GetComponent<ModelSkinController>();
			model = ((Component)this).GetComponent<CharacterModel>();
			List<Renderer> list = new List<Renderer>();
			List<Light> list2 = new List<Light>();
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (!(((Object)val).name != "backpack"))
				{
					list.AddRange(((Component)val).GetComponentsInChildren<Renderer>(true));
					list2.AddRange(((Component)val).GetComponentsInChildren<Light>(true));
				}
			}
			lightRenderers = list.ToArray();
			lights = list2.ToArray();
		}

		private void SetLights(bool on)
		{
			Renderer[] array = lightRenderers;
			foreach (Renderer val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					val.enabled = on;
				}
			}
			Light[] array2 = lights;
			foreach (Light val2 in array2)
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					((Behaviour)val2).enabled = on;
				}
			}
			lightsHidden = !on;
		}

		private bool SkinActive()
		{
			if (!Object.op_Implicit((Object)(object)skins) || !Object.op_Implicit((Object)(object)skin) || skins.skins == null)
			{
				return false;
			}
			int currentSkinIndex = skins.currentSkinIndex;
			if (currentSkinIndex >= 0 && currentSkinIndex < skins.skins.Length)
			{
				return (Object)(object)skins.skins[currentSkinIndex] == (Object)(object)skin;
			}
			if (Object.op_Implicit((Object)(object)model) && model.baseRendererInfos != null)
			{
				return Array.Exists(model.baseRendererInfos, delegate(RendererInfo r)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					Renderer renderer = r.renderer;
					SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null);
					return val != null && Object.op_Implicit((Object)(object)val.sharedMesh) && ((Object)val.sharedMesh).name == "teto_body";
				});
			}
			return false;
		}

		private void LateUpdate()
		{
			if (SkinActive())
			{
				SetLights(on: false);
			}
			else if (lightsHidden)
			{
				SetLights(on: true);
			}
		}
	}
	[BepInPlugin("com.chaz.tetorailgunner", "TetoRailgunner", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TetoRailgunnerPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.chaz.tetorailgunner";

		public const string PluginName = "TetoRailgunner";

		public const string PluginVersion = "1.0.0";

		private const string SkinNameToken = "CHAZ_TETORAILGUNNER_SKIN_NAME";

		private const string Backpack = "RailGunnerArmature/ROOT/base/stomach/backpack";

		internal static ManualLogSource Log;

		public static SkinDef Skin { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				LanguageAPI.Add("CHAZ_TETORAILGUNNER_SKIN_NAME", "Kasane Teto");
				AddSkin();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to add Teto skin: " + ex));
			}
		}

		private void AddSkin()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_0106: 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_0118: Expected O, but got Unknown
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: 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)
			GameObject body = Load<GameObject>("RoR2/DLC1/Railgunner/RailgunnerBody.prefab");
			GameObject model = ((Component)body.GetComponent<ModelLocator>().modelTransform).gameObject;
			SkinDef val = model.GetComponent<ModelSkinController>().skins[0];
			SkinDefParams val2 = (Object.op_Implicit((Object)(object)val.skinDefParams) ? val.skinDefParams : LoadRef<SkinDefParams>(val.skinDefParamsAddress));
			if (!Object.op_Implicit((Object)(object)val2))
			{
				throw new Exception("Railgunner default skin params not found");
			}
			SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)FindRenderer(model, "mdlRailGunnerBase");
			SkinnedMeshRenderer val4 = (SkinnedMeshRenderer)FindRenderer(model, "mdlRailGunnerMetal");
			Renderer val5 = FindRenderer(model, "mdlRailgunBackpackMesh");
			Renderer val6 = FindRenderer(model, "mdlRailGunBackpackScreen");
			Renderer val7 = FindRenderer(model, "RailGunnerArmature/ROOT/base/stomach/backpack/AllBackpackVFX Root/Idle/Monitor, Charging");
			Dictionary<string, Matrix4x4> bindposes = Assets.ReadBindposes("bindposes.bin");
			Mesh value = Assets.ReadSkinnedMesh("teto_body.hkm", val3, bindposes);
			Mesh value2 = Assets.ReadSkinnedMesh("teto_hair.hkm", val4, bindposes);
			Mesh value3 = new Mesh
			{
				name = "tetoEmpty"
			};
			Material template = MaterialOf(val2, (Renderer)(object)val3);
			Material value4 = Assets.MakeMaterial(template, "matTetoBody", Assets.ReadTexture("teto_body.png", alpha: false), cutout: false, 0.06f, 10f);
			Material value5 = Assets.MakeMaterial(template, "matTetoHair", Assets.ReadTexture("teto_hair.png", alpha: true), cutout: true, 0.06f, 10f);
			Dictionary<Renderer, Material> materials = new Dictionary<Renderer, Material>
			{
				[(Renderer)(object)val3] = value4,
				[(Renderer)(object)val4] = value5
			};
			Dictionary<Renderer, Mesh> meshes = new Dictionary<Renderer, Mesh>
			{
				[(Renderer)(object)val3] = value,
				[(Renderer)(object)val4] = value2,
				[val5] = value3,
				[val6] = value3,
				[val7] = value3
			};
			RendererInfo[] rendererInfos = val2.rendererInfos.Select(delegate(RendererInfo ri)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				ri.renderer = Resolve(model, ri.renderer);
				if (Object.op_Implicit((Object)(object)ri.renderer) && materials.TryGetValue(ri.renderer, out var value6))
				{
					ri.defaultMaterial = value6;
					ri.defaultMaterialAddress = null;
				}
				return ri;
			}).ToArray();
			List<MeshReplacement> list = val2.meshReplacements.Select(delegate(MeshReplacement mr)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				mr.renderer = Resolve(model, mr.renderer);
				if (Object.op_Implicit((Object)(object)mr.renderer) && meshes.TryGetValue(mr.renderer, out var value6))
				{
					mr.mesh = value6;
					mr.meshAddress = null;
				}
				return mr;
			}).ToList();
			foreach (KeyValuePair<Renderer, Mesh> kv in meshes)
			{
				if (!list.Any((MeshReplacement mr) => (Object)(object)mr.renderer == (Object)(object)kv.Key))
				{
					list.Add(new MeshReplacement
					{
						renderer = kv.Key,
						mesh = kv.Value
					});
				}
			}
			List<GameObjectActivation> list2 = val2.gameObjectActivations.Select(delegate(GameObjectActivation ga)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				ga.gameObject = ResolveObject(model, ga.gameObject);
				return ga;
			}).ToList();
			string[] array = new string[3] { "RailGunnerArmature/ROOT/base/stomach/backpack/AllBackpackVFX Root", "RailGunnerArmature/ROOT/base/stomach/backpack/StatusLED, Backpack", "RailGunnerArmature/ROOT/base/stomach/backpack/PowerLED, Barrel" };
			foreach (string text in array)
			{
				Transform val8 = model.transform.Find(text);
				if (Object.op_Implicit((Object)(object)val8))
				{
					list2.Add(new GameObjectActivation
					{
						gameObject = ((Component)val8).gameObject,
						shouldActivate = false
					});
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Not found: " + text));
				}
			}
			Skin = Skins.CreateNewSkinDef(new SkinDefParamsInfo
			{
				Name = "skinRailGunnerTeto",
				NameToken = "CHAZ_TETORAILGUNNER_SKIN_NAME",
				Icon = Skins.CreateSkinIcon(Color32.op_Implicit(new Color32((byte)206, (byte)52, (byte)70, byte.MaxValue)), Color32.op_Implicit(new Color32((byte)52, (byte)84, (byte)112, byte.MaxValue)), Color32.op_Implicit(new Color32((byte)232, (byte)112, (byte)140, byte.MaxValue)), Color32.op_Implicit(new Color32((byte)32, (byte)26, (byte)32, byte.MaxValue))),
				RootObject = model,
				BaseSkins = (SkinDef[])(object)new SkinDef[1] { val },
				RendererInfos = rendererInfos,
				MeshReplacements = list.ToArray(),
				ProjectileGhostReplacements = Array.Empty<ProjectileGhostReplacement>(),
				GameObjectActivations = list2.ToArray(),
				MinionSkinReplacements = Array.Empty<MinionSkinReplacement>()
			});
			if (!Skins.AddSkinToCharacter(body, Skin))
			{
				throw new Exception("R2API refused the skin");
			}
			TetoController.skin = Skin;
			model.AddComponent<TetoController>();
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
			{
				GameObject val9 = SurvivorCatalog.FindSurvivorDefFromBody(body)?.displayPrefab;
				CharacterModel val10 = (Object.op_Implicit((Object)(object)val9) ? val9.GetComponentInChildren<CharacterModel>(true) : null);
				if (Object.op_Implicit((Object)(object)val10) && !Object.op_Implicit((Object)(object)((Component)val10).GetComponent<TetoController>()))
				{
					((Component)val10).gameObject.AddComponent<TetoController>();
				}
			});
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Added Kasane Teto skin to Railgunner");
		}

		private static Material MaterialOf(SkinDefParams p, Renderer r)
		{
			//IL_000d: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			RendererInfo[] rendererInfos = p.rendererInfos;
			foreach (RendererInfo val in rendererInfos)
			{
				if (Object.op_Implicit((Object)(object)val.renderer) && !(((Object)val.renderer).name != ((Object)r).name))
				{
					Material val2 = (Object.op_Implicit((Object)(object)val.defaultMaterial) ? val.defaultMaterial : LoadRef<Material>(val.defaultMaterialAddress));
					if (Object.op_Implicit((Object)(object)val2))
					{
						return val2;
					}
				}
			}
			Material sharedMaterial = r.sharedMaterial;
			if (Object.op_Implicit((Object)(object)sharedMaterial))
			{
				return sharedMaterial;
			}
			throw new Exception("No material for " + ((Object)r).name);
		}

		private static T Load<T>(string key) where T : Object
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			T val = Addressables.LoadAssetAsync<T>((object)key).WaitForCompletion();
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new Exception("Missing addressable " + key);
			}
			return val;
		}

		private static T LoadRef<T>(AssetReferenceT<T> r) where T : Object
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (r == null || !((AssetReference)r).RuntimeKeyIsValid())
			{
				return default(T);
			}
			return Addressables.LoadAssetAsync<T>(((AssetReference)r).RuntimeKey).WaitForCompletion();
		}

		private static Renderer FindRenderer(GameObject model, string path)
		{
			Transform val = model.transform.Find(path);
			Renderer obj = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<Renderer>() : null);
			if (!Object.op_Implicit((Object)(object)obj))
			{
				throw new Exception("Renderer not found: " + path);
			}
			return obj;
		}

		private static string PathUnderModel(Transform t, string modelName)
		{
			List<string> list = new List<string>();
			Transform val = t;
			while (Object.op_Implicit((Object)(object)val) && ((Object)val).name != modelName)
			{
				list.Add(((Object)val).name);
				val = val.parent;
			}
			list.Reverse();
			return string.Join("/", list);
		}

		private static Renderer Resolve(GameObject model, Renderer r)
		{
			if (!Object.op_Implicit((Object)(object)r))
			{
				return r;
			}
			Transform val = model.transform.Find(PathUnderModel(((Component)r).transform, ((Object)model).name));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return r;
			}
			Component component = ((Component)val).GetComponent(((object)r).GetType());
			return (Renderer)(object)((component is Renderer) ? component : null);
		}

		private static GameObject ResolveObject(GameObject model, GameObject g)
		{
			if (!Object.op_Implicit((Object)(object)g))
			{
				return g;
			}
			Transform val = model.transform.Find(PathUnderModel(g.transform, ((Object)model).name));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return g;
			}
			return ((Component)val).gameObject;
		}
	}
}