using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using YAPYAP;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("YAPYAP_ServerList")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("YAPYAP_ServerList")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fafcfe35-5a1d-4819-aebc-c1669943e8c0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace YAPYAP_ServerList;
[HarmonyPatch]
[BepInPlugin("com.github.qert2002.YAPYAP_ServerList", "YAPYAP_ServerList", "1.0")]
public class YAPYAP_ServerList : BaseUnityPlugin
{
public static YAPYAP_ServerList PluginInstance;
public static ManualLogSource Log;
public static Harmony HarmonyInstance;
public static GameObject MainGameObject;
public static GameObject LobbyListGameObject;
public static GameObject LobbyListGameObject_Content;
public static List<UIButton3D> all_buttons;
public static GameObject LobbyTemplate;
public static CallResult<LobbyMatchList_t> lobbyListCallResult;
public static bool OneTimeInit;
public static float LastCheckTime;
private void Awake()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
PluginInstance = this;
Log = ((BaseUnityPlugin)this).Logger;
all_buttons = new List<UIButton3D>();
HarmonyInstance = new Harmony("YAPYAP_ServerList");
HarmonyInstance.PatchAll();
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
}
private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
if (!OneTimeInit)
{
OneTimeInit = true;
if ((Object)(object)MainGameObject == (Object)null)
{
MainGameObject = new GameObject("YAPYAP_ServerList");
Object.DontDestroyOnLoad((Object)(object)MainGameObject);
Log.LogInfo((object)"Loaded!");
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(MenuController), "Initialise")]
public static void OV_MenuController_Initialise()
{
//IL_0259: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Expected O, but got Unknown
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_02f2: Expected O, but got Unknown
//IL_037b: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
//IL_0469: Unknown result type (might be due to invalid IL or missing references)
//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_0558: Unknown result type (might be due to invalid IL or missing references)
//IL_055f: Expected O, but got Unknown
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Expected O, but got Unknown
lobbyListCallResult = CallResult<LobbyMatchList_t>.Create((APIDispatchDelegate<LobbyMatchList_t>)OnLobbyListReceived);
GameObject val = GameObject.Find("3DButtonsContainer/");
if ((Object)(object)val != (Object)null)
{
all_buttons.Clear();
if ((Object)(object)val.GetComponent<Animator>() != (Object)null)
{
((Behaviour)val.GetComponent<Animator>()).enabled = false;
}
GameObject val2 = Object.Instantiate<GameObject>(GameObject.Find("3DButtonsContainer/Play_Button3D"));
((Object)val2).name = "LobbyList_Button3D";
val2.transform.parent = val.transform;
val2.transform.SetSiblingIndex(1);
((Behaviour)((Component)val2.transform.Find("Root/Text")).GetComponent<LocalisedTMP>()).enabled = false;
((TMP_Text)((Component)val2.transform.Find("Root/Text")).GetComponent<TextMeshPro>()).text = "LOBBY LIST";
val2.GetComponent<UIButton3D>().onClick.AddListener(new UnityAction(OnLobbyListBtn_Open));
VerticalObjectSpacer component = val.GetComponent<VerticalObjectSpacer>();
if ((Object)(object)component != (Object)null)
{
typeof(VerticalObjectSpacer).GetMethod("DistributeObjects", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(component, new object[0]);
}
foreach (Transform item in val.transform)
{
Transform val3 = item;
all_buttons.Add(((Component)val3).GetComponent<UIButton3D>());
}
}
GameObject val4 = GameObject.Find("Canvas_Menu/UISettings/CreditsWindow");
if (!((Object)(object)val4 != (Object)null))
{
return;
}
UICredits component2 = val4.GetComponent<UICredits>();
LobbyListGameObject = Object.Instantiate<GameObject>(val4, val4.transform.parent);
((Object)LobbyListGameObject).name = "LobbyListWindow";
Object.Destroy((Object)(object)LobbyListGameObject.GetComponent<UICredits>());
Object.Destroy((Object)(object)((Component)LobbyListGameObject.transform.Find("TitleElement/TitleText")).GetComponent<LocalisedTMP>());
((TMP_Text)((Component)LobbyListGameObject.transform.Find("TitleElement/TitleText")).GetComponent<TextMeshProUGUI>()).text = "LOBBIES";
Transform val5 = LobbyListGameObject.transform.Find("Content/ButtonContainer/Close");
((UnityEventBase)((Component)val5).GetComponent<Button>().onClick).RemoveAllListeners();
((UnityEvent)((Component)val5).GetComponent<Button>().onClick).AddListener(new UnityAction(OnLobbyListBtn_Close));
Transform val6 = Object.Instantiate<Transform>(val5, ((Component)val5).transform.parent);
((Object)val6).name = "RefreshLobbiesBtn";
Object.Destroy((Object)(object)((Component)((Component)val6).transform.Find("Text")).GetComponent<LocalisedTMP>());
((TMP_Text)((Component)((Component)val6).transform.Find("Text")).GetComponent<TextMeshProUGUI>()).text = "Refresh";
((UnityEventBase)((Component)val6).GetComponent<Button>().onClick).RemoveAllListeners();
((UnityEvent)((Component)val6).GetComponent<Button>().onClick).AddListener(new UnityAction(OnLobbyListBtn_Refresh));
LobbyListGameObject_Content = ((Component)LobbyListGameObject.transform.Find("Content/Scroll View/Viewport/Content")).gameObject;
LobbyTemplate = Object.Instantiate<GameObject>(((Component)LobbyListGameObject_Content.transform.Find("UICreditEntry")).gameObject, LobbyListGameObject_Content.transform);
((Object)LobbyTemplate).name = "LobbyTemplate";
Object.Destroy((Object)(object)LobbyTemplate.GetComponent<UICreditsEntry>());
Transform val7 = LobbyTemplate.transform.Find("Social");
Vector3 localPosition = ((Component)val7).transform.localPosition;
Transform val8 = Object.Instantiate<Transform>(val5, ((Component)val7).transform.parent);
((Object)val8).name = "JoinBtn";
Object.DestroyImmediate((Object)(object)((Component)((Component)val8).transform.Find("Text")).GetComponent<LocalisedTMP>());
val8.localPosition = localPosition;
((TMP_Text)((Component)((Component)val8).transform.Find("Text")).GetComponent<TextMeshProUGUI>()).text = "Join";
((UnityEventBase)((Component)val8).GetComponent<Button>().onClick).RemoveAllListeners();
((MaskableGraphic)((Component)val8).GetComponent<Image>()).maskable = true;
Object.Destroy((Object)(object)((Component)val7).gameObject);
((Object)((Component)LobbyTemplate.transform.Find("Role")).gameObject).name = "Players";
((TMP_Text)((Component)LobbyTemplate.transform.Find("Name")).GetComponent<TextMeshProUGUI>()).margin = new Vector4(6f, 0f, 0f, 0f);
LobbyTemplate.AddComponent<HorizontalLayoutGroup>();
Image val9 = LobbyTemplate.AddComponent<Image>();
Image component3 = ((Component)LobbyTemplate.transform.Find("Background")).GetComponent<Image>();
val9.sprite = component3.sprite;
((Graphic)val9).color = ((Graphic)component3).color;
((Graphic)val9).material = ((Graphic)component3).material;
val9.type = component3.type;
val9.fillMethod = component3.fillMethod;
val9.fillOrigin = component3.fillOrigin;
val9.fillAmount = component3.fillAmount;
val9.fillClockwise = component3.fillClockwise;
Object.Destroy((Object)(object)((Component)LobbyTemplate.transform.Find("Background")).gameObject);
foreach (Transform item2 in LobbyListGameObject_Content.transform)
{
Transform val10 = item2;
if (((Object)val10).name != "LobbyTemplate")
{
Object.Destroy((Object)(object)((Component)val10).gameObject);
}
}
Transform val11 = LobbyListGameObject.transform.Find("Content/Scroll View");
Object.DestroyImmediate((Object)(object)((Component)val11).gameObject.GetComponent<CustomScrollRect>());
ScrollRect val12 = ((Component)val11).gameObject.AddComponent<ScrollRect>();
val12.scrollSensitivity = 10f;
val12.movementType = (MovementType)2;
val12.content = ((Component)LobbyListGameObject_Content.transform).GetComponent<RectTransform>();
val12.viewport = ((Component)LobbyListGameObject.transform.Find("Content/Scroll View/Viewport")).GetComponent<RectTransform>();
val12.verticalScrollbar = ((Component)LobbyListGameObject.transform.Find("Content/Scroll View/Scrollbar Vertical")).GetComponent<Scrollbar>();
val12.verticalScrollbarVisibility = (ScrollbarVisibility)1;
Object.DestroyImmediate((Object)(object)((Component)((Component)val11).transform.Find("Scrollbar Horizontal")).gameObject);
}
public static void OnLobbyListBtn_Open()
{
foreach (UIButton3D all_button in all_buttons)
{
all_button.ToggleInteractable(false);
}
ClearLobbyList();
LobbyListGameObject.SetActive(true);
}
public static void OnLobbyListBtn_Close()
{
foreach (UIButton3D all_button in all_buttons)
{
all_button.ToggleInteractable(true);
}
LobbyListGameObject.SetActive(false);
}
public static void OnLobbyListBtn_Refresh()
{
//IL_0040: 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_004b: Unknown result type (might be due to invalid IL or missing references)
ClearLobbyList();
Log.LogInfo((object)"Requested server list, please wait...");
if (lobbyListCallResult.IsActive())
{
lobbyListCallResult.Cancel();
}
SteamMatchmaking.AddRequestLobbyListFilterSlotsAvailable(1);
SteamMatchmaking.AddRequestLobbyListDistanceFilter((ELobbyDistanceFilter)3);
SteamAPICall_t val = SteamMatchmaking.RequestLobbyList();
lobbyListCallResult.Set(val, (APIDispatchDelegate<LobbyMatchList_t>)null);
}
public static void ClearLobbyList()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
foreach (Transform item in LobbyListGameObject_Content.transform)
{
Transform val = item;
if (((Object)val).name != "LobbyTemplate")
{
Object.Destroy((Object)(object)((Component)val).gameObject);
}
}
}
public static void AddLobby(string name, string players, ulong steamid)
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
GameObject val = Object.Instantiate<GameObject>(LobbyTemplate, LobbyListGameObject_Content.transform);
((Object)val).name = "Lobby";
((TMP_Text)((Component)val.transform.Find("Name")).GetComponent<TextMeshProUGUI>()).text = name;
((TMP_Text)((Component)val.transform.Find("Players")).GetComponent<TextMeshProUGUI>()).text = players;
((UnityEvent)((Component)val.transform.Find("JoinBtn")).GetComponent<Button>().onClick).AddListener((UnityAction)delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
SteamMatchmaking.JoinLobby(new CSteamID(steamid));
});
val.SetActive(true);
}
public static void OnLobbyListReceived(LobbyMatchList_t result, bool failure)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
if (failure)
{
Debug.LogError((object)"Failed to get lobby list");
return;
}
Log.LogInfo((object)$"We get {result.m_nLobbiesMatching} lobbies!");
for (int i = 0; i < result.m_nLobbiesMatching; i++)
{
CSteamID lobbyByIndex = SteamMatchmaking.GetLobbyByIndex(i);
string lobbyData = SteamMatchmaking.GetLobbyData(lobbyByIndex, "name");
int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(lobbyByIndex);
int lobbyMemberLimit = SteamMatchmaking.GetLobbyMemberLimit(lobbyByIndex);
if (numLobbyMembers != 0)
{
AddLobby(lobbyData, $"{numLobbyMembers}/{lobbyMemberLimit}", lobbyByIndex.m_SteamID);
}
}
}
public void Update()
{
if (Time.realtimeSinceStartup - LastCheckTime >= 1f)
{
LastCheckTime = Time.realtimeSinceStartup;
}
}
}