using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using Steamworks;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("LobbyHeartbeat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+51ea44a460d2f636e243b7dfa498f5415515567a")]
[assembly: AssemblyProduct("LobbyHeartbeat")]
[assembly: AssemblyTitle("LobbyHeartbeat")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 LobbyHeartbeat
{
[BepInPlugin("com.ontogether.lobbyheartbeat", "Heartbeat", "1.1.0")]
public class LobbyHeartbeatPlugin : BaseUnityPlugin
{
public const string PluginGuid = "com.ontogether.lobbyheartbeat";
public const string PluginName = "Heartbeat";
public const string PluginVersion = "1.1.0";
private static readonly string[] LobbyKeys = new string[6] { "Name", "focus", "mature", "chill", "break", "modded" };
private static float _heartbeatTimer;
private static bool _firstHeartbeat = true;
private ConfigEntry<bool> _enabled;
private ConfigEntry<float> _intervalMinutes;
private void Awake()
{
_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Steam", "LobbyHeartbeatEnabled", true, "Periodically update lobby data so Steam does not expire the listing.");
_intervalMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("Steam", "LobbyHeartbeatIntervalMinutes", 2f, "Minutes between lobby heartbeat updates. Use 1-2 for 12+ hour runs. Max ~10.");
_heartbeatTimer = float.MaxValue;
_firstHeartbeat = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)("Heartbeat v1.1.0 loaded (heartbeat " + (_enabled.Value ? "enabled" : "disabled") + ")"));
}
private void Update()
{
if (_enabled.Value)
{
float num = _intervalMinutes.Value * 60f;
_heartbeatTimer += Time.deltaTime;
if (_heartbeatTimer >= num)
{
_heartbeatTimer = 0f;
SendLobbyHeartbeat();
}
}
}
private void SendLobbyHeartbeat()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
try
{
MultiplayerManager i = MonoSingleton<MultiplayerManager>.I;
if ((Object)(object)i == (Object)null || !i.LobbyStatus)
{
return;
}
string lobbyCode = i.LobbyCode;
if (string.IsNullOrEmpty(lobbyCode))
{
return;
}
CSteamID val = default(CSteamID);
((CSteamID)(ref val))..ctor(ulong.Parse(lobbyCode));
string text = DateTime.UtcNow.Ticks.ToString();
SteamMatchmaking.SetLobbyData(val, "heartbeat", text);
string[] lobbyKeys = LobbyKeys;
foreach (string text2 in lobbyKeys)
{
string lobbyData = SteamMatchmaking.GetLobbyData(val, text2);
if (!string.IsNullOrEmpty(lobbyData))
{
SteamMatchmaking.SetLobbyData(val, text2, lobbyData);
}
}
if (_firstHeartbeat)
{
_firstHeartbeat = false;
((BaseUnityPlugin)this).Logger.LogInfo((object)"First lobby heartbeat sent (Steam listing kept alive)");
}
else
{
((BaseUnityPlugin)this).Logger.LogDebug((object)"Lobby heartbeat sent (Steam listing kept alive)");
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Lobby heartbeat failed: " + ex.GetType().Name + ": " + ex.Message));
}
}
}
}