Decompiled source of LinkInvite v0.0.1

LinkInvite.dll

Decompiled 2 days ago
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 Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LinkInvite")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LinkInvite")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5627cf16-7c91-4edc-9c68-3cba84f83840")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.peak.linkinvite", "LinkInvite", "1.0.7")]
public sealed class LinkInvite : BaseUnityPlugin
{
	private const uint PeakAppId = 3527290u;

	private Callback<LobbyCreated_t> lobbyCreatedCallback;

	private Callback<LobbyEnter_t> lobbyEnterCallback;

	private CSteamID currentLobbyId = CSteamID.Nil;

	private ConfigEntry<Key> copyInviteKey;

	private const string LogColor = "#00FF00";

	private const float LogDuration = 8f;

	private string currentDisplayedPlainText = "";

	private string currentDisplayedColoredText = "";

	private float nativeLogExpireTime = 0f;

	private Coroutine nativeLogCoroutine;

	private void Awake()
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		copyInviteKey = ((BaseUnityPlugin)this).Config.Bind<Key>("General", "Copy Invite Link Key", (Key)99, "현재 PEAK Steam Lobby 참가 링크를 클립보드에 복사하는 단축키입니다.");
		lobbyCreatedCallback = Callback<LobbyCreated_t>.Create((DispatchDelegate<LobbyCreated_t>)OnLobbyCreated);
		lobbyEnterCallback = Callback<LobbyEnter_t>.Create((DispatchDelegate<LobbyEnter_t>)OnLobbyEnter);
		Debug.Log((object)"[LinkInvite] v1.0.7 loaded.");
		Debug.Log((object)("[LinkInvite] Copy invite key: " + ((object)copyInviteKey.Value/*cast due to .constrained prefix*/).ToString()));
	}

	private void Update()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		if (Keyboard.current != null)
		{
			Key value = copyInviteKey.Value;
			if ((int)value != 0 && ((ButtonControl)Keyboard.current[value]).wasPressedThisFrame)
			{
				CopyInviteLink();
			}
		}
	}

	private void OnLobbyCreated(LobbyCreated_t callback)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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)
		if ((int)callback.m_eResult != 1)
		{
			Debug.LogError((object)"[LinkInvite] Steam lobby creation failed.");
			return;
		}
		currentLobbyId = new CSteamID(callback.m_ulSteamIDLobby);
		Debug.Log((object)("[LinkInvite] Lobby created: " + currentLobbyId.m_SteamID));
	}

	private void OnLobbyEnter(LobbyEnter_t callback)
	{
		//IL_0001: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if (callback.m_EChatRoomEnterResponse != 1)
		{
			Debug.LogError((object)"[LinkInvite] Failed to enter Steam lobby.");
			currentLobbyId = CSteamID.Nil;
		}
		else
		{
			currentLobbyId = new CSteamID(callback.m_ulSteamIDLobby);
			Debug.Log((object)("[LinkInvite] Entered lobby: " + currentLobbyId.m_SteamID));
		}
	}

	private void CopyInviteLink()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if (currentLobbyId.m_SteamID == 0)
		{
			Debug.LogError((object)"[LinkInvite] Current Steam lobby ID is not available.");
			return;
		}
		if (!IsLocalPlayerInLobby(currentLobbyId))
		{
			Debug.LogError((object)"[LinkInvite] Local player is not currently in this lobby.");
			currentLobbyId = CSteamID.Nil;
			return;
		}
		CSteamID lobbyOwner = SteamMatchmaking.GetLobbyOwner(currentLobbyId);
		if (lobbyOwner.m_SteamID == 0)
		{
			Debug.LogError((object)"[LinkInvite] Could not get lobby owner Steam ID.");
			return;
		}
		string text = (GUIUtility.systemCopyBuffer = "steam://joinlobby/" + 3527290u + "/" + currentLobbyId.m_SteamID + "/" + lobbyOwner.m_SteamID);
		ShowNativeGameLog();
		Debug.Log((object)"[LinkInvite] Invite link copied.");
		Debug.Log((object)("[LinkInvite] Lobby ID: " + currentLobbyId.m_SteamID));
		Debug.Log((object)("[LinkInvite] Lobby Owner: " + lobbyOwner.m_SteamID));
		Debug.Log((object)("[LinkInvite] Link: " + text));
	}

	private bool IsLocalPlayerInLobby(CSteamID lobbyId)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		CSteamID steamID = SteamUser.GetSteamID();
		int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(lobbyId);
		for (int i = 0; i < numLobbyMembers; i++)
		{
			CSteamID lobbyMemberByIndex = SteamMatchmaking.GetLobbyMemberByIndex(lobbyId, i);
			if (lobbyMemberByIndex == steamID)
			{
				return true;
			}
		}
		return false;
	}

	private string GetLocalizedCopyMessage()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected I4, but got Unknown
		Language cURRENT_LANGUAGE = LocalizedText.CURRENT_LANGUAGE;
		Language val = cURRENT_LANGUAGE;
		return (int)val switch
		{
			0 => "Invite link copied.", 
			1 => "Lien d'invitation copié.", 
			2 => "Link di invito copiato.", 
			3 => "Einladungslink kopiert.", 
			4 => "Enlace de invitación copiado.", 
			5 => "Enlace de invitación copiado.", 
			6 => "Link de convite copiado.", 
			7 => "Ссылка-приглашение скопирована.", 
			8 => "Посилання-запрошення скопійовано.", 
			9 => "邀请链接已复制。", 
			10 => "邀請連結已複製。", 
			11 => "招待リンクをコピーしました。", 
			12 => "링크가 복사되었습니다.", 
			13 => "Link z zaproszeniem został skopiowany.", 
			14 => "Davet bağlantısı kopyalandı.", 
			_ => "Invite link copied.", 
		};
	}

	private void ShowNativeGameLog()
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		PlayerConnectionLog val = Object.FindFirstObjectByType<PlayerConnectionLog>();
		if ((Object)(object)val == (Object)null)
		{
			Debug.LogWarning((object)"[LinkInvite] PlayerConnectionLog was not found.");
			return;
		}
		if ((Object)(object)val.text == (Object)null)
		{
			Debug.LogWarning((object)"[LinkInvite] PlayerConnectionLog text was not found.");
			return;
		}
		string localizedCopyMessage = GetLocalizedCopyMessage();
		string text = "<color=#00FF00>" + localizedCopyMessage + "</color>";
		RemoveCurrentLogMessage(val);
		currentDisplayedPlainText = localizedCopyMessage;
		currentDisplayedColoredText = text;
		TextMeshProUGUI text2 = val.text;
		((TMP_Text)text2).text = ((TMP_Text)text2).text + text + "\n";
		if (Object.op_Implicit((Object)(object)val.sfxJoin))
		{
			val.sfxJoin.Play(default(Vector3));
		}
		else
		{
			Debug.LogWarning((object)"[LinkInvite] PEAK join sound was not found.");
		}
		nativeLogExpireTime = Time.realtimeSinceStartup + 8f;
		if (nativeLogCoroutine == null)
		{
			nativeLogCoroutine = ((MonoBehaviour)this).StartCoroutine(NativeLogTimeoutRoutine());
		}
	}

	private void RemoveCurrentLogMessage(PlayerConnectionLog playerLog)
	{
		if (!((Object)(object)playerLog == (Object)null) && !((Object)(object)playerLog.text == (Object)null) && !string.IsNullOrEmpty(currentDisplayedColoredText))
		{
			string oldValue = currentDisplayedColoredText + "\n";
			((TMP_Text)playerLog.text).text = ((TMP_Text)playerLog.text).text.Replace(oldValue, "");
		}
	}

	private IEnumerator NativeLogTimeoutRoutine()
	{
		while (Time.realtimeSinceStartup < nativeLogExpireTime)
		{
			yield return null;
		}
		PlayerConnectionLog playerLog = Object.FindFirstObjectByType<PlayerConnectionLog>();
		if ((Object)(object)playerLog != (Object)null && (Object)(object)playerLog.text != (Object)null)
		{
			RemoveCurrentLogMessage(playerLog);
		}
		currentDisplayedPlainText = "";
		currentDisplayedColoredText = "";
		nativeLogCoroutine = null;
	}
}