Decompiled source of DIDYOUGUYSSSEETHAT v1.0.1

DIDYOUGUYSSEETHAT.dll

Decompiled 17 hours ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
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")]
[CompilerGenerated]
[EditorBrowsable(EditorBrowsableState.Never)]
[GeneratedCode("Unity.MonoScriptGenerator.MonoScriptInfoGenerator", null)]
internal class UnitySourceGeneratedAssemblyMonoScriptTypes_v1
{
	private struct MonoScriptData
	{
		public byte[] FilePathsData;

		public byte[] TypesData;

		public int TotalTypes;

		public int TotalFiles;

		public bool IsEditorOnly;
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private static MonoScriptData Get()
	{
		return new MonoScriptData
		{
			FilePathsData = new byte[125]
			{
				0, 0, 0, 1, 0, 0, 0, 61, 92, 65,
				115, 115, 101, 116, 115, 92, 83, 107, 105, 110,
				77, 111, 100, 115, 92, 68, 73, 68, 89, 79,
				85, 71, 85, 89, 83, 83, 69, 69, 84, 72,
				65, 84, 92, 68, 73, 68, 89, 79, 85, 71,
				85, 89, 83, 83, 69, 69, 84, 72, 65, 84,
				80, 108, 117, 103, 105, 110, 46, 99, 115, 0,
				0, 0, 6, 0, 0, 0, 48, 92, 65, 115,
				115, 101, 116, 115, 92, 83, 107, 105, 110, 77,
				111, 100, 115, 92, 68, 73, 68, 89, 79, 85,
				71, 85, 89, 83, 83, 69, 69, 84, 72, 65,
				84, 92, 83, 116, 97, 116, 105, 99, 67, 111,
				100, 101, 46, 99, 115
			},
			TypesData = new byte[262]
			{
				0, 0, 0, 0, 41, 68, 73, 68, 89, 79,
				85, 71, 85, 89, 83, 83, 69, 69, 84, 72,
				65, 84, 124, 68, 73, 68, 89, 79, 85, 71,
				85, 89, 83, 83, 69, 69, 84, 72, 65, 84,
				80, 108, 117, 103, 105, 110, 0, 0, 0, 0,
				25, 68, 73, 68, 89, 79, 85, 71, 85, 89,
				83, 83, 69, 69, 84, 72, 65, 84, 124, 72,
				101, 108, 112, 101, 114, 115, 0, 0, 0, 0,
				29, 68, 73, 68, 89, 79, 85, 71, 85, 89,
				83, 83, 69, 69, 84, 72, 65, 84, 124, 82,
				101, 109, 111, 118, 101, 67, 108, 111, 110, 101,
				0, 0, 0, 0, 32, 68, 73, 68, 89, 79,
				85, 71, 85, 89, 83, 83, 69, 69, 84, 72,
				65, 84, 124, 70, 105, 101, 108, 100, 69, 120,
				99, 101, 112, 116, 105, 111, 110, 0, 0, 0,
				0, 34, 68, 73, 68, 89, 79, 85, 71, 85,
				89, 83, 83, 69, 69, 84, 72, 65, 84, 124,
				69, 108, 101, 109, 101, 110, 116, 69, 120, 99,
				101, 112, 116, 105, 111, 110, 0, 0, 0, 0,
				29, 68, 73, 68, 89, 79, 85, 71, 85, 89,
				83, 83, 69, 69, 84, 72, 65, 84, 124, 73,
				110, 115, 101, 114, 116, 66, 111, 110, 101, 115,
				0, 0, 0, 0, 37, 68, 73, 68, 89, 79,
				85, 71, 85, 89, 83, 83, 69, 69, 84, 72,
				65, 84, 124, 65, 100, 100, 68, 121, 110, 97,
				109, 105, 99, 67, 111, 108, 108, 105, 100, 101,
				114, 115
			},
			TotalFiles = 2,
			TotalTypes = 7,
			IsEditorOnly = false
		};
	}
}
namespace DIDYOUGUYSSEETHAT;

[BepInPlugin("com.Mirza16498.DIDYOUGUYSSEETHAT", "DIDYOUGUYSSEETHAT", "1.0.1")]
public class DIDYOUGUYSSEETHATPlugin : BaseUnityPlugin
{
	private static AssetBundle assetBundle;

	private static readonly List<Material> materialsWithRoRShader = new List<Material>();

	public static ConfigEntry<bool> NewSkinDefinitionEnabledConfig;

	internal static DIDYOUGUYSSEETHATPlugin Instance { get; private set; }

	internal static ManualLogSource InstanceLogger
	{
		get
		{
			DIDYOUGUYSSEETHATPlugin instance = Instance;
			if (instance == null)
			{
				return null;
			}
			return ((BaseUnityPlugin)instance).Logger;
		}
	}

	private void Start()
	{
		Instance = this;
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
		NewSkinDefinitionEnabledConfig = ((BaseUnityPlugin)Instance).Config.Bind<bool>("NewSkinDefinition", "Enabled", true, (ConfigDescription)null);
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		((BaseUnityPlugin)this).Config.Save();
		using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DIDYOUGUYSSEETHAT.mirza16498didyouguysseethat"))
		{
			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/acoleyes/acoleyesmaterial.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("MIRZA16498_SKIN_NEW_SKIN_DEFINITION_NAME", "DIDYOUGUYSSEETHAT");
	}

	private static void BodyCatalogInit()
	{
		AddAcolyteBodyNewSkinDefinitionSkin();
	}

	private static SkinDef CreateAcolyteBodyNewSkinDefinitionSkin(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 = "New Skin Definition";
		skin.nameToken = "MIRZA16498_SKIN_NEW_SKIN_DEFINITION_NAME";
		skin.rootObject = mdl;
		Helpers.TryCatchThrow("Icon", delegate
		{
			skin.icon = assetBundle.LoadAsset<Sprite>("Assets\\SkinMods\\DIDYOUGUYSSEETHAT\\Icons\\New Skin DefinitionIcon.png");
		});
		Helpers.TryCatchThrow("Unlockable Name", delegate
		{
			skin.unlockableDef = ((IEnumerable<UnlockableDef>)ContentManager.unlockableDefs).FirstOrDefault((Func<UnlockableDef, bool>)((UnlockableDef def) => def.cachedName == "DIDYOUGUYSSEETHAT"));
		});
		Helpers.TryCatchThrow("Base Skins", delegate
		{
			skin.baseSkins = (SkinDef[])(object)new SkinDef[1] { Helpers.ThrowIfOutOfBounds(0, "Index 0 is out of bounds of skins array", skinController.skins, 0) };
		});
		Helpers.TryCatchThrow("Game Object Activations", delegate
		{
			skinParams.gameObjectActivations = Array.Empty<GameObjectActivation>();
		});
		Helpers.TryCatchThrow("Renderer Infos", delegate
		{
			//IL_0010: 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_0088: 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)
			skinParams.rendererInfos = (RendererInfo[])(object)new RendererInfo[1]
			{
				new RendererInfo
				{
					defaultMaterial = assetBundle.LoadAsset<Material>("Assets/acoleyes/acoleyesmaterial.mat"),
					defaultShadowCastingMode = (ShadowCastingMode)0,
					ignoreOverlays = false,
					renderer = Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"acolyte_eyes\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "acolyte_eyes"))),
					hideOnDeath = false,
					ignoresMaterialOverrides = false
				}
			};
		});
		Helpers.TryCatchThrow("MeshReplacements", delegate
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			skinParams.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[1]
			{
				new MeshReplacement
				{
					mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\DIDYOUGUYSSEETHAT\\Meshes\\acolyte_eyes.mesh"),
					renderer = Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"acolyte_eyes\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "acolyte_eyes")))
				}
			};
		});
		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 AddAcolyteBodyNewSkinDefinitionSkin()
	{
		if (!NewSkinDefinitionEnabledConfig.Value)
		{
			return;
		}
		string text = "AcolyteBody";
		string text2 = "New Skin Definition";
		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 = CreateAcolyteBodyNewSkinDefinitionSkin(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 = CreateAcolyteBodyNewSkinDefinitionSkin(((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);
		}
	}
}
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()
	{
		string name = ((Object)this).name;
		((Object)this).name = name.Substring(0, name.Length - 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);
		}
	}
}