Decompiled source of ButteredLillys Skin Manager v3.0.0

Mods/Skins.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.MoveSystem;
using Il2CppRUMBLE.Players;
using LillysSkinManager;
using MelonLoader;
using MelonLoader.Utils;
using Skins;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(_SkinManager), "Lilly's Skins", "3.0.0", "Lilly", null)]
[assembly: AssemblyTitle("Lilly's Skins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lilly's Skins")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("CACE994B-5AD9-4AD5-91E2-D41CE114D248")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LillysSkinManager
{
	public class _SkinManager : MelonMod
	{
		[HarmonyPatch(typeof(PlayerManager), "Initialize")]
		public static class playerManInit
		{
			private static void Postfix(ref PlayerManager __instance)
			{
				lilsTexPlayerMan = __instance;
			}
		}

		public byte[] Bytes;

		public Texture2D[] texturesLocal = (Texture2D[])(object)new Texture2D[6];

		public static PlayerManager lilsTexPlayerMan;

		private Player_Texturing playerTex = new Player_Texturing();

		private Structure_Texturing strucTex = new Structure_Texturing();

		public override void OnLateInitializeMelon()
		{
			((MelonBase)this).OnLateInitializeMelon();
			playerTex.init();
			strucTex.init();
		}
	}
}
namespace Skins
{
	internal class Player_Texturing
	{
		[HarmonyPatch(typeof(PlayerController), "Initialize", new Type[] { typeof(Player) })]
		public static class playerspawn
		{
			private static void Postfix(ref PlayerController __instance, ref Player player)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Invalid comparison between Unknown and I4
				PlayerTex.updateTex(((Component)__instance).gameObject, (int)__instance.controllerType == 1);
			}
		}

		private byte[] Bytes;

		private const int texCount = 9;

		private Texture2D[] playertexturesLocal = (Texture2D[])(object)new Texture2D[9];

		private Texture2D[] playertexturesRemote = (Texture2D[])(object)new Texture2D[9];

		private string[] filetypes = new string[9];

		private string[] texProps = new string[9];

		private string[] objectPaths = new string[9];

		public static Player_Texturing PlayerTex;

		public void init()
		{
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Expected O, but got Unknown
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Expected O, but got Unknown
			PlayerTex = this;
			filetypes[0] = "Suit/Main";
			filetypes[1] = "Suit/Mat";
			filetypes[2] = "Suit/Normal";
			filetypes[3] = "Shiftsocket/Main_R";
			filetypes[4] = "Shiftsocket/Mat_R";
			filetypes[5] = "Shiftsocket/Normal_R";
			filetypes[6] = "Shiftsocket/Main_L";
			filetypes[7] = "Shiftsocket/Mat_L";
			filetypes[8] = "Shiftsocket/Normal_L";
			texProps[0] = "_Color_Map";
			texProps[1] = "_Metal_Map";
			texProps[2] = "_Normal_Map";
			texProps[3] = "_Color_Map";
			texProps[4] = "_Metal_Map";
			texProps[5] = "_Normal_Map";
			texProps[6] = "_Color_Map";
			texProps[7] = "_Metal_Map";
			texProps[8] = "_Normal_Map";
			objectPaths[0] = "Visuals/Suit";
			objectPaths[1] = "Visuals/Suit";
			objectPaths[2] = "Visuals/Suit";
			objectPaths[3] = "Visuals/RIG/Bone_Pelvis/Bone_Spine/Bone_Chest/Bone_Shoulderblade_R/Bone_Shoulder_R/Bone_Lowerarm_R/Bone_Hand_R/ShiftstoneSocket_R/Shiftsocket";
			objectPaths[4] = "Visuals/RIG/Bone_Pelvis/Bone_Spine/Bone_Chest/Bone_Shoulderblade_R/Bone_Shoulder_R/Bone_Lowerarm_R/Bone_Hand_R/ShiftstoneSocket_R/Shiftsocket";
			objectPaths[5] = "Visuals/RIG/Bone_Pelvis/Bone_Spine/Bone_Chest/Bone_Shoulderblade_R/Bone_Shoulder_R/Bone_Lowerarm_R/Bone_Hand_R/ShiftstoneSocket_R/Shiftsocket";
			objectPaths[6] = "Visuals/RIG/Bone_Pelvis/Bone_Spine/Bone_Chest/Bone_Shoulderblade_L/Bone_Shoulder_L/Bone_Lowerarm_L/Bone_Hand_L/ShiftstoneSocket_L/Shiftsocket";
			objectPaths[7] = "Visuals/RIG/Bone_Pelvis/Bone_Spine/Bone_Chest/Bone_Shoulderblade_L/Bone_Shoulder_L/Bone_Lowerarm_L/Bone_Hand_L/ShiftstoneSocket_L/Shiftsocket";
			objectPaths[8] = "Visuals/RIG/Bone_Pelvis/Bone_Spine/Bone_Chest/Bone_Shoulderblade_L/Bone_Shoulder_L/Bone_Lowerarm_L/Bone_Hand_L/ShiftstoneSocket_L/Shiftsocket";
			for (int i = 0; i < playertexturesLocal.Length; i++)
			{
				if (File.Exists(MelonEnvironment.UserDataDirectory + "/Skins/Player/" + filetypes[i] + ".png"))
				{
					playertexturesLocal[i] = new Texture2D(2, 2);
					Bytes = File.ReadAllBytes(MelonEnvironment.UserDataDirectory + "/Skins/Player/" + filetypes[i] + ".png");
					ImageConversion.LoadImage(playertexturesLocal[i], Il2CppStructArray<byte>.op_Implicit(Bytes));
					((Object)playertexturesLocal[i]).hideFlags = (HideFlags)61;
				}
				else
				{
					playertexturesLocal[i] = null;
				}
				if (File.Exists(MelonEnvironment.UserDataDirectory + "/Skins/Player/" + filetypes[i] + "_Alt.png"))
				{
					playertexturesRemote[i] = new Texture2D(2, 2);
					Bytes = File.ReadAllBytes(MelonEnvironment.UserDataDirectory + "/Skins/Player/" + filetypes[i] + "_Alt.png");
					ImageConversion.LoadImage(playertexturesRemote[i], Il2CppStructArray<byte>.op_Implicit(Bytes));
					((Object)playertexturesRemote[i]).hideFlags = (HideFlags)61;
				}
				else
				{
					playertexturesRemote[i] = playertexturesLocal[i];
					if ((Object)(object)playertexturesRemote[i] != (Object)null)
					{
						((Object)playertexturesRemote[i]).hideFlags = (HideFlags)61;
					}
				}
			}
			MelonLogger.Msg("Player Passed File loading");
		}

		public void updateTex(GameObject player, bool isLocal)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			try
			{
				MelonLogger.Msg("trying to skin player");
				Texture2D[] array = ((!isLocal) ? playertexturesRemote : playertexturesLocal);
				MaterialPropertyBlock val = new MaterialPropertyBlock();
				Renderer component = ((Component)player.transform.Find(objectPaths[0])).GetComponent<Renderer>();
				string text = objectPaths[0];
				component.GetPropertyBlock(val);
				for (int i = 0; i < array.Length; i++)
				{
					if (objectPaths[i] != text)
					{
						component.SetPropertyBlock(val);
						component = ((Component)player.transform.Find(objectPaths[i])).GetComponent<Renderer>();
						component.GetPropertyBlock(val);
					}
					if ((Object)(object)array[i] != (Object)null)
					{
						val.SetTexture(texProps[i], (Texture)(object)array[i]);
					}
					text = objectPaths[i];
				}
				component.SetPropertyBlock(val);
			}
			catch (Exception ex)
			{
				MelonLogger.Msg(ex.ToString());
			}
		}
	}
	internal class Structure_Texturing
	{
		[HarmonyPatch(typeof(Structure), "Start")]
		public static class strutuerespawn
		{
			private static void Postfix(ref Structure __instance)
			{
				bool isLocal = true;
				int num;
				GameObject gameObject;
				try
				{
					num = Array.IndexOf(types, ((Object)((Component)__instance.processableComponent).gameObject).name);
					if (num < 0 || __instance.isSceneStructure)
					{
						return;
					}
					gameObject = ((Component)((Component)__instance.processableComponent).gameObject.transform.GetChild(0)).gameObject;
				}
				catch (Exception ex)
				{
					MelonLogger.Msg((object)ex);
					return;
				}
				Struc.texture(gameObject, num, isLocal);
			}
		}

		public static string[] types = new string[5];

		private string[] texTypes = new string[4];

		private string[] texPaths = new string[5];

		private Texture2D[][] texturesLocal = new Texture2D[5][];

		private Texture2D[][] texturesRemote = new Texture2D[5][];

		private byte[] Bytes;

		public static Structure_Texturing Struc;

		public void init()
		{
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			Struc = this;
			types[0] = "Pillar";
			types[1] = "Wall";
			types[2] = "Disc";
			types[3] = "RockCube";
			types[4] = "Ball";
			texPaths[0] = "/Skins/Pillar/";
			texPaths[1] = "/Skins/Wall/";
			texPaths[2] = "/Skins/Disc/";
			texPaths[3] = "/Skins/Cube/";
			texPaths[4] = "/Skins/Ball/";
			texTypes[0] = "Normal";
			texTypes[1] = "Main";
			texTypes[2] = "Mat";
			texTypes[3] = "Grounded";
			for (int i = 0; i < texturesLocal.Length; i++)
			{
				texturesLocal[i] = (Texture2D[])(object)new Texture2D[4];
				texturesRemote[i] = (Texture2D[])(object)new Texture2D[4];
				for (int j = 0; j < texTypes.Length; j++)
				{
					if (File.Exists(MelonEnvironment.UserDataDirectory + texPaths[i] + texTypes[j] + ".png"))
					{
						texturesLocal[i][j] = new Texture2D(2, 2);
						Bytes = File.ReadAllBytes(MelonEnvironment.UserDataDirectory + texPaths[i] + texTypes[j] + ".png");
						ImageConversion.LoadImage(texturesLocal[i][j], Il2CppStructArray<byte>.op_Implicit(Bytes));
						((Object)texturesLocal[i][j]).hideFlags = (HideFlags)61;
					}
					else
					{
						texturesLocal[i][j] = null;
					}
				}
			}
			MelonLogger.Msg("Structures Passed File loading");
		}

		public void texture(GameObject obj, int type, bool isLocal)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			Texture2D[][] array = ((!isLocal) ? texturesRemote : texturesLocal);
			MeshRenderer component = obj.GetComponent<MeshRenderer>();
			MaterialPropertyBlock val = new MaterialPropertyBlock();
			((Renderer)component).GetPropertyBlock(val);
			if ((Object)(object)array[type][0] != (Object)null)
			{
				val.SetTexture("Texture2D_2058E65A", (Texture)(object)array[type][0]);
			}
			if ((Object)(object)array[type][1] != (Object)null)
			{
				val.SetTexture("Texture2D_3812B1EC", (Texture)(object)array[type][1]);
			}
			if ((Object)(object)array[type][2] != (Object)null)
			{
				val.SetTexture("Texture2D_8F187FEF", (Texture)(object)array[type][2]);
			}
			if ((Object)(object)array[type][3] != (Object)null)
			{
				val.SetTexture("_GroundTexture", (Texture)(object)array[type][3]);
			}
			((Renderer)component).SetPropertyBlock(val);
		}
	}
}