using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BaboonAPI.Hooks.Initializer;
using BaboonAPI.Hooks.Tracks;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TootTallyCore;
using TootTallyCore.APIServices;
using TootTallyCore.Graphics;
using TootTallyCore.Utils.Helpers;
using TootTallyCore.Utils.TootTallyGlobals;
using TootTallyCore.Utils.TootTallyModules;
using TootTallyDiffCalcLibs;
using TootTallyGameModifiers;
using TootTallySettings;
using TrombLoader.CustomTracks;
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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("TootTallyTTCounter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("TT Counter display while you are playing")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("TootTallyTTCounter")]
[assembly: AssemblyTitle("TootTallyTTCounter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 TootTallyTTCounter
{
[BepInPlugin("TootTallyTTCounter", "TootTallyTTCounter", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin, ITootTallyModule
{
public static class TTCounterPatches
{
private static SongDataFromDB _songData;
private static TTCounter _ttCounter;
[HarmonyPatch(typeof(GameController), "Start")]
[HarmonyPostfix]
public static void OnGameControllerStartPostfix(GameController __instance)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
TMP_Text val = GameObjectFactory.CreateSingleText(((Component)__instance.ui_score_shadow).transform.parent.parent, "TTCounter", "0.00tt", Color.white, (TextFont)0);
_ttCounter = ((Component)val).gameObject.AddComponent<TTCounter>();
_ttCounter.levelData = __instance.leveldata;
if (_songData != null && _songData.track_ref == GlobalVariables.chosen_track_data.trackref)
{
_ttCounter.SetChartData(DiffCalcGlobals.selectedChart, _songData);
return;
}
GetSongDataFromServer(delegate(SongDataFromDB songData)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
_songData = songData;
if (DiffCalcGlobals.selectedChart.trackRef != "")
{
_ttCounter.SetChartData(DiffCalcGlobals.selectedChart, _songData);
}
});
}
[HarmonyPatch(typeof(LevelSelectController), "clickPlay")]
[HarmonyPostfix]
public static void TryPreloadSongData()
{
if (_songData == null || !(_songData.track_ref == GlobalVariables.chosen_track_data.trackref))
{
GetSongDataFromServer(delegate(SongDataFromDB songData)
{
_songData = songData;
});
}
}
[HarmonyPatch(typeof(GameController), "getScoreAverage")]
[HarmonyPostfix]
public static void OnScoreAveragePostfix(int ___totalscore, int ___scores_A, int ___scores_B, int ___currentnoteindex)
{
_ttCounter?.OnScoreChanged(___totalscore, ___scores_A + ___scores_B, ___currentnoteindex);
}
public static void GetSongDataFromServer(Action<SongDataFromDB> callback)
{
TromboneTrack val = TrackLookup.lookup(GlobalVariables.chosen_track_data.trackref);
string songHash = SongDataHelper.GetSongHash(val);
((MonoBehaviour)Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetHashInDB(songHash, val is CustomTrack, (Action<int>)delegate(int songHashInDB)
{
if (songHashInDB == 0)
{
callback(null);
}
((MonoBehaviour)Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetSongDataFromDB(songHashInDB, callback));
}));
}
}
public static Plugin Instance;
private Harmony _harmony;
public ConfigEntry<bool> ModuleConfigEnabled { get; set; }
public bool IsConfigInitialized { get; set; }
public string Name
{
get
{
return "TTCounter";
}
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", "TTCounter", true, "Enables TT Counter display while you are playing");
TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
Plugin.Instance.AddModuleToSettingPage((ITootTallyModule)(object)this);
}
public void LoadModule()
{
_harmony.PatchAll(typeof(TTCounterPatches));
LogInfo("Module loaded!");
}
public void UnloadModule()
{
_harmony.UnpatchSelf();
LogInfo("Module unloaded!");
}
}
public class TTCounter : MonoBehaviour
{
private TMP_Text _counterText;
private bool _isSongRated;
public List<float[]> levelData;
private Chart _chart;
public string[] modifiers;
private float _targetTT;
private float _currentTT;
private float _updateTimer;
private float _timeSinceLastScore;
private readonly float CHAR_SPACING = 7.2f;
private void Awake()
{
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
_isSongRated = false;
modifiers = null;
_targetTT = 0f;
_currentTT = 0f;
_counterText = ((Component)this).gameObject.GetComponent<TMP_Text>();
_counterText.enableWordWrapping = false;
_counterText.fontSize = 12f;
_counterText.alignment = (TextAlignmentOptions)514;
RectTransform component = ((Component)_counterText).GetComponent<RectTransform>();
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(0.5f, 0.92f);
component.anchorMax = val;
component.anchorMin = val;
component.sizeDelta = Vector2.zero;
}
private void Update()
{
_updateTimer += Time.unscaledDeltaTime;
_timeSinceLastScore += Time.unscaledDeltaTime;
if (_updateTimer > 0.06f && _currentTT != _targetTT)
{
_currentTT = EaseTTValue(_currentTT, _targetTT - _currentTT, _timeSinceLastScore, 2f);
if (_currentTT < 0f || _targetTT < 0f)
{
_currentTT = (_targetTT = 0f);
}
UpdateTTText();
_updateTimer = 0f;
}
}
public void OnScoreChanged(int totalScore, int hitCount, int noteIndex)
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
if (!(_chart.trackRef == "") && _chart.indexToMaxScoreDict != null && _chart.indexToMaxScoreDict.ContainsKey(noteIndex))
{
float num = (float)totalScore / (float)_chart.indexToMaxScoreDict[noteIndex];
_targetTT = Utils.CalculateScoreTT(_chart, TootTallyGlobalVariables.gameSpeedMultiplier, hitCount, _chart.indexToNoteCountDict[noteIndex], num, modifiers);
_timeSinceLastScore = 0f;
}
}
public void SetChartData(Chart chart, SongDataFromDB songData = null)
{
//IL_0001: 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_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
if (!(chart.trackRef == ""))
{
_isSongRated = songData?.is_rated ?? false;
_chart = chart;
string modifiersString = GameModifierManager.GetModifiersString();
if (modifiersString != "None")
{
modifiers = modifiersString.Split(new char[1] { ',' });
}
_targetTT = (_currentTT = Utils.CalculateScoreTT(chart, TootTallyGlobalVariables.gameSpeedMultiplier, 1, 1, 1f, modifiers));
UpdateTTText();
}
}
private void UpdateTTText()
{
int num = (int)_currentTT;
string arg = (_currentTT - (float)(int)_currentTT).ToString("0.00").Substring(2);
_counterText.text = $"<mspace=mspace={CHAR_SPACING}>{num}</mspace>" + "." + $"<mspace=mspace={CHAR_SPACING}>{arg}</mspace>tt" + (_isSongRated ? "" : "(Unrated) ");
}
private float EaseTTValue(float currentTT, float diff, float timeSum, float duration)
{
return Mathf.Max(diff * (0f - Mathf.Pow(2f, -10f * timeSum / duration) + 1f) * 1024f / 1023f + currentTT, 0f);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "TootTallyTTCounter";
public const string PLUGIN_NAME = "TootTallyTTCounter";
public const string PLUGIN_VERSION = "1.1.1";
}
}