using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LCSymphony.Patches;
using Steamworks;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LCSymphony")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCSymphony")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("047A9A10-3A21-461E-A7A5-DD6CA798B0A3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCSymphony
{
public static class ConfigSettings
{
public static ConfigEntry<bool> PingEnabled { get; set; }
public static ConfigEntry<string> LaunchOption { get; set; }
public static ConfigEntry<bool> SkipTerminalBoot { get; set; }
public static void Init()
{
PingEnabled = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Ping Management", "PingEnabled", true, "Enable or disable the ping display in the top right corner.");
LaunchOption = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("Launch Options", "LaunchOption", "online", "Choose between launching into online mode, lan mode, or normal startup. Online will launch the game directly to online mode, lan will launch the game directly to lan mode, and normal will launch the game normally. Valid options are: online, lan, normal.");
SkipTerminalBoot = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Launch Options", "SkipTerminalBoot", true, "Skip the terminal boot screen.");
}
}
public class PingManager : MonoBehaviour
{
private Coroutine _coroutine;
public int Ping { get; private set; }
private void Start()
{
if (ConfigSettings.PingEnabled.Value)
{
_coroutine = ((MonoBehaviour)this).StartCoroutine(UpdatePingData());
}
}
private void OnDestroy()
{
((MonoBehaviour)this).StopCoroutine(_coroutine);
}
private IEnumerator UpdatePingData()
{
while ((Object)(object)StartOfRound.Instance == (Object)null)
{
yield return (object)new WaitForSeconds(3f);
}
while (true)
{
if (SteamNetworkingUtils.LocalPingLocation.HasValue && SteamNetworkingUtils.LocalPingLocation.HasValue)
{
Ping = SteamNetworkingUtils.EstimatePingTo(SteamNetworkingUtils.LocalPingLocation.Value);
yield return (object)new WaitForSeconds(0.5f);
}
else
{
Plugin.Log("Could not update ping data. Retrying in 10 seconds.");
yield return (object)new WaitForSeconds(10f);
}
}
}
}
[BepInPlugin("dev.alexanderdiaz.lcsymphony", "LC Symphony", "1.3.0")]
public class Plugin : BaseUnityPlugin
{
private const string ModGuid = "dev.alexanderdiaz.lcsymphony";
private const string ModName = "LC Symphony";
private const string ModVersion = "1.3.0";
private readonly Harmony _harmony = new Harmony("dev.alexanderdiaz.lcsymphony");
public static Plugin Instance;
public static PingManager PingManager;
public void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
ConfigSettings.Init();
_harmony.PatchAll(typeof(SkipToStartPatch));
if (ConfigSettings.PingEnabled.Value && ConfigSettings.LaunchOption.Value != "lan")
{
_harmony.PatchAll(typeof(HudManagerPatch));
}
InitPingManager();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LC Symphony-1.3.0 loaded!");
}
private void InitPingManager()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("PingManager");
Object.DontDestroyOnLoad((Object)val);
((Object)val).hideFlags = (HideFlags)61;
val.AddComponent<PingManager>();
PingManager = val.GetComponent<PingManager>();
}
public static void Log(string message)
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
}
}
public class PluginInfo
{
public const string PLUGIN_GUID = "dev.alexanderdiaz.lcsymphony";
public const string PLUGIN_NAME = "LC Symphony";
public const string PLUGIN_VERSION = "1.3.0";
}
}
namespace LCSymphony.Patches
{
[HarmonyPatch(typeof(HUDManager))]
internal class HudManagerPatch
{
private static TextMeshProUGUI _displayText;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void PatchHudManagerStart(ref HUDManager __instance)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: 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_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("PingManagerDisplay");
val.AddComponent<RectTransform>();
TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
RectTransform rectTransform = ((TMP_Text)obj).rectTransform;
((Transform)rectTransform).SetParent(((TMP_Text)__instance.debugText).transform.parent.parent.parent, false);
((Transform)rectTransform).parent = ((Transform)((TMP_Text)__instance.debugText).rectTransform).parent.parent.parent;
rectTransform.anchorMin = new Vector2(1f, 1f);
rectTransform.anchorMax = new Vector2(1f, 1f);
rectTransform.pivot = new Vector2(1f, 1f);
rectTransform.sizeDelta = new Vector2(100f, 100f);
rectTransform.anchoredPosition = new Vector2(50f, -1f);
((TMP_Text)obj).font = ((TMP_Text)__instance.controlTipLines[0]).font;
((TMP_Text)obj).fontSize = 7f;
((TMP_Text)obj).text = $"Ping: {Plugin.PingManager.Ping}ms";
((TMP_Text)obj).overflowMode = (TextOverflowModes)0;
((Behaviour)obj).enabled = true;
_displayText = obj;
Plugin.Log("PingManagerDisplay component added to Canvas.");
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void PatchHudManagerUpdate(ref HUDManager __instance)
{
if (((NetworkBehaviour)__instance).NetworkManager.IsHost)
{
((TMP_Text)_displayText).text = "Ping: Host";
}
else
{
((TMP_Text)_displayText).text = $"Ping: {Plugin.PingManager.Ping}ms";
}
}
}
internal class SkipToStartPatch
{
[HarmonyPatch(typeof(PreInitSceneScript), "SkipToFinalSetting")]
[HarmonyPostfix]
internal static void SetLaunchModePatch(PreInitSceneScript __instance, ref bool ___choseLaunchOption)
{
if (!(ConfigSettings.LaunchOption.Value == "normal"))
{
Plugin.Log("Setting chosen quick-launch option.");
GameObject[] launchSettingsPanels = __instance.LaunchSettingsPanels;
for (int i = 0; i < launchSettingsPanels.Length; i++)
{
launchSettingsPanels[i].gameObject.SetActive(false);
}
__instance.currentLaunchSettingPanel = 0;
((TMP_Text)__instance.headerText).text = "";
__instance.continueButton.gameObject.SetActive(false);
___choseLaunchOption = true;
bool num = ConfigSettings.LaunchOption.Value == "online";
Plugin.Log("Launching into " + ConfigSettings.LaunchOption.Value + " mode.");
SceneManager.LoadScene(num ? "InitScene" : "InitSceneLANMode");
}
}
[HarmonyPatch(typeof(InitializeGame), "Awake")]
[HarmonyPostfix]
private static void SkipTerminalBootPatch(ref InitializeGame __instance)
{
Plugin.Log("Skipping boot-up screen.");
if (ConfigSettings.SkipTerminalBoot.Value)
{
__instance.runBootUpScreen = false;
}
}
}
}