Decompiled source of MatyasZERO ModpackPosters v2.1.1

MatySMP_models.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("d")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("d")]
[assembly: AssemblyTitle("d")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Matysmpmodels
{
	public class MRSKRTEK : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "Skrtek";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class MRVIKTOR : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "Viktor";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class MRFANDYS : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "Fandys";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class MRKEISHTAN : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "Keishtan";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class MRMATY : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "Maty";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	[BepInPlugin("com.matyaszero.matysmpmodels", "MatySMP suits", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static readonly Dictionary<string, Type> RegisteredSuitTypes = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase);

		public static Plugin? Instance { get; private set; }

		public static ManualLogSource? LoggerInstance { get; private set; }

		private void Awake()
		{
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			Instance = this;
			LoggerInstance = ((BaseUnityPlugin)this).Logger;
			Assets.PopulateAssets();
			RegisterSuits(typeof(MRSKRTEK), "Skrtek", "Skrtek suit", "Škrrteček", "Škrrteček suit", "Skrrtecek", "Skrrtecek suit");
			RegisterSuits(typeof(MRVIKTOR), "Viktor", "Viktor suit", "vitko3000", "vitko3000 suit", "vitko", "vitko suit");
			RegisterSuits(typeof(MRMATY), "Maty", "Maty suit", "MatyasZERO", "MatyasZERO suit", "Matyas", "Matyas suit");
			RegisterSuits(typeof(MRFANDYS), "Fandys", "Fandys suit");
			RegisterSuits(typeof(MRKEISHTAN), "Keishtan", "Keishtan suit");
			Harmony val = new Harmony("com.matyaszero.matysmpmodels");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.matyaszero.matysmpmodels loaded with player & suit mappings!");
		}

		private static void RegisterSuits(Type modelType, params string[] suitNames)
		{
			foreach (string text in suitNames)
			{
				if (string.IsNullOrWhiteSpace(text))
				{
					continue;
				}
				string text2 = text.Trim();
				string key = text2.ToLowerInvariant().Replace(" ", "");
				if (RegisteredSuitTypes.ContainsKey(key))
				{
					continue;
				}
				RegisteredSuitTypes[key] = modelType;
				try
				{
					ModelReplacementAPI.RegisterSuitModelReplacement(text2, modelType);
				}
				catch (Exception ex)
				{
					ManualLogSource? loggerInstance = LoggerInstance;
					if (loggerInstance != null)
					{
						loggerInstance.LogWarning((object)("Could not register suit '" + text2 + "' with ModelReplacementAPI: " + ex.Message));
					}
				}
			}
		}

		public static string NormalizeUsername(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return string.Empty;
			}
			text = text.Trim().ToLowerInvariant();
			string text2 = text.Normalize(NormalizationForm.FormD);
			StringBuilder stringBuilder = new StringBuilder();
			string text3 = text2;
			foreach (char c in text3)
			{
				UnicodeCategory unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
				if (unicodeCategory != UnicodeCategory.NonSpacingMark)
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
		}

		public static bool TryGetModelForPlayer(string? username, out Type? modelType)
		{
			modelType = null;
			if (string.IsNullOrWhiteSpace(username))
			{
				return false;
			}
			string text = NormalizeUsername(username);
			if (text.Contains("skrrtecek") || text.Contains("skrtek"))
			{
				modelType = typeof(MRSKRTEK);
				return true;
			}
			if (text.Contains("matyaszero") || text.Contains("matyas") || text == "maty" || text.StartsWith("matyas"))
			{
				modelType = typeof(MRMATY);
				return true;
			}
			if (text.Contains("vitko3000") || text.Contains("vitko") || text.Contains("viktor"))
			{
				modelType = typeof(MRVIKTOR);
				return true;
			}
			if (text.Contains("fandys"))
			{
				modelType = typeof(MRFANDYS);
				return true;
			}
			if (text.Contains("keishtan"))
			{
				modelType = typeof(MRKEISHTAN);
				return true;
			}
			return false;
		}

		public static string GetSuitName(int suitID)
		{
			try
			{
				if ((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.unlockablesList != (Object)null && StartOfRound.Instance.unlockablesList.unlockables != null && suitID >= 0 && suitID < StartOfRound.Instance.unlockablesList.unlockables.Count)
				{
					return StartOfRound.Instance.unlockablesList.unlockables[suitID].unlockableName ?? string.Empty;
				}
			}
			catch
			{
			}
			return string.Empty;
		}
	}
	[HarmonyPatch]
	public static class ManageRegistryBodyReplacementsPatch
	{
		[HarmonyTargetMethod]
		public static MethodBase? TargetMethod()
		{
			Type nestedType = typeof(ModelReplacementAPI).GetNestedType("PlayerControllerBPatch", BindingFlags.Public | BindingFlags.NonPublic);
			if (nestedType == null)
			{
				ManualLogSource? loggerInstance = Plugin.LoggerInstance;
				if (loggerInstance != null)
				{
					loggerInstance.LogError((object)"Could not find nested class PlayerControllerBPatch in ModelReplacementAPI!");
				}
				return null;
			}
			MethodInfo method = nestedType.GetMethod("ManageRegistryBodyReplacements", BindingFlags.Static | BindingFlags.Public);
			if (method == null)
			{
				ManualLogSource? loggerInstance2 = Plugin.LoggerInstance;
				if (loggerInstance2 != null)
				{
					loggerInstance2.LogError((object)"Could not find method ManageRegistryBodyReplacements in PlayerControllerBPatch!");
				}
			}
			return method;
		}

		[HarmonyPrefix]
		public static bool Prefix(ref PlayerControllerB __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.thisPlayerBody == (Object)null)
			{
				return true;
			}
			try
			{
				string playerUsername = __instance.playerUsername;
				if (Plugin.TryGetModelForPlayer(playerUsername, out Type modelType) && modelType != null)
				{
					int currentSuitID = __instance.currentSuitID;
					string suitName = Plugin.GetSuitName(currentSuitID);
					string key = suitName.ToLowerInvariant().Replace(" ", "");
					if (Plugin.RegisteredSuitTypes.TryGetValue(key, out Type value) && value != null && value != modelType)
					{
						ModelReplacementAPI.SetPlayerModelReplacement(__instance, value);
						return false;
					}
					ModelReplacementAPI.SetPlayerModelReplacement(__instance, modelType);
					return false;
				}
			}
			catch (Exception arg)
			{
				ManualLogSource? loggerInstance = Plugin.LoggerInstance;
				if (loggerInstance != null)
				{
					loggerInstance.LogError((object)$"Error in ManageRegistryBodyReplacements Prefix: {arg}");
				}
			}
			return true;
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "MatySMPmodels";

		public static AssetBundle? MainAssetBundle = null;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
		}

		public static void PopulateAssets()
		{
			if (!((Object)(object)MainAssetBundle == (Object)null))
			{
				return;
			}
			string name = GetAssemblyName() + "." + mainAssetBundleName;
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			if (stream != null)
			{
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}