using System;
using System.Collections;
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.Security;
using System.Security.Permissions;
using BaboonAPI.Hooks.Initializer;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TootTallyCore;
using TootTallyCore.Utils.Helpers;
using TootTallyCore.Utils.TootTallyModules;
using TootTallyCore.Utils.TootTallyNotifs;
using TootTallySettings;
using TootTallySettings.TootTallySettingsObjects;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TootTallyCustomTromboner")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Custom Tromboner Module for TootTally")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("TootTallyCustomTromboner")]
[assembly: AssemblyTitle("TootTallyCustomTromboner")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.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 TootTallyCustomTromboner
{
public static class CustomTromboner
{
public static class CustomTrombonerPatches
{
public static GameObject _customPuppet;
public static GameObject _customPuppetPrefab;
public static Animator _customPuppetAnimator;
private static bool _lastTooting;
private static bool _lastOutOfBreath;
[HarmonyPatch(typeof(GameController), "Start")]
[HarmonyPrefix]
public static void SetPuppetIDOnStartPrefix(GameController __instance)
{
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.Instance.option.BonerName.Value == "None")
{
return;
}
if ((Object)(object)_currentBundle == (Object)null)
{
ResolveCurrentBundle();
}
if ((Object)(object)_currentBundle == (Object)null)
{
return;
}
_customPuppetPrefab = _currentBundle.LoadAsset<GameObject>("puppet.prefab");
if ((Object)(object)_customPuppetPrefab != (Object)null)
{
_customPuppet = Object.Instantiate<GameObject>(_customPuppetPrefab, __instance.modelparent.transform);
_customPuppet.transform.localPosition = new Vector3(0.7f, -0.4f, 1.3f);
if (!_customPuppet.TryGetComponent<Animator>(ref _customPuppetAnimator))
{
Plugin.LogInfo("No animator found in custom puppet.");
}
else
{
((Behaviour)_customPuppetAnimator).enabled = false;
}
}
}
[HarmonyPatch(typeof(GameController), "isNoteButtonPressed")]
[HarmonyPostfix]
public static void OnTootingEvent(ref bool __result)
{
if (!((Object)(object)_customPuppetAnimator == (Object)null))
{
if (_lastTooting != __result)
{
_customPuppetAnimator.SetBool("Tooting", __result);
}
_lastTooting = __result;
}
}
[HarmonyPatch(typeof(GameController), "Update")]
[HarmonyPostfix]
public static void UpdatePointerYEvent(GameController __instance)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_customPuppetAnimator == (Object)null))
{
float num = (__instance.pointer.transform.localPosition.y + 180f) / 360f;
_customPuppetAnimator.SetFloat("PointerY", num);
_customPuppetAnimator.SetFloat("Breathing", __instance.breathcounter);
if (_lastOutOfBreath != __instance.outofbreath)
{
_customPuppetAnimator.SetBool("OutOfBreath", __instance.outofbreath);
}
_lastOutOfBreath = __instance.outofbreath;
}
}
[HarmonyPatch(typeof(HumanPuppetController), "startPuppetBob")]
[HarmonyPostfix]
public static void ActivateCustomPuppetAnimation()
{
if ((Object)(object)_customPuppetAnimator != (Object)null)
{
((Behaviour)_customPuppetAnimator).enabled = true;
}
}
[HarmonyPatch(typeof(HumanPuppetController), "playCameraRotationTween")]
[HarmonyPostfix]
public static void SetCustomAnimationActive(bool play)
{
if ((Object)(object)_customPuppetAnimator != (Object)null)
{
((Behaviour)_customPuppetAnimator).enabled = play;
}
}
[HarmonyPatch(typeof(GameController), "Start")]
[HarmonyPostfix]
public static void OverwriteHumanPuppetBody(GameController __instance)
{
if ((Object)(object)_customPuppetPrefab != (Object)null)
{
__instance.puppet_human.SetActive(false);
if ((Object)(object)_customPuppetAnimator != (Object)null)
{
_customPuppetAnimator.SetBool("Tooting", false);
_customPuppetAnimator.SetBool("OutOfBreath", false);
_customPuppetAnimator.SetFloat("PointerY", 0.5f);
float num = __instance.tempo * (GlobalVariables.turbomode ? 2f : GlobalVariables.practicemode);
_customPuppetAnimator.SetFloat("Tempo", num);
_customPuppetAnimator.SetFloat("AnimationSpeed", num / 120f);
}
}
else if (!((Object)(object)_currentBundle == (Object)null))
{
Plugin.LogInfo("Applying Custom Boner...");
HumanPuppetController puppet_humanc = __instance.puppet_humanc;
puppet_humanc.head_oob = GetMaterial("head_oob.mat");
puppet_humanc.head_def = GetMaterial("head_def.mat");
puppet_humanc.head_def_es = GetMaterial("head_def_es.mat");
puppet_humanc.head_act = GetMaterial("head_act.mat");
puppet_humanc.costume_alt = GetMaterial("custom_alt.mat");
Material[] materials = ((Renderer)puppet_humanc.bodymesh).materials;
materials[0] = GetMaterial("body.mat");
((Renderer)puppet_humanc.bodymesh).materials = materials;
}
}
}
[Serializable]
private class BonerInfo : MonoBehaviour
{
public string Name { get; set; }
public string Description { get; set; }
public string Author { get; set; }
public string PuppetName { get; set; }
}
public const string CUSTOM_TROMBONER_FOLDER = "CustomTromboners";
private static Dictionary<string, AssetBundle> _bonerDict;
private static AssetBundle _currentBundle;
public static string[] GetBonerNames => _bonerDict.Keys.ToArray();
public static void LoadAssetBundles()
{
Plugin.LogInfo("Loading CustomTromboners...");
if (_bonerDict != null)
{
foreach (string key in _bonerDict.Keys)
{
_bonerDict[key].Unload(true);
}
}
_bonerDict = new Dictionary<string, AssetBundle>();
string diretory = Path.Combine(Paths.BepInExRootPath, "CustomTromboners");
List<FileInfo> allBonerFilesFromDirectory = TrombonerFileHelper.GetAllBonerFilesFromDirectory(diretory);
allBonerFilesFromDirectory.ForEach(delegate(FileInfo file)
{
((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)LoadAssetBundleAsync(file.FullName, delegate(AssetBundle bundle)
{
string text = file.Name.Replace(".boner", "");
_bonerDict.Add(text, bundle);
Plugin.dropdown.AddOptions(new string[1] { text });
Plugin.LogInfo(text + " boner added.");
}));
});
Plugin.LogInfo("Custom Tromboners Loaded.");
}
public static IEnumerator<AssetBundleCreateRequest> LoadAssetBundleAsync(string path, Action<AssetBundle> callback)
{
AssetBundleCreateRequest bundleRequest = AssetBundle.LoadFromFileAsync(path);
yield return bundleRequest;
if ((Object)(object)bundleRequest.assetBundle != (Object)null)
{
callback(bundleRequest.assetBundle);
}
else
{
Plugin.LogInfo("Failed to load " + path + " boner.");
}
}
public static void ResolveCurrentBundle()
{
string value = Plugin.Instance.option.BonerName.Value;
if (value != "None" && _bonerDict != null && _bonerDict.TryGetValue(value, out _currentBundle))
{
Plugin.LogInfo("Boner bundle " + value + " loaded.");
}
else if ((Object)(object)_currentBundle != (Object)null && value == "None")
{
Plugin.LogInfo("No bundle loaded.");
_currentBundle = null;
}
}
public static Material GetMaterial(string name)
{
AssetBundle currentBundle = _currentBundle;
return (currentBundle != null) ? currentBundle.LoadAsset<Material>(name) : null;
}
public static Texture GetTexture(string name)
{
AssetBundle currentBundle = _currentBundle;
return (currentBundle != null) ? currentBundle.LoadAsset<Texture>(name) : null;
}
public static int GetPuppetIDFromName(string PuppetName)
{
string text = PuppetName.ToLower().Replace(" ", "");
if (1 == 0)
{
}
int result;
switch (text)
{
case "beezerly":
case "kazyleii":
result = 0;
break;
case "appaloosa":
case "trixiebell":
result = 2;
break;
case "hornlord":
case "soda":
result = 4;
break;
case "jermajesty":
case "meldor":
result = 6;
break;
default:
result = -1;
break;
}
if (1 == 0)
{
}
return result;
}
}
[BepInPlugin("TootTallyCustomTromboner", "TootTallyCustomTromboner", "1.1.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin, ITootTallyModule
{
public class Options
{
public ConfigEntry<string> BonerName { get; set; }
}
public static Plugin Instance;
private const string CONFIG_NAME = "CustomBoner.cfg";
private const string BONER_CONFIG_FIELD = "CustomBoner";
public const string DEFAULT_BONER = "None";
public Options option;
private Harmony _harmony;
public static TootTallySettingPage settingPage;
public static TootTallySettingDropdown dropdown;
public ConfigEntry<bool> ModuleConfigEnabled { get; set; }
public bool IsConfigInitialized { get; set; }
public string Name
{
get
{
return "Custom Tromboner";
}
set
{
Name = value;
}
}
public static void LogInfo(string msg)
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
}
public static void LogError(string msg)
{
((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
}
private void Awake()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
if (!((Object)(object)Instance != (Object)null))
{
Instance = this;
_harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
GameInitializationEvent.Register(((BaseUnityPlugin)this).Info, (Action)TryInitialize);
}
}
private void TryInitialize()
{
ModuleConfigEnabled = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Modules", "Custom Tromboner", true, "Change the appearance of your tromboner");
TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
Plugin.Instance.AddModuleToSettingPage((ITootTallyModule)(object)this);
}
public void LoadModule()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
string text = Path.Combine(Paths.BepInExRootPath, "config/");
ConfigFile val = new ConfigFile(text + "CustomBoner.cfg", true);
option = new Options
{
BonerName = val.Bind<string>("CustomBoner", "BonerName", "None", (ConfigDescription)null)
};
string text2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location), "CustomTromboners");
string text3 = Path.Combine(Paths.BepInExRootPath, "CustomTromboners");
FileHelper.TryMigrateFolder(text2, text3, true);
settingPage = TootTallySettingsManager.AddNewPage("Custom Tromboner", "Custom Tromboner", 40f, new Color(0f, 0f, 0f, 0f));
settingPage.AddLabel("BonerLabel", "Custom Tromboners", 24f, (FontStyles)0, (TextAlignmentOptions)1025);
CustomTromboner.LoadAssetBundles();
List<string> list = new List<string> { "None" };
list.AddRange(CustomTromboner.GetBonerNames);
dropdown = settingPage.AddDropdown("BonerDropdown", Instance.option.BonerName, list.ToArray());
settingPage.AddButton("Reload Tromboners", (Action)delegate
{
dropdown.dropdown.ClearOptions();
dropdown.AddOptions(new string[1] { "None" });
CustomTromboner.LoadAssetBundles();
TootTallyNotifManager.DisplayNotif("Reloaded tromboners.", 6f);
});
Plugin.TryAddThunderstoreIconToPageButton(((BaseUnityPlugin)Instance).Info.Location, Name, settingPage);
_harmony.PatchAll(typeof(CustomTromboner.CustomTrombonerPatches));
LogInfo("Module loaded!");
}
public void UnloadModule()
{
_harmony.UnpatchSelf();
settingPage.Remove();
LogInfo("Module unloaded!");
}
}
public static class TrombonerFileHelper
{
public const string BONER_FILE_EXT = ".boner";
public static FileInfo[] GetFilesFromDirectory(string directory)
{
return GetOrCreateDirectory(directory).GetFiles();
}
public static DirectoryInfo GetOrCreateDirectory(string directory)
{
if (!Directory.Exists(directory))
{
return Directory.CreateDirectory(directory);
}
return new DirectoryInfo(directory);
}
public static List<FileInfo> GetAllBonerFilesFromDirectory(string diretory)
{
return (from x in GetFilesFromDirectory(diretory)
where x.FullName.Contains(".boner")
select x).ToList();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "TootTallyCustomTromboner";
public const string PLUGIN_NAME = "TootTallyCustomTromboner";
public const string PLUGIN_VERSION = "1.1.2";
}
}