Decompiled source of Nightwing Selectable Suit v0.1.5

BepInEx/plugins/KMHNZXT-Nightwing/KMHNZXT.Nightwing.dll

Decompiled 3 days ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using ModelReplacement;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.1.4.0")]
namespace KMHNZXT.Nightwing;

[BepInPlugin("kmhnzxt.nightwing.suit", "Nightwing Selectable Suit", "0.1.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	internal static AssetBundle Bundle;

	internal static Texture Albedo;

	private void Awake()
	{
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "kmhnzxt_nightwing");
		Bundle = AssetBundle.LoadFromFile(text);
		if ((Object)(object)Bundle == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Nightwing asset bundle could not be loaded: " + text));
			return;
		}
		if ((Object)(object)Bundle.LoadAsset<GameObject>("Nightwing") == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Nightwing prefab missing from bundle");
			return;
		}
		Albedo = ((Renderer)Bundle.LoadAsset<GameObject>("Nightwing").GetComponentInChildren<SkinnedMeshRenderer>()).sharedMaterial.GetTexture("_BaseColorMap");
		if ((Object)(object)Albedo == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Nightwing albedo texture is missing");
			return;
		}
		ModelReplacementAPI.RegisterSuitModelReplacement("Nightwing", typeof(NightwingReplacement));
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Nightwing selectable suit registered.");
	}
}
public class NightwingReplacement : BodyReplacementBase
{
	protected override GameObject LoadAssetsAndReturnModel()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Plugin.Bundle.LoadAsset<GameObject>("Nightwing");
		Material sharedMaterial = ((Renderer)((BodyReplacementBase)this).controller.thisPlayerModel).sharedMaterial;
		Shader val2 = Shader.Find("HDRP/Lit");
		Material val3 = new Material(((Object)(object)val2 != (Object)null && val2.isSupported) ? val2 : sharedMaterial.shader);
		((Object)val3).name = "Nightwing_GameShader";
		val3.SetFloat("_SurfaceType", 0f);
		val3.SetFloat("_DoubleSidedEnable", 1f);
		val3.SetTexture("_BaseColorMap", Plugin.Albedo);
		val3.SetColor("_BaseColor", Color.white);
		val3.mainTexture = Plugin.Albedo;
		val3.mainTextureScale = Vector2.one;
		val3.mainTextureOffset = Vector2.zero;
		if (val3.HasProperty("_MaskMap"))
		{
			val3.SetTexture("_MaskMap", (Texture)null);
		}
		if (val3.HasProperty("_NormalMap"))
		{
			val3.SetTexture("_NormalMap", (Texture)null);
		}
		if (val3.HasProperty("_NormalScale"))
		{
			val3.SetFloat("_NormalScale", 0f);
		}
		if (val3.HasProperty("_Metallic"))
		{
			val3.SetFloat("_Metallic", 0f);
		}
		if (val3.HasProperty("_Smoothness"))
		{
			val3.SetFloat("_Smoothness", 0.35f);
		}
		if (val3.HasProperty("_EmissiveColor"))
		{
			val3.SetColor("_EmissiveColor", Color.black);
		}
		HDMaterial.ValidateMaterial(val3);
		Debug.Log((object)("Nightwing 0.1.4 shader=" + ((Object)val3.shader).name + " albedo=" + ((Object)Plugin.Albedo).name + " texture=" + (object)val3.GetTexture("_BaseColorMap")));
		SkinnedMeshRenderer[] componentsInChildren = val.GetComponentsInChildren<SkinnedMeshRenderer>();
		foreach (SkinnedMeshRenderer val4 in componentsInChildren)
		{
			((Renderer)val4).sharedMaterial = val3;
		}
		return val;
	}
}