Please disclose if any significant portion of your mod was created 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 TooManyEmotesAddonFix v0.2.0
TooManyEmotesAddonFix.dll
Decompiled a month agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TooManyEmotes; using TooManyEmotes.Props; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TooManyEmotesAddonFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Fixes TooManyEmotes addons.")] [assembly: AssemblyFileVersion("0.2.0.0")] [assembly: AssemblyInformationalVersion("0.2.0+a39099850a87a4afb9f5088bb1aec7c46abe07fc")] [assembly: AssemblyProduct("TooManyEmotesAddonFix")] [assembly: AssemblyTitle("TooManyEmotesAddonFix")] [assembly: AssemblyVersion("0.2.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 TooManyEmotesAddonFix { [HarmonyPatch] internal static class AddonTiers { private static readonly List<UnlockableEmote> addonEmotes = new List<UnlockableEmote>(); private static readonly FieldRef<List<UnlockableEmote>> complementaryEmotesDefault = AccessTools.StaticFieldRefAccess<List<UnlockableEmote>>(AccessTools.Field(typeof(EmotesManager), "complementaryEmotesDefault")); internal static void Apply() { if (EmotesManager.allUnlockableEmotes == null || !BaseBundles.Found) { return; } float[] tierFloors = Settings.TierFloors(); Dictionary<string, int> dictionary = Settings.ParseOverrides(); addonEmotes.Clear(); int[] array = new int[4]; foreach (UnlockableEmote allUnlockableEmote in EmotesManager.allUnlockableEmotes) { if (allUnlockableEmote.complementary && !((Object)(object)allUnlockableEmote.animationClip == (Object)null) && !BaseBundles.FreeClips.Contains(allUnlockableEmote.animationClip)) { allUnlockableEmote.complementary = false; allUnlockableEmote.displayName = OriginalCaseName(allUnlockableEmote); if (!dictionary.TryGetValue(allUnlockableEmote.displayName, out allUnlockableEmote.rarity)) { allUnlockableEmote.rarity = TierFor(allUnlockableEmote, tierFloors); } addonEmotes.Add(allUnlockableEmote); TierList(allUnlockableEmote.rarity).Add(allUnlockableEmote); complementaryEmotesDefault.Invoke()?.Remove(allUnlockableEmote); EmotesManager.complementaryEmotes?.Remove(allUnlockableEmote); array[allUnlockableEmote.rarity]++; } } int num = array[0] + array[1] + array[2] + array[3]; if (num > 0) { Plugin.mlg.LogInfo((object)$"Tiered {num} addon emotes: {array[0]} Common, {array[1]} Rare, {array[2]} Epic, {array[3]} Legendary."); } } [HarmonyPatch(typeof(SessionManager), "ResetEmotesLocal")] [HarmonyPostfix] private static void UnlockFreeAddonEmotes() { if (!Settings.MustBeBought.Value) { SessionManager.UnlockEmotesLocal((IEnumerable<UnlockableEmote>)addonEmotes, false, ""); } } private static int TierFor(UnlockableEmote emote, float[] tierFloors) { float num = emote.animationClip.length; if ((Object)(object)emote.transitionsToClip != (Object)null) { num += emote.transitionsToClip.length; } int i; for (i = 0; i < tierFloors.Length && num >= tierFloors[i]; i++) { } return i; } private static string OriginalCaseName(UnlockableEmote emote) { string text = ((emote.emoteSyncGroupName != "") ? emote.emoteSyncGroupName : emote.emoteName); text = text.Replace('_', ' ').Trim(' '); if (!(text != "")) { return emote.displayName; } return text; } private static List<UnlockableEmote> TierList(int rarity) { return rarity switch { 1 => EmotesManager.allEmotesTier1, 2 => EmotesManager.allEmotesTier2, 3 => EmotesManager.allEmotesTier3, _ => EmotesManager.allEmotesTier0, }; } } internal static class BaseBundles { private static readonly string[] emoteBundles = new string[6] { "emotes_0", "emotes_1", "emotes_2", "emotes_3", "emotes_complementary", "emotes_special" }; private static readonly string[] freeBundles = new string[2] { "emotes_complementary", "emotes_special" }; internal static List<(AnimationClip clip, string originalName)> Clips { get; private set; } internal static HashSet<AnimationClip> AllClips { get; private set; } internal static HashSet<AnimationClip> FreeClips { get; private set; } internal static bool Found => Clips != null; internal static void Find() { if (Found) { return; } List<(AnimationClip, string)> list = new List<(AnimationClip, string)>(); HashSet<AnimationClip> hashSet = new HashSet<AnimationClip>(); HashSet<AnimationClip> hashSet2 = new HashSet<AnimationClip>(); int num = 0; foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles()) { if (Array.IndexOf(emoteBundles, ((Object)allLoadedAssetBundle).name) < 0) { continue; } num++; bool flag = Array.IndexOf(freeBundles, ((Object)allLoadedAssetBundle).name) >= 0; string[] allAssetNames = allLoadedAssetBundle.GetAllAssetNames(); foreach (string text in allAssetNames) { if (!text.EndsWith(".anim", StringComparison.OrdinalIgnoreCase)) { continue; } AnimationClip val = allLoadedAssetBundle.LoadAsset<AnimationClip>(text); if (!((Object)(object)val == (Object)null)) { list.Add((val, Path.GetFileNameWithoutExtension(text))); hashSet.Add(val); if (flag) { hashSet2.Add(val); } } } } if (num < emoteBundles.Length) { Plugin.mlg.LogError((object)$"Found {num} of TooManyEmotes' {emoteBundles.Length} emote bundles, emotes are left as they are."); return; } Clips = list; AllClips = hashSet; FreeClips = hashSet2; } } [HarmonyPatch] internal static class EmoteListRepair { private readonly struct AddonEmoteSettings { private readonly bool boomboxAudio; private readonly bool canMoveWhileEmoting; private readonly string overrideAudioClipName; private readonly string overrideAudioLoopClipName; private readonly float recordSongLoopValue; private readonly bool requiresHeldProp; private readonly GameObject requiredHeldPropPrefab; private readonly List<string> propNamesInEmote; internal AddonEmoteSettings(UnlockableEmote emote) { boomboxAudio = isBoomboxAudio.Invoke(emote); canMoveWhileEmoting = emote.canMoveWhileEmoting; overrideAudioClipName = emote.overrideAudioClipName; overrideAudioLoopClipName = emote.overrideAudioLoopClipName; recordSongLoopValue = emote.recordSongLoopValue; requiresHeldProp = emote.requiresHeldProp; requiredHeldPropPrefab = emote.requiredHeldPropPrefab; propNamesInEmote = emote.propNamesInEmote; } internal void ApplyTo(UnlockableEmote emote) { isBoomboxAudio.Invoke(emote) = boomboxAudio; emote.canMoveWhileEmoting = canMoveWhileEmoting; emote.overrideAudioClipName = overrideAudioClipName; emote.overrideAudioLoopClipName = overrideAudioLoopClipName; emote.recordSongLoopValue = recordSongLoopValue; emote.requiresHeldProp = requiresHeldProp; emote.requiredHeldPropPrefab = requiredHeldPropPrefab; if (emote.propNamesInEmote == null) { emote.propNamesInEmote = propNamesInEmote; } } } private static bool ready; private static bool rebuilding; private static Dictionary<AnimationClip, AddonEmoteSettings> addonSettings; private static readonly FieldRef<UnlockableEmote, bool> isBoomboxAudio = AccessTools.FieldRefAccess<UnlockableEmote, bool>("_isBoomboxAudio"); private static readonly FieldInfo emotePropsData = AccessTools.Field(AccessTools.TypeByName("TooManyEmotes.Props.EmotePropManager"), "emotePropsData"); private static readonly MethodInfo buildEmotePropList = AccessTools.Method(AccessTools.TypeByName("TooManyEmotes.Props.EmotePropManager"), "BuildEmotePropList", (Type[])null, (Type[])null); internal static void AtStartup() { Stopwatch stopwatch = Stopwatch.StartNew(); BaseBundles.Find(); ready = BaseBundles.Found; if (ready) { addonSettings = SaveAddonSettings(); Repair(); Plugin.mlg.LogInfo((object)$"Emote list repaired and tiered in {stopwatch.ElapsedMilliseconds} ms."); } } [HarmonyPatch(typeof(EmotesManager), "BuildEmotesList")] [HarmonyPrefix] private static void BeforeBuild() { if (ready && !rebuilding) { addonSettings = SaveAddonSettings(); } } [HarmonyPatch(typeof(EmotesManager), "BuildEmotesList")] [HarmonyPostfix] private static void AfterBuild() { if (ready && !rebuilding) { Repair(); } } private static void Repair() { try { RestoreClipNames(); rebuilding = true; try { EmotesManager.BuildEmotesList(); } finally { rebuilding = false; } RerunBaseSetup(); RestoreAddonSettings(); } catch (Exception arg) { Plugin.mlg.LogError((object)$"Could not repair the emote list: {arg}"); } AddonTiers.Apply(); } private static void RestoreClipNames() { foreach (var (val, text) in BaseBundles.Clips) { if ((Object)(object)val != (Object)null && !string.Equals(((Object)val).name, text, StringComparison.OrdinalIgnoreCase)) { ((Object)val).name = text; } } } private static void RerunBaseSetup() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (emotePropsData?.GetValue(null) is IEnumerable enumerable) { foreach (EmotePropData item in enumerable) { if ((int)item != 0) { item.parentEmotes?.Clear(); } } } buildEmotePropList?.Invoke(null, null); AdditionalEmoteData.SetAdditionalEmoteData(); AdditionalEmoteData.SetAdditionalPropData(); AdditionalEmoteData.SetAdditionalMusicData(); } private static Dictionary<AnimationClip, AddonEmoteSettings> SaveAddonSettings() { Dictionary<AnimationClip, AddonEmoteSettings> dictionary = new Dictionary<AnimationClip, AddonEmoteSettings>(); if (EmotesManager.allUnlockableEmotes == null) { return dictionary; } foreach (UnlockableEmote allUnlockableEmote in EmotesManager.allUnlockableEmotes) { if ((Object)(object)allUnlockableEmote.animationClip != (Object)null && !BaseBundles.AllClips.Contains(allUnlockableEmote.animationClip)) { dictionary[allUnlockableEmote.animationClip] = new AddonEmoteSettings(allUnlockableEmote); } } return dictionary; } private static void RestoreAddonSettings() { if (addonSettings == null) { return; } foreach (UnlockableEmote allUnlockableEmote in EmotesManager.allUnlockableEmotes) { if ((Object)(object)allUnlockableEmote.animationClip != (Object)null && addonSettings.TryGetValue(allUnlockableEmote.animationClip, out var value)) { value.ApplyTo(allUnlockableEmote); } } } } [BepInPlugin("dev.davesco.TooManyEmotesAddonFix", "TooManyEmotesAddonFix", "0.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string modGUID = "dev.davesco.TooManyEmotesAddonFix"; public const string modName = "TooManyEmotesAddonFix"; public const string modVersion = "0.2.0"; private Harmony _harmony = new Harmony("dev.davesco.TooManyEmotesAddonFix"); internal static ManualLogSource mlg = Logger.CreateLogSource("dev.davesco.TooManyEmotesAddonFix"); private void Awake() { Settings.Init(((BaseUnityPlugin)this).Config); _harmony.PatchAll(); EmoteListRepair.AtStartup(); mlg.LogInfo((object)"Plugin TooManyEmotesAddonFix is loaded!"); } } internal static class Settings { internal static ConfigEntry<bool> MustBeBought; internal static ConfigEntry<float> RareFrom; internal static ConfigEntry<float> EpicFrom; internal static ConfigEntry<float> LegendaryFrom; internal static ConfigEntry<string> TierOverrides; private static readonly string[] tierNames = new string[4] { "common", "rare", "epic", "legendary" }; internal static void Init(ConfigFile config) { MustBeBought = config.Bind<bool>("Addon emotes", "MustBeBought", true, "If false, addon emotes still get a tier but are unlocked from the start.\nEveryone in the lobby needs the same value."); RareFrom = config.Bind<float>("Tiers", "RareFromSeconds", 7f, "Addon emotes are tiered by animation length. Shorter than this is Common.\nEveryone in the lobby needs the same value."); EpicFrom = config.Bind<float>("Tiers", "EpicFromSeconds", 14f, "Emotes at least this long are Epic.\nEveryone in the lobby needs the same value."); LegendaryFrom = config.Bind<float>("Tiers", "LegendaryFromSeconds", 28f, "Emotes at least this long are Legendary.\nEveryone in the lobby needs the same value."); TierOverrides = config.Bind<string>("Tiers", "Overrides", "", "Set the tier of single emotes by name, e.g. Chicken Dance:Common, SCOOBY DOO:Epic\nEveryone in the lobby needs the same value."); } internal static float[] TierFloors() { float[] obj = new float[3] { RareFrom.Value, EpicFrom.Value, LegendaryFrom.Value }; Array.Sort(obj); return obj; } internal static Dictionary<string, int> ParseOverrides() { Dictionary<string, int> dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); string[] array = TierOverrides.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { int num = text.LastIndexOf(':'); int num2 = ((num < 0) ? (-1) : Array.IndexOf(tierNames, text.Substring(num + 1).Trim().ToLowerInvariant())); if (num2 < 0) { Plugin.mlg.LogWarning((object)("Can't read tier override \"" + text.Trim() + "\", expected Name:Common/Rare/Epic/Legendary.")); } else { dictionary[text.Substring(0, num).Trim()] = num2; } } return dictionary; } } public static class PluginInfo { public const string PLUGIN_GUID = "TooManyEmotesAddonFix"; public const string PLUGIN_NAME = "TooManyEmotesAddonFix"; public const string PLUGIN_VERSION = "0.2.0"; } }