Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of VantaHuntress v1.0.0
VantaHuntress.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using MonoMod.RuntimeDetour.HookGen; using RoR2; using RoR2.ContentManagement; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace VantaHuntress; public static class Helpers { private static GameObject prefabHolder; public static GameObject ClonePrefab(GameObject gameObject) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)prefabHolder)) { prefabHolder = new GameObject("PrefabHolder"); Object.DontDestroyOnLoad((Object)(object)prefabHolder); prefabHolder.SetActive(false); } GameObject obj = Object.Instantiate<GameObject>(gameObject, prefabHolder.transform); obj.AddComponent<RemoveClone>(); ((Object)obj).name = ((Object)gameObject).name; return obj; } public static Transform GetChild(this Transform transform, int index, out Transform child) { return child = transform.GetChild(index); } public static GameObject WithComponent<T>(this GameObject gameObject, Action<T> modifier = null) where T : Component { T obj = gameObject.AddComponent<T>(); modifier?.Invoke(obj); return gameObject; } public static GameObject WithTryComponent<T>(this GameObject gameObject, Action<T> modifier = null) where T : Component { if (Object.op_Implicit((Object)(object)gameObject) && !Object.op_Implicit((Object)(object)gameObject.GetComponent<T>())) { T obj = gameObject.AddComponent<T>(); modifier?.Invoke(obj); } return gameObject; } public static T ThrowIfEquals<T>(int index, string message, T value, T expected) where T : Enum { if (value.Equals(expected)) { throw new ElementException(index, message); } return value; } public static T ThrowIfOutOfBounds<T>(int index, string message, T[] array, int elementIndex) where T : class { if (array == null || array.Length <= elementIndex) { throw new ElementException(index, message); } return array[elementIndex]; } public static T ThrowIfNull<T>(int index, string message, T value) where T : class { if (value == null) { throw new ElementException(index, message); } return value; } public static void TryCatchThrow(string message, Action action) { try { action?.Invoke(); } catch (Exception innerException) { throw new FieldException(message, innerException); } } } public class RemoveClone : MonoBehaviour { public void Awake() { ((Object)this).name = ((Object)this).name[..^7]; } } public class FieldException : Exception { public FieldException(string message, Exception innerException) : base(message, innerException) { } } public class ElementException : Exception { public int Index { get; } public ElementException(int index, string message) : base(message) { Index = index; } } public class InsertBones : MonoBehaviour { private readonly List<SkinnedMeshRenderer> modifiedRenderers = new List<SkinnedMeshRenderer>(); public List<string> rendererPaths = new List<string>(); public List<Transform> newBones = new List<Transform>(); public string afterPath; public void Awake() { Transform transform = ((Component)((Component)this).GetComponentInParent<ModelSkinController>()).transform; Transform value = ((Component)transform).transform.Find(afterPath); foreach (string rendererPath in rendererPaths) { Transform obj = transform.Find(rendererPath); SkinnedMeshRenderer val = ((obj != null) ? ((Component)obj).GetComponent<SkinnedMeshRenderer>() : null); if (Object.op_Implicit((Object)(object)val)) { Transform[] array = val.bones; int num = Array.IndexOf(array, value) + 1; if (num != 0) { Array.Resize(ref array, array.Length + newBones.Count); Array.Copy(array, num, array, num + newBones.Count, array.Length - newBones.Count - num); newBones.CopyTo(array, num); val.bones = array; modifiedRenderers.Add(val); } } } } public void OnDestroy() { foreach (SkinnedMeshRenderer modifiedRenderer in modifiedRenderers) { if (Object.op_Implicit((Object)(object)modifiedRenderer)) { Transform[] array = modifiedRenderer.bones; int num = Array.IndexOf(array, ((Component)this).transform); Array.Copy(array, num + newBones.Count, array, num, array.Length - num - newBones.Count); Array.Resize(ref array, array.Length - newBones.Count); modifiedRenderer.bones = array; } } modifiedRenderers.Clear(); } } public class AddDynamicColliders : MonoBehaviour { public List<string> paths = new List<string>(); public void Awake() { Transform transform = ((Component)((Component)this).GetComponentInParent<ModelSkinController>()).transform; List<DynamicBoneCollider> list = new List<DynamicBoneCollider>(); foreach (string path in paths) { Transform val = transform.Find(path); if (Object.op_Implicit((Object)(object)val)) { list.AddRange(((Component)val).GetComponents<DynamicBoneCollider>()); } } DynamicBone[] components = ((Component)this).GetComponents<DynamicBone>(); for (int i = 0; i < components.Length; i++) { components[i].m_Colliders.AddRange(list); } } } [BepInPlugin("com.Miyowi.VantaHuntress", "VantaHuntress", "1.0.0")] public class VantaHuntressPlugin : BaseUnityPlugin { private static AssetBundle assetBundle; private static readonly List<Material> materialsWithRoRShader = new List<Material>(); internal static VantaHuntressPlugin Instance { get; private set; } internal static ManualLogSource InstanceLogger { get { VantaHuntressPlugin instance = Instance; if (instance == null) { return null; } return ((BaseUnityPlugin)instance).Logger; } } private void Start() { Instance = this; using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("VantaHuntress.miyowivantahuntress")) { assetBundle = AssetBundle.LoadFromStream(stream); } ((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)BodyCatalogInit); HookEndpointManager.Add((MethodBase)typeof(Language).GetMethod("LoadStrings"), (Delegate)new Action<Action<Language>, Language>(LanguageLoadStrings)); ReplaceShaders(); } private static void ReplaceShaders() { LoadMaterialsWithReplacedShader("RoR2/Base/Shaders/HGStandard.shader", "Assets/SkinAssets/VantaHuntress/matVantaHuntress.mat", "Assets/SkinAssets/VantaHuntress/matVantaHuntressCape.mat", "Assets/SkinAssets/VantaHuntress/matVantaHuntressBow.mat"); LoadMaterialsWithReplacedShader("RoR2/Base/Shaders/HGCloudRemap.shader", "Assets/SkinAssets/VantaHuntress/matVantaHuntressBowString.mat", "Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat", "Assets/SkinAssets/VantaHuntress/matVantaHuntressCharged.mat"); } private static void LoadMaterialsWithReplacedShader(string shaderPath, params string[] materialPaths) { //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) Shader shader = Addressables.LoadAssetAsync<Shader>((object)shaderPath).WaitForCompletion(); foreach (string text in materialPaths) { Material val = assetBundle.LoadAsset<Material>(text); val.shader = shader; materialsWithRoRShader.Add(val); } } private static void LanguageLoadStrings(Action<Language> orig, Language self) { orig(self); self.SetStringByToken("MIYOWI_SKIN_DEFVANTAHUNTRESS_NAME", "Vanta"); } private static void BodyCatalogInit() { AddHuntressBodyDefVantaHuntressSkin(); } private static SkinDef CreateHuntressBodyDefVantaHuntressSkin(GameObject mdl, ModelSkinController skinController) { Renderer[] renderers = mdl.GetComponentsInChildren<Renderer>(true); mdl.GetComponentsInChildren<Light>(true); SkinDef skin = ScriptableObject.CreateInstance<SkinDef>(); SkinDefParams skinParams = ScriptableObject.CreateInstance<SkinDefParams>(); skin.skinDefParams = skinParams; ((Object)skin).name = "DefVantaHuntress"; skin.nameToken = "MIYOWI_SKIN_DEFVANTAHUNTRESS_NAME"; skin.rootObject = mdl; Helpers.TryCatchThrow("Icon", delegate { skin.icon = assetBundle.LoadAsset<Sprite>("Assets\\SkinMods\\VantaHuntress\\Icons\\DefVantaHuntressIcon.png"); }); Helpers.TryCatchThrow("Unlockable Name", delegate { skin.unlockableDef = null; }); Helpers.TryCatchThrow("Base Skins", delegate { skin.baseSkins = (SkinDef[])(object)new SkinDef[1] { Helpers.ThrowIfOutOfBounds(0, "Index 1 is out of bounds of skins array", skinController.skins, 1) }; }); Helpers.TryCatchThrow("Game Object Activations", delegate { skinParams.gameObjectActivations = Array.Empty<GameObjectActivation>(); }); Helpers.TryCatchThrow("Renderer Infos", delegate { //IL_0011: 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_0089: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_018d: 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_0197: 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_020f: 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_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0291: 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) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_0313: 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_031d: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0395: Unknown result type (might be due to invalid IL or missing references) //IL_0396: 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_03be: Unknown result type (might be due to invalid IL or missing references) //IL_0417: 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_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0440: Unknown result type (might be due to invalid IL or missing references) //IL_0499: Unknown result type (might be due to invalid IL or missing references) //IL_049a: Unknown result type (might be due to invalid IL or missing references) //IL_04a4: Unknown result type (might be due to invalid IL or missing references) //IL_04c3: Unknown result type (might be due to invalid IL or missing references) //IL_051d: Unknown result type (might be due to invalid IL or missing references) //IL_051e: Unknown result type (might be due to invalid IL or missing references) //IL_0528: Unknown result type (might be due to invalid IL or missing references) //IL_0547: Unknown result type (might be due to invalid IL or missing references) //IL_05a1: Unknown result type (might be due to invalid IL or missing references) //IL_05a2: Unknown result type (might be due to invalid IL or missing references) //IL_05ac: Unknown result type (might be due to invalid IL or missing references) //IL_05cb: Unknown result type (might be due to invalid IL or missing references) //IL_0625: 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) skinParams.rendererInfos = (RendererInfo[])(object)new RendererInfo[12] { new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntress.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = false, renderer = Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"HuntressMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "HuntressMesh"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressCape.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = false, renderer = Helpers.ThrowIfNull<Renderer>(1, "There is no renderer with the name \"HuntressScarfMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "HuntressScarfMesh"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressBow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = false, renderer = Helpers.ThrowIfNull<Renderer>(2, "There is no renderer with the name \"BowMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "BowMesh"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressBowString.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(3, "There is no renderer with the name \"BowString\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "BowString"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(4, "There is no renderer with the name \"Quad 1\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Quad 1"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(5, "There is no renderer with the name \"Quad 2\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Quad 2"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(6, "There is no renderer with the name \"Quad Cluster 1\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Quad Cluster 1"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(7, "There is no renderer with the name \"Quad Cluster 2\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Quad Cluster 2"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(8, "There is no renderer with the name \"Quad Cluster 3\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Quad Cluster 3"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(9, "There is no renderer with the name \"Quad Cluster 4\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Quad Cluster 4"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressArrow.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(10, "There is no renderer with the name \"Quad Cluster 5\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Quad Cluster 5"))), hideOnDeath = false, ignoresMaterialOverrides = false }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/SkinAssets/VantaHuntress/matVantaHuntressCharged.mat"), defaultShadowCastingMode = (ShadowCastingMode)0, ignoreOverlays = true, renderer = Helpers.ThrowIfNull<Renderer>(11, "There is no renderer with the name \"Flash\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Flash"))), hideOnDeath = false, ignoresMaterialOverrides = false } }; }); Helpers.TryCatchThrow("MeshReplacements", delegate { skinParams.meshReplacements = Array.Empty<MeshReplacement>(); }); Helpers.TryCatchThrow("Light Infos", delegate { skinParams.lightReplacements = Array.Empty<LightInfo>(); }); Helpers.TryCatchThrow("Minion Skin Replacements", delegate { skinParams.minionSkinReplacements = Array.Empty<MinionSkinReplacement>(); }); Helpers.TryCatchThrow("Projectile Ghost Replacements", delegate { skinParams.projectileGhostReplacements = Array.Empty<ProjectileGhostReplacement>(); }); return skin; } private static void AddHuntressBodyDefVantaHuntressSkin() { string text = "HuntressBody"; string text2 = "DefVantaHuntress"; GameObject bodyPrefab = BodyCatalog.FindBodyPrefab(text); if (!Object.op_Implicit((Object)(object)bodyPrefab)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin because \"" + text + "\" doesn't exist")); return; } try { ModelLocator component = bodyPrefab.GetComponent<ModelLocator>(); if (!Object.op_Implicit((Object)(object)component)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelLocator\" component")); return; } GameObject gameObject = ((Component)component.modelTransform).gameObject; ModelSkinController val = (Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<ModelSkinController>() : null); if (!Object.op_Implicit((Object)(object)val)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelSkinController\" component")); return; } SkinDef val2 = CreateHuntressBodyDefVantaHuntressSkin(gameObject, val); Array.Resize(ref val.skins, val.skins.Length + 1); val.skins[val.skins.Length - 1] = val2; } catch (FieldException ex) { if (ex.InnerException is ElementException ex2) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)$"Field causing issue: {ex.Message}, element: {ex2.Index}"); InstanceLogger.LogWarning((object)ex2.Message); InstanceLogger.LogError((object)ex.InnerException); } else { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)("Field causing issue: " + ex.Message)); InstanceLogger.LogError((object)ex.InnerException); } } catch (Exception ex3) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogError((object)ex3); } try { SurvivorDef val3 = ((IEnumerable<SurvivorDef>)ContentManager.survivorDefs).FirstOrDefault((Func<SurvivorDef, bool>)((SurvivorDef d) => (Object)(object)d.bodyPrefab == (Object)(object)bodyPrefab)); if (!Object.op_Implicit((Object)(object)val3)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\" because SurvivorDef doesn't exist")); return; } ModelSkinController componentInChildren = val3.displayPrefab.GetComponentInChildren<ModelSkinController>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\" because it doesn't have \"ModelSkinController\" component")); } else { SkinDef val4 = CreateHuntressBodyDefVantaHuntressSkin(((Component)componentInChildren).gameObject, componentInChildren); Array.Resize(ref componentInChildren.skins, componentInChildren.skins.Length + 1); componentInChildren.skins[^1] = val4; } } catch (FieldException ex4) { if (ex4.InnerException is ElementException ex5) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)$"Field causing issue: {ex4.Message}, element: {ex5.Index}"); InstanceLogger.LogWarning((object)ex5.Message); InstanceLogger.LogError((object)ex4.InnerException); } else { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)("Field causing issue: " + ex4.Message)); InstanceLogger.LogError((object)ex4.InnerException); } } catch (Exception ex6) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\"")); InstanceLogger.LogError((object)ex6); } } }