Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of XoF Avatar pack v1.1.1
BepInEx/plugins/PlayerAvatarLoader.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Xml; using BepInEx; using BepInEx.Configuration; 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 = "")] [assembly: AssemblyCompany("PlayerAvatarLoader")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PlayerAvatarLoader")] [assembly: AssemblyTitle("PlayerAvatarLoader")] [assembly: AssemblyVersion("1.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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 PlayerAvatarLoader { public class BodyReplacement : BodyReplacementBase { protected override GameObject LoadAssetsAndReturnModel() { PlayerControllerB component = ((Component)this).gameObject.GetComponent<PlayerControllerB>(); ulong playerSteamId = component.playerSteamId; string playerUsername = component.playerUsername; int currentSuitID = component.currentSuitID; string text = StartOfRound.Instance.unlockablesList.unlockables[currentSuitID].unlockableName; if (text == "Default") { Debug.LogWarning((object)"Detected An Attempt To Load Suit 'Default'. This Is Likely Because MoreSuits Is Installed. Falling Back To 'Orange suit'."); text = "Orange suit"; } Debug.LogWarning((object)("Attempting To Load '" + text + "' For " + playerUsername + "(" + playerSteamId + ")")); if (Assets.loadedBundleIds.FirstOrDefault((string stringToCheck) => stringToCheck.Contains(playerSteamId.ToString())) != null) { Debug.LogWarning((object)("Found Previously Loaded Bundle For " + playerUsername + "(" + playerSteamId + ")")); int index = Assets.loadedBundleIds.FindIndex((string x) => x.Contains(playerSteamId.ToString())); GameObject val = Assets.loadedAssetBundles[index].LoadAsset<GameObject>(text); if ((Object)(object)val != (Object)null) { return val; } Debug.LogError((object)("No '" + text + "' Model Found For " + playerSteamId + "!!! Falling Back To Default")); val = Assets.initAssetBundle.LoadAsset<GameObject>(text); if ((Object)(object)val == (Object)null) { Debug.LogError((object)("No '" + text + "' Model Found Inside Default Bundle!!! Falling Back To 'Orange suit'")); return Assets.initAssetBundle.LoadAsset<GameObject>("Orange suit"); } return val; } Debug.LogWarning((object)("Bundle Not Yet Loaded For " + playerUsername + "(" + playerSteamId + "). Attempting To Load New Bundle...")); AssetBundle val2 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Avatars", playerSteamId.ToString())); if ((Object)(object)val2 != (Object)null) { Assets.PopulateAssets(check: true, playerSteamId.ToString(), val2); GameObject val3 = val2.LoadAsset<GameObject>(text); if ((Object)(object)val3 != (Object)null) { return val3; } Debug.LogError((object)("No '" + text + "' Model Found For " + playerSteamId + "!!! Falling Back To Default")); return Assets.initAssetBundle.LoadAsset<GameObject>(text); } Debug.LogError((object)(playerUsername + "(" + playerSteamId + ") Does Not Have A Bundle!!! Falling Back To Default.")); return Assets.initAssetBundle.LoadAsset<GameObject>(text); } protected override void OnEmoteStart(int emoteId) { PlayerControllerB component = ((Component)this).gameObject.GetComponent<PlayerControllerB>(); ulong playerSteamId = component.playerSteamId; string playerUsername = component.playerUsername; int currentSuitID = component.currentSuitID; string text = StartOfRound.Instance.unlockablesList.unlockables[currentSuitID].unlockableName; if (text == "Default") { text = "Orange suit"; } string path = playerSteamId + ".xml"; if (!File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Avatars", path))) { return; } Debug.LogWarning((object)("Blend Shapes Found For " + playerUsername + "(" + playerSteamId + "). Checking Settings For '" + text + "'...")); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Avatars", path)); string text2 = string.Concat(text.Where((char c) => !char.IsWhiteSpace(c))); XmlNode xmlNode = xmlDocument.SelectSingleNode("/root/" + text2); if (xmlNode == null) { return; } XmlNode xmlNode2 = xmlDocument.SelectSingleNode("/root/" + text2 + "/BlendShapes"); if (xmlNode2 != null) { bool flag = false; int num = 1; while (!flag) { XmlNode xmlNode3 = xmlDocument.SelectSingleNode("/root/" + text2 + "/BlendShapes/Default/Blend" + num); if (xmlNode3 != null) { string[] array = xmlNode3.InnerText.Split("%/"); base.replacementModel.GetComponentInChildren<SkinnedMeshRenderer>().SetBlendShapeWeight(int.Parse(array[0]), float.Parse(array[1])); num++; } else { flag = true; } } if (emoteId == 1) { bool flag2 = false; int num2 = 1; while (!flag2) { XmlNode xmlNode4 = xmlDocument.SelectSingleNode("/root/" + text2 + "/BlendShapes/Emote1/Blend" + num2); if (xmlNode4 != null) { string[] array2 = xmlNode4.InnerText.Split("%/"); base.replacementModel.GetComponentInChildren<SkinnedMeshRenderer>().SetBlendShapeWeight(int.Parse(array2[0]), float.Parse(array2[1])); num2++; } else { flag2 = true; } } } if (emoteId != 2) { return; } bool flag3 = false; int num3 = 1; while (!flag3) { XmlNode xmlNode5 = xmlDocument.SelectSingleNode("/root/" + text2 + "/BlendShapes/Emote2/Blend" + num3); if (xmlNode5 != null) { string[] array3 = xmlNode5.InnerText.Split("%/"); base.replacementModel.GetComponentInChildren<SkinnedMeshRenderer>().SetBlendShapeWeight(int.Parse(array3[0]), float.Parse(array3[1])); num3++; } else { flag3 = true; } } } else { Debug.LogWarning((object)("No BlendShapes Found For '" + text + "'")); } } protected override void OnEmoteEnd() { PlayerControllerB component = ((Component)this).gameObject.GetComponent<PlayerControllerB>(); ulong playerSteamId = component.playerSteamId; string playerUsername = component.playerUsername; int currentSuitID = component.currentSuitID; string text = StartOfRound.Instance.unlockablesList.unlockables[currentSuitID].unlockableName; if (text == "Default") { text = "Orange suit"; } string path = playerSteamId + ".xml"; if (!File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Avatars", path))) { return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Avatars", path)); string text2 = string.Concat(text.Where((char c) => !char.IsWhiteSpace(c))); XmlNode xmlNode = xmlDocument.SelectSingleNode("/root/" + text2); if (xmlNode == null) { return; } XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/root/" + text2 + "/BlendShapes"); if (xmlNodeList == null) { return; } bool flag = false; int num = 1; while (!flag) { XmlNode xmlNode2 = xmlDocument.SelectSingleNode("/root/" + text2 + "/BlendShapes/Default/Blend" + num); if (xmlNode2 != null) { string[] array = xmlNode2.InnerText.Split("%/"); base.replacementModel.GetComponentInChildren<SkinnedMeshRenderer>().SetBlendShapeWeight(int.Parse(array[0]), float.Parse(array[1])); num++; } else { flag = true; } } } } [BepInPlugin("NotAustinVT.PlayerAvatarLoader", "Player Avatar Loader", "1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(PlayerControllerB))] public class PlayerControllerBPatch { [HarmonyPatch("Update")] [HarmonyPostfix] public static void UpdatePatch(ref PlayerControllerB __instance) { if (__instance.playerSteamId != 0) { } } } public static readonly Harmony Harmony = new Harmony("NotAustinVT.PlayerAvatarLoader"); public static ConfigEntry<string> SuitsToReg = null; private void Awake() { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown SuitsToReg = ((BaseUnityPlugin)this).Config.Bind<string>("Suits - ONLY EDIT FOR SUIT MOD COMPATIBILITY", "Suits", "Orange suit,Green suit,Hazard suit,Pajama suit", "Include all suits being loaded. (If using More_Suits, DO NOT INCLUDE 'Default' IN THE LIST OF SUITS TO LOAD"); char[] separator = new char[1] { ',' }; string[] array = SuitsToReg.Value.Split(separator); ModelReplacementAPI.RegisterSuitModelReplacement("Default", typeof(BodyReplacement)); for (int i = 0; i < array.Length; i++) { if (array[i] != "Default") { ModelReplacementAPI.RegisterSuitModelReplacement(array[i], typeof(BodyReplacement)); } } Assets.PopulateAssets(check: false, "if you see this you're gay", null); Harmony val = new Harmony("NotAustinVT.AvatarLoader"); val.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin NotAustinVT.PlayerAvatarLoader is loaded!"); } } public static class Assets { public static AssetBundle initAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Avatars", "default")); public static List<string> loadedBundleIds = new List<string>(); public static List<AssetBundle> loadedAssetBundles = new List<AssetBundle>(); private static string GetAssemblyName() { return Assembly.GetExecutingAssembly().FullName.Split(',')[0]; } public static void PopulateAssets(bool check, string playerSteamId, AssetBundle playerAssetBundle) { if (check) { loadedBundleIds.Add(playerSteamId); loadedAssetBundles.Add(playerAssetBundle); } } } }