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 TootTallySettings;
using TootTallySettings.TootTallySettingsObjects;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
[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("TootTallyCustomNote")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Custom Note module for TootTally")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TootTallyCustomNote")]
[assembly: AssemblyTitle("TootTallyCustomNote")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 TootTallyCustomNote
{
public static class CustomNote
{
private static Sprite _noteOriginalInTexture;
private static Sprite _noteOriginalOutTexture;
private static Sprite _noteStartOutTexture;
private static Sprite _noteEndOutTexture;
private static Sprite _noteStartInTexture;
private static Sprite _noteEndInTexture;
private static string _lastNoteName;
private static readonly Random _rdm = new Random();
public static void LoadNoteTexture(GameController __instance, string NoteName)
{
if (AreAllTexturesLoaded() && !ConfigNotesNameChanged())
{
return;
}
string text = Path.Combine(Paths.BepInExRootPath, Plugin.NOTES_FOLDER_PATH, NoteName);
((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)LoadNoteTexture(text + "/NoteStartOutline.png", delegate(Texture2D texture)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
_noteStartOutTexture = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), Vector2.one / 2f);
Plugin.LogInfo("NoteStartOutline Texture Loaded.");
if (AreAllTexturesLoaded() && (Object)(object)__instance != (Object)null)
{
OnAllTextureLoadedAfterConfigChange(__instance);
}
}));
((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)LoadNoteTexture(text + "/NoteEndOutline.png", delegate(Texture2D texture)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
_noteEndOutTexture = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), Vector2.one / 2f);
Plugin.LogInfo("NoteEndOutline Texture Loaded.");
if (AreAllTexturesLoaded() && (Object)(object)__instance != (Object)null)
{
OnAllTextureLoadedAfterConfigChange(__instance);
}
}));
((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)LoadNoteTexture(text + "/NoteStartInline.png", delegate(Texture2D texture)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
_noteStartInTexture = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), Vector2.one / 2f);
Plugin.LogInfo("NoteStartInline Texture Loaded.");
if (AreAllTexturesLoaded() && (Object)(object)__instance != (Object)null)
{
OnAllTextureLoadedAfterConfigChange(__instance);
}
}));
((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)LoadNoteTexture(text + "/NoteEndInline.png", delegate(Texture2D texture)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
_noteEndInTexture = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), Vector2.one / 2f);
Plugin.LogInfo("NoteEndInline Texture Loaded.");
if (AreAllTexturesLoaded() && (Object)(object)__instance != (Object)null)
{
OnAllTextureLoadedAfterConfigChange(__instance);
}
}));
}
public static void UnloadTextures()
{
Object.DestroyImmediate((Object)(object)_noteStartOutTexture);
Object.DestroyImmediate((Object)(object)_noteEndOutTexture);
Object.DestroyImmediate((Object)(object)_noteStartInTexture);
Object.DestroyImmediate((Object)(object)_noteEndInTexture);
Plugin.LogInfo("Custom Notes Textures Destroyed.");
}
public static void OnAllTextureLoadedAfterConfigChange(GameController __instance)
{
ApplyCustomTextureToNotes(__instance);
_lastNoteName = Plugin.Instance.NoteName.Value;
}
public static bool AreAllTexturesLoaded()
{
return (Object)(object)_noteStartOutTexture != (Object)null && (Object)(object)_noteEndOutTexture != (Object)null && (Object)(object)_noteStartInTexture != (Object)null && (Object)(object)_noteEndInTexture != (Object)null;
}
public static bool ConfigNotesNameChanged()
{
return Plugin.Instance.NoteName.Value != _lastNoteName;
}
public static IEnumerator<UnityWebRequestAsyncOperation> LoadNoteTexture(string filePath, Action<Texture2D> callback)
{
UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(filePath);
yield return webRequest.SendWebRequest();
if (!webRequest.isNetworkError && !webRequest.isHttpError)
{
callback(DownloadHandlerTexture.GetContent(webRequest));
}
else
{
Plugin.LogInfo("Custom Note does not exist or have the wrong format.");
}
}
public static void ResolvePresets(GameController __instance)
{
if ((!AreAllTexturesLoaded() || (Object)(object)__instance == (Object)null) && Plugin.Instance.NoteName.Value != "Default")
{
Plugin.LogInfo("[" + Plugin.Instance.NoteName.Value + "] preset loading...");
LoadNoteTexture(__instance, Plugin.Instance.NoteName.Value);
}
else if (Plugin.Instance.NoteName.Value != "Default")
{
ApplyCustomTextureToNotes(__instance);
}
else if ((Object)(object)__instance != (Object)null)
{
SetToOriginalTexture(__instance);
Plugin.LogInfo("[Default] preset selected. Not loading any Custom Notes.");
}
}
public static void ApplyCustomTextureToNotes(GameController __instance)
{
if (AreAllTexturesLoaded())
{
Plugin.LogInfo("Applying Custom Textures to notes.");
NoteDesigner component = __instance.singlenote.GetComponent<NoteDesigner>();
if ((Object)(object)_noteOriginalInTexture == (Object)null || (Object)(object)_noteOriginalOutTexture == (Object)null)
{
_noteOriginalInTexture = component.startdot.sprite;
_noteOriginalOutTexture = ((Component)__instance.singlenote.transform.Find("StartPoint")).GetComponent<Image>().sprite;
}
((Component)__instance.singlenote.transform.Find("StartPoint")).GetComponent<Image>().sprite = _noteStartOutTexture;
((Component)__instance.singlenote.transform.Find("EndPoint")).GetComponent<Image>().sprite = _noteEndOutTexture;
component.startdot.sprite = _noteStartInTexture;
component.enddot.sprite = _noteEndInTexture;
}
}
public static void SetToOriginalTexture(GameController __instance)
{
if (!((Object)(object)_noteOriginalInTexture == (Object)null) && !((Object)(object)_noteOriginalOutTexture == (Object)null))
{
NoteDesigner component = __instance.singlenote.GetComponent<NoteDesigner>();
((Component)__instance.singlenote.transform.Find("StartPoint")).GetComponent<Image>().sprite = _noteOriginalOutTexture;
Image component2 = ((Component)__instance.singlenote.transform.Find("EndPoint")).GetComponent<Image>();
Image startdot = component.startdot;
Sprite val = (component.enddot.sprite = _noteOriginalInTexture);
Sprite sprite = (startdot.sprite = val);
component2.sprite = sprite;
}
}
public static void ApplyColor(GameController __instance)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: 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)
Color value = Plugin.Instance.NoteColorStart.Value;
Color value2 = Plugin.Instance.NoteColorEnd.Value;
__instance.note_c_start = new float[3] { value.r, value.g, value.b };
__instance.note_c_end = new float[3] { value2.r, value2.g, value2.b };
}
public static void ApplyRandomColor(ref float col_r, ref float col_g, ref float col_b, ref float col_r2, ref float col_g2, ref float col_b2)
{
col_r = (float)_rdm.NextDouble();
col_g = (float)_rdm.NextDouble();
col_b = (float)_rdm.NextDouble();
col_r2 = (float)_rdm.NextDouble();
col_g2 = (float)_rdm.NextDouble();
col_b2 = (float)_rdm.NextDouble();
}
public static Color GetColorFromPosition(float pos)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
float num = 1f - (pos + 180f) / 360f;
return new Color(1f - num, num, Math.Abs(2f * num - 1f));
}
public static void ApplyNoteResize(GameController __instance)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: 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_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
RectTransform component = ((Component)__instance.singlenote.transform.Find("StartPoint")).GetComponent<RectTransform>();
RectTransform component2 = ((Component)__instance.singlenote.transform.Find("EndPoint")).GetComponent<RectTransform>();
component.sizeDelta = Plugin.Instance.NoteHeadSize.Value * Vector2.one * 40f;
component2.sizeDelta = Plugin.Instance.NoteHeadSize.Value * Vector2.one * 17f;
Vector2 pivot = (component2.pivot = Vector2.one / 2f);
component.pivot = pivot;
component.anchoredPosition = Vector2.zero;
((Component)__instance.singlenote.transform.Find("StartPoint/StartPointColor")).GetComponent<RectTransform>().sizeDelta = Plugin.Instance.NoteHeadSize.Value * Vector2.one * 16f;
((Component)__instance.singlenote.transform.Find("EndPoint/EndPointColor")).GetComponent<RectTransform>().sizeDelta = Plugin.Instance.NoteHeadSize.Value * Vector2.one * 10f;
((Component)__instance.singlenote.transform.Find("Line")).GetComponent<LineRenderer>().widthMultiplier = Plugin.Instance.NoteBodySize.Value * 7f;
((Component)__instance.singlenote.transform.Find("OutlineLine")).GetComponent<LineRenderer>().widthMultiplier = Plugin.Instance.NoteBodySize.Value * 12f;
}
public static void FixNoteEndPosition(GameController __instance)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
foreach (GameObject allnote in __instance.allnotes)
{
RectTransform component = ((Component)((Component)allnote.transform).transform.Find("EndPoint")).GetComponent<RectTransform>();
Vector2 anchorMin = (component.anchorMax = new Vector2(1f, 0.5f));
component.anchorMin = anchorMin;
component.pivot = new Vector2(0.34f, 0.5f);
}
}
}
[BepInPlugin("TootTallyCustomNote", "TootTallyCustomNote", "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, ITootTallyModule
{
public static class CustomNotePatches
{
[HarmonyPatch(typeof(HomeController), "tryToSaveSettings")]
[HarmonyPostfix]
public static void OnSettingsChange()
{
CustomNote.ResolvePresets(null);
}
[HarmonyPatch(typeof(HomeController), "Start")]
[HarmonyPostfix]
public static void OnHomeStartLoadTexture()
{
CustomNote.ResolvePresets(null);
}
[HarmonyPatch(typeof(GameController), "buildNotes")]
[HarmonyPrefix]
public static void PatchCustorTexture(GameController __instance)
{
CustomNote.ResolvePresets(__instance);
CustomNote.ApplyNoteResize(__instance);
if (Instance.OverwriteNoteColor.Value)
{
CustomNote.ApplyColor(__instance);
}
}
[HarmonyPatch(typeof(NoteDesigner), "setColorScheme")]
[HarmonyPrefix]
public static void PatchCursorColorRandom(ref float col_r, ref float col_g, ref float col_b, ref float col_r2, ref float col_g2, ref float col_b2)
{
if (Instance.RandomNoteColor.Value)
{
CustomNote.ApplyRandomColor(ref col_r, ref col_g, ref col_b, ref col_r2, ref col_g2, ref col_b2);
}
}
[HarmonyPatch(typeof(GameController), "buildNotes")]
[HarmonyPostfix]
public static void FixEndNotePosition(GameController __instance)
{
CustomNote.FixNoteEndPosition(__instance);
}
}
public static Plugin Instance;
private const string CONFIG_NAME = "CustomNote.cfg";
private const string NOTE_CONFIG_FIELD = "CustomNote";
public static string NOTES_FOLDER_PATH = "CustomNotes";
public const string DEFAULT_NOTENAME = "Default";
private Harmony _harmony;
public static TootTallySettingPage settingPage;
public ConfigEntry<bool> ModuleConfigEnabled { get; set; }
public bool IsConfigInitialized { get; set; }
public string Name
{
get
{
return "Custom Note";
}
set
{
Name = value;
}
}
public ConfigEntry<string> NoteName { get; set; }
public ConfigEntry<float> NoteHeadSize { get; set; }
public ConfigEntry<float> NoteBodySize { get; set; }
public ConfigEntry<bool> RandomNoteColor { get; set; }
public ConfigEntry<bool> OverwriteNoteColor { get; set; }
public ConfigEntry<Color> NoteColorStart { get; set; }
public ConfigEntry<Color> NoteColorEnd { get; set; }
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 Note", true, "Enable Custom Note Module");
TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
Plugin.Instance.AddModuleToSettingPage((ITootTallyModule)(object)this);
}
public void LoadModule()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
string text = Path.Combine(Paths.BepInExRootPath, "config/");
ConfigFile val = new ConfigFile(text + "CustomNote.cfg", true)
{
SaveOnConfigSet = true
};
NoteName = val.Bind<string>("CustomNote", "NoteName", "Default", (ConfigDescription)null);
NoteHeadSize = val.Bind<float>("CustomNote", "NoteHeadSize", 1f, "Size of the start and end note circles");
NoteBodySize = val.Bind<float>("CustomNote", "NoteBodySize", 1f, "Size of the note line");
RandomNoteColor = val.Bind<bool>("CustomNote", "RandomNoteColor", false, "Randomize all the colors of the notes");
OverwriteNoteColor = val.Bind<bool>("CustomNote", "OverwriteNoteColor", false, "Make the note color consistent");
NoteColorStart = val.Bind<Color>("CustomNote", "NoteColorStart", Color.white, (ConfigDescription)null);
NoteColorEnd = val.Bind<Color>("CustomNote", "NoteColorEnd", Color.black, (ConfigDescription)null);
string text2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location), "CustomNotes");
string text3 = Path.Combine(Paths.BepInExRootPath, "CustomNotes");
FileHelper.TryMigrateFolder(text2, text3, true);
settingPage = TootTallySettingsManager.AddNewPage("Custom Note", "Custom Note", 40f, new Color(0f, 0f, 0f, 0f));
CreateDropdownFromFolder(NOTES_FOLDER_PATH, NoteName, "Default");
TootTallySettingSlider headSlider = settingPage.AddSlider("NoteHeadSizeSlider", 0f, 5f, 250f, "Note Head Size", NoteHeadSize, false);
TootTallySettingSlider bodySlider = settingPage.AddSlider("NoteBodySizeSlider", 0f, 5f, 250f, "Note Body Size", NoteBodySize, false);
settingPage.AddButton("ResetSliders", new Vector2(160f, 80f), "Reset", (Action)delegate
{
headSlider.slider.value = 1f;
bodySlider.slider.value = 1f;
});
settingPage.AddToggle("RandomNoteColor", RandomNoteColor, (UnityAction<bool>)null);
settingPage.AddToggle("OverwriteNoteColor", OverwriteNoteColor, (UnityAction<bool>)OnToggleValueChange);
Plugin.TryAddThunderstoreIconToPageButton(((BaseUnityPlugin)Instance).Info.Location, Name, settingPage);
if (OverwriteNoteColor.Value)
{
OnToggleValueChange(value: true);
}
_harmony.PatchAll(typeof(CustomNotePatches));
LogInfo("Module loaded!");
}
public void UnloadModule()
{
_harmony.UnpatchSelf();
settingPage.Remove();
LogInfo("Module unloaded!");
}
public void CreateDropdownFromFolder(string folderName, ConfigEntry<string> config, string defaultValue)
{
List<string> folderNames = new List<string> { defaultValue };
string path = Path.Combine(Paths.BepInExRootPath, folderName);
if (Directory.Exists(path))
{
List<string> list = Directory.GetDirectories(path).ToList();
list.ForEach(delegate(string d)
{
if (!d.Contains("TEMPLATE"))
{
folderNames.Add(Path.GetFileNameWithoutExtension(d));
}
});
}
settingPage.AddLabel(folderName, folderName, 24f, (FontStyles)0, (TextAlignmentOptions)1025);
settingPage.AddDropdown(folderName + "Dropdown", config, folderNames.ToArray());
}
public void OnToggleValueChange(bool value)
{
if (value)
{
settingPage.AddLabel("Note Start Color", (FontStyles)0, (TextAlignmentOptions)4097);
settingPage.AddColorSliders("NoteStart", "Note Start Color", NoteColorStart);
settingPage.AddLabel("Note End Color", (FontStyles)0, (TextAlignmentOptions)4097);
settingPage.AddColorSliders("NoteEnd", "Note End Color", NoteColorEnd);
}
else
{
settingPage.RemoveSettingObjectFromList("Note Start Color");
settingPage.RemoveSettingObjectFromList("NoteStart");
settingPage.RemoveSettingObjectFromList("Note End Color");
settingPage.RemoveSettingObjectFromList("NoteEnd");
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "TootTallyCustomNote";
public const string PLUGIN_NAME = "TootTallyCustomNote";
public const string PLUGIN_VERSION = "1.0.0";
}
}