using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 Newtonsoft.Json;
using TMPro;
using TootTallyCore;
using TootTallyCore.Utils.TootTallyModules;
using TootTallyCore.Utils.TootTallyNotifs;
using TootTallySettings;
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("TootTallyLocalOffset")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("TootTally's LocalOffset module")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("TootTallyLocalOffset")]
[assembly: AssemblyTitle("TootTallyLocalOffset")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 TootTallyLocalOffset
{
public static class FileHelper
{
private static readonly string FILE_PATH = Path.Combine(Paths.BepInExRootPath, "config", "TootTallyLocalOffsets.json");
public static Dictionary<string, int> LoadOffetFile()
{
Dictionary<string, int> dictionary;
if (!File.Exists(FILE_PATH))
{
dictionary = new Dictionary<string, int>();
SaveOffetFile(dictionary);
Plugin.LogInfo("Couldn't find offset file, creating new one!");
return dictionary;
}
try
{
dictionary = JsonConvert.DeserializeObject<Dictionary<string, int>>(File.ReadAllText(FILE_PATH));
}
catch (Exception ex)
{
Plugin.LogError("Couldn't parse local offset file: " + ex.Message);
File.Move(FILE_PATH, FILE_PATH + ".old");
dictionary = new Dictionary<string, int>();
}
return dictionary;
}
public static void SaveOffetFile(Dictionary<string, int> dict)
{
File.WriteAllText(FILE_PATH, JsonConvert.SerializeObject((object)dict));
}
}
public static class LocalOffsetPatches
{
private static float _saveToFileTimer;
private static Dictionary<string, int> _trackRefToOffsetDict = new Dictionary<string, int>();
[HarmonyPatch(typeof(GameController), "Start")]
[HarmonyPostfix]
public static void OnGameControllerStart(GameController __instance)
{
string chosen_track = GlobalVariables.chosen_track;
if (_trackRefToOffsetDict.TryGetValue(chosen_track, out var value) && value != 0)
{
Plugin.LogInfo($"Latency adjusted by local offset by {value}.");
__instance.latency_offset += (float)value * 0.001f;
}
}
[HarmonyPatch(typeof(GameController), "Update")]
[HarmonyPrefix]
public static void OnGameControllerUpdate(GameController __instance)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(Plugin.Instance.OffsetIncreaseKeybind.Value))
{
AddOffsetToDict(__instance, GlobalVariables.chosen_track, Plugin.Instance.OffsetIncrements.Value);
}
if (Input.GetKeyDown(Plugin.Instance.OffsetDecreaseKeybind.Value))
{
AddOffsetToDict(__instance, GlobalVariables.chosen_track, 0f - Plugin.Instance.OffsetIncrements.Value);
}
if (_saveToFileTimer > 0f)
{
_saveToFileTimer -= Time.fixedUnscaledDeltaTime;
if (!(_saveToFileTimer <= 0f))
{
}
}
}
public static void AddOffsetToDict(GameController __instance, string key, float value)
{
if (!_trackRefToOffsetDict.ContainsKey(key))
{
_trackRefToOffsetDict.Add(key, 0);
}
_trackRefToOffsetDict[key] += (int)value;
__instance.latency_offset += value * 0.001f;
TootTallyNotifManager.DisplayNotif($"New Local Offset: {_trackRefToOffsetDict[key]}ms", 6f);
FileHelper.SaveOffetFile(_trackRefToOffsetDict);
}
public static void LoadOffsetsFromFile()
{
_trackRefToOffsetDict = FileHelper.LoadOffetFile();
}
}
[BepInPlugin("TootTallyLocalOffset", "TootTallyLocalOffset", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin, ITootTallyModule
{
public static Plugin Instance;
private Harmony _harmony;
public static TootTallySettingPage settingPage;
public ConfigEntry<bool> ModuleConfigEnabled { get; set; }
public bool IsConfigInitialized { get; set; }
public string Name
{
get
{
return "TootTallyLocalOffset";
}
set
{
Name = value;
}
}
public ConfigEntry<KeyCode> OffsetIncreaseKeybind { get; set; }
public ConfigEntry<KeyCode> OffsetDecreaseKeybind { get; set; }
public ConfigEntry<float> OffsetIncrements { 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", "LocalOffets", true, "Allows offset per charts.");
TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
Plugin.Instance.AddModuleToSettingPage((ITootTallyModule)(object)this);
}
public void LoadModule()
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
string text = Path.Combine(Paths.BepInExRootPath, "config/");
OffsetIncreaseKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "OffsetIncreaseKeybind", (KeyCode)93, "Increase the local offset of the current chart");
OffsetDecreaseKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "OffsetDecreaseKeybind", (KeyCode)91, "Decrease the local offset of the current chart");
OffsetIncrements = ((BaseUnityPlugin)this).Config.Bind<float>("General", "OffsetIncrements", 1f, "Offset Increments per key presses.");
settingPage = TootTallySettingsManager.AddNewPage("Local Offset", "Local Offset", 40f, new Color(0f, 0f, 0f, 0f));
if (settingPage != null)
{
settingPage.AddLabel("Increase Offset Keybind", (FontStyles)0, (TextAlignmentOptions)4097);
settingPage.AddDropdown("Increase Offset Keybind", (ConfigEntryBase)(object)OffsetIncreaseKeybind);
settingPage.AddLabel("Decrease Offset Keybind", (FontStyles)0, (TextAlignmentOptions)4097);
settingPage.AddDropdown("Decrease Offset Keybind", (ConfigEntryBase)(object)OffsetDecreaseKeybind);
settingPage.AddSlider("Increments (ms)", 1f, 50f, OffsetIncrements, true);
}
Plugin.TryAddThunderstoreIconToPageButton(((BaseUnityPlugin)Instance).Info.Location, Name, settingPage);
LocalOffsetPatches.LoadOffsetsFromFile();
_harmony.PatchAll(typeof(LocalOffsetPatches));
LogInfo("Module loaded!");
}
public void UnloadModule()
{
_harmony.UnpatchSelf();
settingPage.Remove();
LogInfo("Module unloaded!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "TootTallyLocalOffset";
public const string PLUGIN_NAME = "TootTallyLocalOffset";
public const string PLUGIN_VERSION = "1.0.2";
}
}