Decompiled source of Heartbeat v1.0.0

BepInEx\plugins\Heartbeat\LobbyHeartbeat.dll

Decompiled 21 hours ago
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.0.0")]
	public class LobbyHeartbeatPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.ontogether.lobbyheartbeat";

		public const string PluginName = "Heartbeat";

		public const string PluginVersion = "1.0.0";

		private static float _heartbeatTimer;

		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 (fixes ghost lobby / can't join after long uptime).");
			_intervalMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("Steam", "LobbyHeartbeatIntervalMinutes", 5f, "Minutes between lobby heartbeat updates (keep under ~10 to avoid Steam timeout).");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Heartbeat v1.0.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_0033: 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)
				{
					string lobbyCode = i.LobbyCode;
					if (!string.IsNullOrEmpty(lobbyCode))
					{
						CSteamID val = new CSteamID(ulong.Parse(lobbyCode));
						string text = DateTime.UtcNow.Ticks.ToString();
						SteamMatchmaking.SetLobbyData(val, "heartbeat", text);
						((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));
			}
		}
	}
}