Decompiled source of REPOJoinWithCode v1.1.1

REPOJoinWithCode.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using HarmonyLib;
using Steamworks;
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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace REPOJoinWithCode;

[HarmonyPatch(typeof(MenuPageMain), "ButtonEventJoinGame")]
public class MenuPatcher
{
	[HarmonyPrefix]
	public static bool Prefix()
	{
		string systemCopyBuffer = GUIUtility.systemCopyBuffer;
		if (!systemCopyBuffer.StartsWith("steam://"))
		{
			InvalidCode();
			return false;
		}
		StartJoin(systemCopyBuffer);
		return false;
	}

	private static void InvalidCode()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		MenuManager.instance.PagePopUp("Invalid Code", Color.red, "<size=20>Sorry, but you currently do not have a valid code in your clipboard.\nSimply copy the many codes shared on the Discord <color=#808080>(starts with 'steam://...')</color> and click join here.", "OK");
	}

	private static async void StartJoin(string clipboard)
	{
		if (!(await JoinLobbyFromURL(clipboard)))
		{
			InvalidCode();
		}
	}

	public static async Task<bool> JoinLobbyFromURL(string steamURL)
	{
		string[] parts = steamURL.Split('/');
		if (parts.Length < 6 || !parts[2].StartsWith("joinlobby"))
		{
			return false;
		}
		string lobbyIDStr = parts[4];
		if (!ulong.TryParse(lobbyIDStr, out var lobbyID))
		{
			Debug.LogError((object)"Invalid lobby ID format");
			return false;
		}
		SteamId steamLobbyID = new SteamId
		{
			Value = lobbyID
		};
		foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
		{
			player.OutroStartRPC();
		}
		Debug.Log((object)$"Joining lobby: {lobbyID}");
		await SteamMatchmaking.JoinLobbyAsync(steamLobbyID);
		typeof(RunManager).GetField("lobbyJoin", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(RunManager.instance, true);
		RunManager.instance.ChangeLevel(true, false, (ChangeLevelType)3);
		return true;
	}
}
[BepInPlugin("com.asigsegv.repoeasyjoin", "Easy Join", "1.0")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin instance;

	public const string VERSION = "1.0";

	public const string GUID = "com.asigsegv.repoeasyjoin";

	private void Awake()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		instance = this;
		Harmony val = new Harmony("com.asigsegv.repoeasyjoin");
		val.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Easy Join successfully awoken. Enjoy -ASIGSEGV");
	}
}