Decompiled source of Lillys Level Uncapper v1.0.1

Mods/Player_Textures.dll

Decompiled 14 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Mirror;
using Player_Textures;
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(PlayerTex), "Player Textures", "1.0.0", "Lilly", null)]
[assembly: MelonGame("KisSoft", "ATLYSS")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Player_Textures")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+70a392a4497e5c262cd2b6c3861a1f779c94d596")]
[assembly: AssemblyProduct("Player_Textures")]
[assembly: AssemblyTitle("Player_Textures")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Player_Textures
{
	public class PlayerTex : MelonMod
	{
		[HarmonyPatch(typeof(ChatBehaviour), "Cmd_SendChatMessage")]
		public static class chatCommands
		{
			private static bool Prefix(ref ChatBehaviour __instance, ref string _message)
			{
				try
				{
					_message = _message.ToLower();
					MelonLogger.Msg(_message);
					if (_message.StartsWith("/reload"))
					{
						instance.reTex();
						return false;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Msg((object)ex);
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Player), "OnGameConditionChange")]
		public static class playerspawn
		{
			private static void Postfix(ref Player __instance)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Invalid comparison between Unknown and I4
				if ((int)__instance._currentGameCondition == 1 && ((NetworkBehaviour)__instance).isLocalPlayer)
				{
					instance.Localplayer = __instance;
					instance.reTex();
				}
			}
		}

		private byte[] Bytes;

		private static PlayerTex instance;

		public Player Localplayer;

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

		public override void OnInitializeMelon()
		{
			instance = this;
			paths[0] = new string[4];
			paths[0][0] = "Imp/Head.png";
			paths[0][1] = "Imp/Chest.png";
			paths[0][2] = "Imp/Legs.png";
			paths[0][3] = "Imp/Tail.png";
			paths[1] = new string[4];
			paths[1][0] = "Poon/Head.png";
			paths[1][1] = "Poon/Chest.png";
			paths[1][2] = "Poon/Legs.png";
			paths[1][3] = "Poon/Tail.png";
			paths[2] = new string[4];
			paths[2][0] = "Kobold/Head.png";
			paths[2][1] = "Kobold/Chest.png";
			paths[2][2] = "Kobold/Legs.png";
			paths[2][3] = "Kobold/Tail.png";
			paths[3] = new string[4];
			paths[3][0] = "Byrdle/Head.png";
			paths[3][1] = "Byrdle/Chest.png";
			paths[3][2] = "Byrdle/Legs.png";
			paths[3][3] = "Byrdle/Tail.png";
			paths[4] = new string[4];
			paths[4][0] = "Chang/Head.png";
			paths[4][1] = "Chang/Chest.png";
			paths[4][2] = "Chang/Legs.png";
			paths[4][3] = "Chang/Tail.png";
		}

		public void reTex()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			string text = Localplayer._pVisual._playerRaceModel._scriptablePlayerRace._raceName.ToLower();
			PlayerRaceModel component = ((Component)((Component)((Component)Localplayer._pVisual).transform.Find("_playerVisualContainer/_playerVisual")).transform.GetChild(0)).GetComponent<PlayerRaceModel>();
			MelonLogger.Msg(((Object)component).name);
			int num = 0;
			MelonLogger.Msg(text);
			switch (text)
			{
			case "imp":
				num = 0;
				break;
			case "poon":
				num = 1;
				break;
			case "kobold":
				num = 2;
				break;
			case "byrdle":
				num = 3;
				break;
			case "chang":
				num = 4;
				break;
			}
			Texture2D val = new Texture2D(2, 2);
			Material val2 = null;
			for (int i = 0; i < paths.Length - 2; i++)
			{
				if (!File.Exists(MelonEnvironment.UserDataDirectory + "/Skins/" + paths[num][i]))
				{
					continue;
				}
				val2 = ((Renderer)component._baseBodyMesh).materials[0];
				if (i == 3)
				{
					SkinnedMeshRenderer[] tailDisplays = component._tailDisplays;
					foreach (SkinnedMeshRenderer val3 in tailDisplays)
					{
						Texture mainTexture = ((Renderer)val3).material.mainTexture;
						val = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null);
						ImageConversion.LoadImage(val, File.ReadAllBytes(MelonEnvironment.UserDataDirectory + "/Skins/" + paths[num][i]));
					}
				}
				else
				{
					Texture mainTexture2 = ((Renderer)component._baseBodyMesh).materials[i].mainTexture;
					val = (Texture2D)(object)((mainTexture2 is Texture2D) ? mainTexture2 : null);
					ImageConversion.LoadImage(val, File.ReadAllBytes(MelonEnvironment.UserDataDirectory + "/Skins/" + paths[num][i]));
				}
			}
		}
	}
}