using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Sagolasin.Patches;
using TooManyEmotes;
using TooManyEmotes.Config;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("TooManyEmotes")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Sagolasin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Sagolasin")]
[assembly: AssemblyTitle("Sagolasin")]
[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 Sagolasin
{
[BepInPlugin("karster.sagolasin", "sagolasin", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(SessionManager), "ResetGameValues")]
public static class ResetComplementary
{
[HarmonyPostfix]
private static void Test()
{
EmotesManager.complementaryEmotes.AddRange(complementaryModded);
}
}
private const string modGuid = "karster.sagolasin";
private const string modName = "sagolasin";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("karster.sagolasin");
private static Plugin instance;
internal static ManualLogSource mls;
public static AssetBundle MainAssets;
internal static CultureInfo defaultSortCulture = CultureInfo.CreateSpecificCulture("en-US");
public static List<UnlockableEmote> complementaryModded = new List<UnlockableEmote>();
public static List<AnimationClip> testClips;
public static AudioClip[] sagoSongs;
private void Awake()
{
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
mls = Logger.CreateLogSource("karster.sagolasin");
MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sagomat"));
mls.LogDebug((object)MainAssets.GetAllAssetNames());
Item obj = MainAssets.LoadAsset<Item>("sagoBox.asset");
TerminalNode val = MainAssets.LoadAsset<TerminalNode>("sagoBoxInfo.asset");
NetworkPrefabs.RegisterNetworkPrefab(obj.spawnPrefab);
Items.RegisterShopItem(obj, (TerminalNode)null, (TerminalNode)null, val, 100);
UnlockableItem obj2 = MainAssets.LoadAsset<UnlockablesList>("UnlockableList.asset").unlockables[0];
NetworkPrefabs.RegisterNetworkPrefab(obj2.prefabObject);
Unlockables.RegisterUnlockable(obj2, 30, (StoreType)2);
testClips = new List<AnimationClip>(LoadEmoteAssetBundle("emotes_test"));
sagoSongs = LoadAudioAssetBundle("sagosongs");
Plugin.complementaryAnimationClips.AddRange(testClips);
Plugin.customAnimationClipsHash.UnionWith(testClips);
Plugin.customAnimationClips = new List<AnimationClip>(Plugin.customAnimationClipsHash);
LoadEmotes();
harmony.PatchAll(typeof(Plugin));
harmony.PatchAll(typeof(ResetComplementary));
harmony.PatchAll(typeof(CustomBoomboxPatch));
}
private static AnimationClip[] LoadEmoteAssetBundle(string assetBundleName)
{
try
{
AnimationClip[] array = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)instance).Info.Location), assetBundleName)).LoadAllAssets<AnimationClip>();
mls.LogInfo((object)$"Successfully loaded {array.Length} animation clips from asset bundle: {assetBundleName}");
return array;
}
catch
{
mls.LogError((object)"Failed to load emotes Asset Bundle.");
return (AnimationClip[])(object)new AnimationClip[0];
}
}
private static AudioClip[] LoadAudioAssetBundle(string assetBundleName)
{
try
{
AudioClip[] array = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)instance).Info.Location), assetBundleName)).LoadAllAssets<AudioClip>();
mls.LogInfo((object)$"Successfully loaded {array.Length} audio clips from asset bundle: {assetBundleName}");
return array;
}
catch
{
mls.LogError((object)"Failed to load emotes Asset Bundle.");
return (AudioClip[])(object)new AudioClip[0];
}
}
public static void LoadEmotes()
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
complementaryModded = new List<UnlockableEmote>();
while (EmotesManager.allQuickEmotes.Count < EmotesManager.allQuickEmotes.Capacity)
{
EmotesManager.allQuickEmotes.Add("");
}
Dictionary<string, List<UnlockableEmote>> dictionary = new Dictionary<string, List<UnlockableEmote>>();
for (int i = Plugin.customAnimationClips.Count - testClips.Count; i < Plugin.customAnimationClips.Count; i++)
{
AnimationClip val = Plugin.customAnimationClips[i];
UnlockableEmote val2 = new UnlockableEmote
{
emoteId = i,
emoteName = ((Object)val).name,
displayName = "",
animationClip = val,
rarity = 0
};
val2.rarity = (Plugin.animationClipsTier1.Contains(val) ? 1 : (Plugin.animationClipsTier2.Contains(val) ? 2 : (Plugin.animationClipsTier3.Contains(val) ? 3 : 0)));
if (Plugin.complementaryAnimationClips.Contains(val))
{
val2.complementary = true;
}
if (val2.emoteName.Contains("_start") && !val2.emoteName.Contains("_start_"))
{
string key = val2.emoteName.Replace("_start", "_loop");
AnimationClip val3 = Plugin.customAnimationClipsLoopDict[key];
if ((Object)(object)val3 != (Object)null)
{
val2.transitionsToClip = val3;
val2.emoteName = val2.emoteName.Replace("_start", "");
((Object)val2.animationClip).name = val2.emoteName + "_start";
((Object)val2.transitionsToClip).name = val2.emoteName + "_loop";
}
}
else if (val2.emoteName.Contains("_pose"))
{
val2.isPose = true;
val2.emoteName = val2.emoteName.Replace("_pose", "");
((Object)val2.animationClip).name = val2.emoteName;
}
if (val2.emoteName.Contains("."))
{
string[] array = val2.emoteName.Split('.');
if (array.Length != 0 && array[0].Length > 0)
{
if (array.Length > 3)
{
mls.LogError((object)("Error parsing emote name: " + val2.emoteName + ". Correct format: \"emote_group.optional_arg.emote_name\""));
continue;
}
val2.emoteSyncGroupName = array[0];
val2.emoteName = val2.emoteSyncGroupName + "." + array[^1];
val2.displayName = val2.emoteSyncGroupName;
if ((Object)(object)val2.transitionsToClip == (Object)null)
{
((Object)val2.animationClip).name = val2.emoteName;
}
else
{
((Object)val2.animationClip).name = val2.emoteName + "_start";
((Object)val2.transitionsToClip).name = val2.emoteName + "_loop";
}
if (!dictionary.TryGetValue(val2.emoteSyncGroupName, out val2.emoteSyncGroup))
{
val2.emoteSyncGroup = new List<UnlockableEmote>();
dictionary.Add(val2.emoteSyncGroupName, val2.emoteSyncGroup);
}
if (array.Length == 3 && array[1].ToLower().Contains("layer_"))
{
((Object)val).name = ((Object)val).name.Replace("." + array[1], "");
if ((Object)(object)val2.transitionsToClip != (Object)null)
{
((Object)val2.transitionsToClip).name = ((Object)val2.transitionsToClip).name.Replace("." + array[1], "");
}
if (!int.TryParse(array[1].Substring(6), out var result))
{
mls.LogError((object)("Failed to parse emote layer number in arg: " + array[1] + ". Emote will not be added."));
continue;
}
val2.purchasable = result == 0;
while (val2.emoteSyncGroup.Count <= result)
{
val2.emoteSyncGroup.Add(null);
}
val2.emoteSyncGroup[result] = val2;
}
else
{
val2.emoteSyncGroup.Add(val2);
val2.purchasable = val2.emoteSyncGroup.Count == 1;
if (array.Length == 3 && array[1].ToLower() == "random")
{
val2.randomEmote = true;
((Object)val).name = ((Object)val).name.Replace("." + array[1], "");
if ((Object)(object)val2.transitionsToClip != (Object)null)
{
((Object)val2.transitionsToClip).name = ((Object)val2.transitionsToClip).name.Replace("." + array[1], "");
}
}
}
}
}
if (val2.emoteName.Contains("_start") && !val2.emoteName.Contains("_start_"))
{
string key2 = val2.emoteName.Replace("_start", "_loop");
AnimationClip val4 = Plugin.customAnimationClipsLoopDict[key2];
if ((Object)(object)val4 != (Object)null)
{
val2.transitionsToClip = val4;
val2.emoteName = val2.emoteName.Replace("_start", "");
((Object)val2.animationClip).name = val2.emoteName + "_start";
((Object)val2.transitionsToClip).name = val2.emoteName + "_loop";
}
}
else if (val2.emoteName.Contains("_pose"))
{
val2.isPose = true;
val2.emoteName = val2.emoteName.Replace("_pose", "");
((Object)val2.animationClip).name = val2.emoteName;
}
if (!((Object)(object)val2.transitionsToClip != (Object)null) && !((Motion)val2.animationClip).isLooping && !val2.isPose)
{
_ = val2.emoteSyncGroup;
}
val2.canSyncEmote = true;
if (val2.displayName == "")
{
val2.displayName = val2.emoteName;
}
val2.displayName = val2.displayName.Replace('_', ' ').Trim(' ');
val2.displayName = char.ToUpper(val2.displayName[0]) + val2.displayName.Substring(1).ToLower();
if (!EmotesManager.allUnlockableEmotes.Contains(val2))
{
EmotesManager.allUnlockableEmotes.Add(val2);
EmotesManager.allUnlockableEmotesDict.Add(val2.emoteName, val2);
}
if (Plugin.complementaryAnimationClips.Contains(val) && val2.purchasable)
{
val2.complementary = true;
complementaryModded.Add(val2);
}
}
try
{
EmotesManager.allUnlockableEmotes.Sort((UnlockableEmote item1, UnlockableEmote item2) => string.Compare(item1.displayName, item2.displayName, ignoreCase: true, defaultSortCulture));
}
catch (Exception)
{
if (ConfigSettings.verboseLogs.Value)
{
mls.LogWarning((object)"Failed to apply default emote sort. Reverting to original sort method.");
}
EmotesManager.allUnlockableEmotes = EmotesManager.allUnlockableEmotes.OrderBy((UnlockableEmote item) => item.emoteName).ToList();
}
int num = 0;
foreach (UnlockableEmote allUnlockableEmote in EmotesManager.allUnlockableEmotes)
{
allUnlockableEmote.emoteId = num++;
if (!allUnlockableEmote.complementary)
{
if (allUnlockableEmote.rarity == 0)
{
EmotesManager.allEmotesTier0.Add(allUnlockableEmote);
}
else if (allUnlockableEmote.rarity == 1)
{
EmotesManager.allEmotesTier1.Add(allUnlockableEmote);
}
else if (allUnlockableEmote.rarity == 2)
{
EmotesManager.allEmotesTier2.Add(allUnlockableEmote);
}
else if (allUnlockableEmote.rarity == 3)
{
EmotesManager.allEmotesTier3.Add(allUnlockableEmote);
}
}
}
EmotesManager.complementaryEmotes.AddRange(complementaryModded);
SaveManager.LoadFavoritedEmotes();
SaveManager.LoadQuickEmotes();
}
}
}
namespace Sagolasin.Patches
{
[HarmonyPatch(typeof(BoomboxItem), "Start")]
internal class CustomBoomboxPatch
{
[HarmonyPostfix]
private static void Patch(ref BoomboxItem __instance)
{
if (((Object)__instance).name.StartsWith("Sagobox"))
{
Plugin.mls.LogInfo((object)((Object)__instance).name);
__instance.musicAudios = Plugin.sagoSongs;
}
else
{
Plugin.mls.LogInfo((object)((Object)__instance).name);
}
}
}
}