Decompiled source of Soroborean Rich Set v1.0.0

plugins/SoroborRichAttire.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using SideLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SoroborRichAttire;

[BepInPlugin("johbenji.soroborrichattire", "Sorobor Rich Attire", "1.0.0")]
public class SoroborRichAttirePlugin : BaseUnityPlugin
{
	public const string GUID = "johbenji.soroborrichattire";

	public const string NAME = "Sorobor Rich Attire";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	internal void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		SL.OnPacksLoaded += SL_OnPacksLoaded;
	}

	internal void SL_OnPacksLoaded()
	{
		Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(-78001);
		Transform itemVisual = itemPrefab.GetItemVisual(itemPrefab.HasSpecialVisualPrefab);
		if (Object.op_Implicit((Object)(object)itemVisual))
		{
			GameObject gameObject = ((Component)itemVisual).gameObject;
			if (Object.op_Implicit((Object)(object)gameObject))
			{
				DestroyObject(FindChild(gameObject, "3300113_SoroboreanRichHatA_e_vLOD"));
				DestroyLODComponent(gameObject);
			}
			else
			{
				Log.LogError((object)"Failed to find Sorobor Rich Attire Boots object.");
			}
		}
		Item itemPrefab2 = ResourcesPrefabManager.Instance.GetItemPrefab(-78003);
		Transform itemVisual2 = itemPrefab2.GetItemVisual(itemPrefab2.HasSpecialVisualPrefab);
		if (!Object.op_Implicit((Object)(object)itemVisual2))
		{
			return;
		}
		GameObject gameObject2 = ((Component)itemVisual2).gameObject;
		if (Object.op_Implicit((Object)(object)gameObject2))
		{
			DestroyObject(FindChild(gameObject2, "3300221_SoroboreanRichBootsA_e_v_LOD"));
			DestroyLODComponent(gameObject2);
			Item itemPrefab3 = ResourcesPrefabManager.Instance.GetItemPrefab(-78002);
			Transform itemVisual3 = itemPrefab3.GetItemVisual(itemPrefab3.HasSpecialVisualPrefab);
			if (!Object.op_Implicit((Object)(object)itemVisual3))
			{
				return;
			}
			GameObject gameObject3 = ((Component)itemVisual3).gameObject;
			if (Object.op_Implicit((Object)(object)gameObject3))
			{
				SkinnedMeshRenderer component = gameObject2.GetComponent<SkinnedMeshRenderer>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					return;
				}
				Material material = ((Renderer)component).material;
				if (Object.op_Implicit((Object)(object)material))
				{
					SkinnedMeshRenderer component2 = gameObject3.GetComponent<SkinnedMeshRenderer>();
					if (Object.op_Implicit((Object)(object)component2))
					{
						((Renderer)component2).material = material;
						Log.LogMessage((object)"Successfully assigned Sorobor Rich Attire Boots material to attire.");
					}
					else
					{
						Log.LogError((object)"Failed to find SkinnedMeshRenderer on Sorobor Rich Attire.");
					}
				}
				else
				{
					Log.LogError((object)"Failed to find material on Sorobor Rich Attire Boots.");
				}
			}
			else
			{
				Log.LogError((object)"Failed to find Sorobor Rich Attire Boots object.");
			}
		}
		else
		{
			Log.LogError((object)"Failed to find Sorobor Rich Attire Boots object.");
		}
	}

	private GameObject FindChild(GameObject parentObject, string childName)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		foreach (Transform item in parentObject.transform)
		{
			Transform val = item;
			if (((Object)val).name == childName)
			{
				return ((Component)val).gameObject;
			}
		}
		return null;
	}

	private void PrintChildNames(GameObject parentObject)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		Log.LogMessage((object)("Parent Name: " + ((Object)parentObject).name + ":"));
		if ((Object)(object)parentObject == (Object)null)
		{
			Log.LogError((object)"Parent object is null.");
			return;
		}
		foreach (Transform item in parentObject.transform)
		{
			Transform val = item;
			Log.LogMessage((object)("Child Name: " + ((Object)val).name));
		}
		if (parentObject.transform.childCount == 0)
		{
			Log.LogMessage((object)"No children found.");
		}
	}

	private void DestroyObject(GameObject obj)
	{
		if ((Object)(object)obj != (Object)null)
		{
			string name = ((Object)obj).name;
			Object.Destroy((Object)(object)obj);
		}
		else
		{
			Log.LogError((object)"Attempted to destroy a null GameObject.");
		}
	}

	private void DestroyLODComponent(GameObject obj)
	{
		if ((Object)(object)obj != (Object)null)
		{
			LODGroup component = obj.GetComponent<LODGroup>();
			if ((Object)(object)component != (Object)null)
			{
				string name = ((Object)obj).name;
				Object.Destroy((Object)(object)component);
			}
			else
			{
				Log.LogError((object)"No LODGroup component found on the GameObject.");
			}
		}
		else
		{
			Log.LogError((object)"Attempted to destroy a null GameObject.");
		}
	}
}