using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.UIElements;
[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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Antro.ServerSorter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Antro.ServerSorter")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("Antro.ServerSorter")]
[assembly: AssemblyTitle("Antro.ServerSorter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 ServerSorterMod
{
[BepInPlugin("com.Antro.ServerSorter", "Server Sorter UI Toolkit", "1.7.2")]
public class ServerSorterPlugin : BaseUnityPlugin
{
public static ServerSorterPlugin Instance;
public int currentSortMode = 0;
public bool sortAscending = false;
public bool filterOpenOnly = false;
public bool filterThreePlusPlayers = false;
private VisualElement uiRootElement;
private Button sortDefaultBtn;
private Button sortPingBtn;
private Button sortPlayersBtn;
private Button sortNameBtn;
private Button filterOpenBtn;
private Button filterThreePlusBtn;
private Texture2D stolenBgTexture;
private Texture2D stolenBtnTexture;
private Texture2D stolenToggleTexture;
private Font baseFont;
public MenuController currentMenuController;
private GameObject cachedServerListPanel;
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.Antro.ServerSorter");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Server Sorter Mod loaded successfully!");
}
private void Update()
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
if (uiRootElement != null)
{
if ((Object)(object)cachedServerListPanel == (Object)null && (Object)(object)currentMenuController != (Object)null)
{
ref GameObject reference = ref cachedServerListPanel;
object? value = AccessTools.Field(typeof(MenuController), "serverListPanel").GetValue(currentMenuController);
reference = (GameObject)((value is GameObject) ? value : null);
}
if ((Object)(object)cachedServerListPanel != (Object)null)
{
bool activeInHierarchy = cachedServerListPanel.activeInHierarchy;
uiRootElement.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!activeInHierarchy));
}
}
}
public void BuildCustomUI()
{
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Expected O, but got Unknown
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: 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_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_033b: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_0470: Unknown result type (might be due to invalid IL or missing references)
//IL_0476: Expected O, but got Unknown
//IL_0481: Unknown result type (might be due to invalid IL or missing references)
//IL_0538: Unknown result type (might be due to invalid IL or missing references)
DestroyCustomUI();
UIDocument val = Object.FindFirstObjectByType<UIDocument>((FindObjectsInactive)1);
if ((Object)(object)val == (Object)null)
{
return;
}
if ((Object)(object)currentMenuController != (Object)null)
{
ref GameObject reference = ref cachedServerListPanel;
object? value = AccessTools.Field(typeof(MenuController), "serverListPanel").GetValue(currentMenuController);
reference = (GameObject)((value is GameObject) ? value : null);
if ((Object)(object)cachedServerListPanel != (Object)null)
{
Image val2 = cachedServerListPanel.GetComponent<Image>();
if ((Object)(object)val2 == (Object)null)
{
val2 = cachedServerListPanel.GetComponentInChildren<Image>(true);
}
if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sprite != (Object)null)
{
stolenBgTexture = val2.sprite.texture;
}
}
object? value2 = AccessTools.Field(typeof(MenuController), "serverListRefreshButton").GetValue(currentMenuController);
GameObject val3 = (GameObject)((value2 is GameObject) ? value2 : null);
if ((Object)(object)val3 != (Object)null)
{
Image component = val3.GetComponent<Image>();
if ((Object)(object)component != (Object)null && (Object)(object)component.sprite != (Object)null)
{
stolenBtnTexture = component.sprite.texture;
}
}
object? value3 = AccessTools.Field(typeof(MenuController), "serverListElementPrefab").GetValue(currentMenuController);
GameObject val4 = (GameObject)((value3 is GameObject) ? value3 : null);
if ((Object)(object)val4 != (Object)null)
{
Transform val5 = val4.transform.Find("GameObject/Graphic");
if ((Object)(object)val5 != (Object)null)
{
Image component2 = ((Component)val5).GetComponent<Image>();
if ((Object)(object)component2 != (Object)null && (Object)(object)component2.sprite != (Object)null)
{
stolenToggleTexture = component2.sprite.texture;
}
}
}
}
LoadBaseFont();
uiRootElement = new VisualElement();
uiRootElement.style.position = StyleEnum<Position>.op_Implicit((Position)1);
uiRootElement.style.left = StyleLength.op_Implicit(1359f);
uiRootElement.style.top = StyleLength.op_Implicit(Length.Percent(50f));
uiRootElement.style.translate = new StyleTranslate(new Translate(Length.op_Implicit(0f), new Length(-50f, (LengthUnit)1)));
uiRootElement.style.width = StyleLength.op_Implicit(360f);
uiRootElement.style.height = StyleLength.op_Implicit(600f);
uiRootElement.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)0);
uiRootElement.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
uiRootElement.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)0);
uiRootElement.style.paddingTop = StyleLength.op_Implicit(60f);
uiRootElement.style.paddingBottom = StyleLength.op_Implicit(10f);
if ((Object)(object)stolenBgTexture != (Object)null)
{
uiRootElement.style.backgroundImage = new StyleBackground(stolenBgTexture);
uiRootElement.style.unityBackgroundScaleMode = StyleEnum<ScaleMode>.op_Implicit((ScaleMode)0);
}
else
{
uiRootElement.style.backgroundColor = new StyleColor(new Color(0.15f, 0.1f, 0.05f, 0.95f));
}
uiRootElement.Add(CreateNonClickableLabel("SORT BY:"));
sortDefaultBtn = CreateCustomButton("Default (Clear)", delegate
{
OnSortClicked(0);
});
sortPingBtn = CreateCustomButton("Ping", delegate
{
OnSortClicked(3);
});
sortPlayersBtn = CreateCustomButton("Players", delegate
{
OnSortClicked(1);
});
sortNameBtn = CreateCustomButton("Name", delegate
{
OnSortClicked(2);
});
uiRootElement.Add((VisualElement)(object)sortDefaultBtn);
uiRootElement.Add((VisualElement)(object)sortPingBtn);
uiRootElement.Add((VisualElement)(object)sortPlayersBtn);
uiRootElement.Add((VisualElement)(object)sortNameBtn);
VisualElement val6 = new VisualElement();
val6.style.flexGrow = StyleFloat.op_Implicit(0f);
uiRootElement.Add(val6);
uiRootElement.Add(CreateNonClickableLabel("SHOW ONLY:"));
filterOpenBtn = CreateCustomButton("Open (No Password)", delegate
{
filterOpenOnly = !filterOpenOnly;
UpdateFilterButtonsVisuals();
AutoRefresh();
}, stolenToggleTexture, 60);
filterThreePlusBtn = CreateCustomButton("3+ Players", delegate
{
filterThreePlusPlayers = !filterThreePlusPlayers;
UpdateFilterButtonsVisuals();
AutoRefresh();
}, stolenToggleTexture, 60);
uiRootElement.Add((VisualElement)(object)filterOpenBtn);
uiRootElement.Add((VisualElement)(object)filterThreePlusBtn);
UpdateSortButtonsVisuals();
UpdateFilterButtonsVisuals();
uiRootElement.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
val.rootVisualElement.Add(uiRootElement);
}
private void LoadBaseFont()
{
baseFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
if ((Object)(object)baseFont == (Object)null)
{
baseFont = Font.CreateDynamicFontFromOSFont("Arial", 24);
}
}
private VisualElement CreateNonClickableLabel(string text)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Expected O, but got Unknown
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
VisualElement val = new VisualElement();
val.style.width = StyleLength.op_Implicit(240f);
val.style.height = StyleLength.op_Implicit(40f);
val.style.minHeight = StyleLength.op_Implicit(40f);
val.style.maxHeight = StyleLength.op_Implicit(40f);
val.style.flexShrink = StyleFloat.op_Implicit(0f);
val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
val.style.marginTop = StyleLength.op_Implicit(12f);
val.style.marginBottom = StyleLength.op_Implicit(6f);
if ((Object)(object)stolenBtnTexture != (Object)null)
{
val.style.backgroundImage = new StyleBackground(stolenBtnTexture);
val.style.unityBackgroundImageTintColor = StyleColor.op_Implicit(new Color(0.5f, 0.5f, 0.5f));
}
else
{
val.style.backgroundColor = new StyleColor(new Color(0.3f, 0.3f, 0.3f));
}
Label val2 = new Label(text);
((VisualElement)val2).style.color = StyleColor.op_Implicit(Color.white);
((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(20f);
((VisualElement)val2).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
((VisualElement)val2).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
((VisualElement)val2).style.height = StyleLength.op_Implicit(Length.Percent(100f));
((VisualElement)val2).style.width = StyleLength.op_Implicit(Length.Percent(100f));
if ((Object)(object)baseFont != (Object)null)
{
((VisualElement)val2).style.unityFont = StyleFont.op_Implicit(baseFont);
((VisualElement)val2).style.unityFontDefinition = new StyleFontDefinition(baseFont);
}
val.Add((VisualElement)(object)val2);
return val;
}
private Button CreateCustomButton(string baseText, Action onClick, Texture2D customTexture = null, int customHeight = 50)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_025e: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_028b: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
Button val = new Button(onClick);
((VisualElement)val).userData = baseText;
((TextElement)val).text = baseText;
((Focusable)val).focusable = false;
((VisualElement)val).style.width = StyleLength.op_Implicit(320f);
((VisualElement)val).style.height = StyleLength.op_Implicit((float)customHeight);
((VisualElement)val).style.minHeight = StyleLength.op_Implicit((float)customHeight);
((VisualElement)val).style.maxHeight = StyleLength.op_Implicit((float)customHeight);
((VisualElement)val).style.flexShrink = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.marginTop = StyleLength.op_Implicit(3f);
((VisualElement)val).style.marginBottom = StyleLength.op_Implicit(3f);
((VisualElement)val).style.fontSize = StyleLength.op_Implicit(20f);
((VisualElement)val).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
if ((Object)(object)customTexture != (Object)null)
{
((VisualElement)val).style.backgroundImage = new StyleBackground(customTexture);
((VisualElement)val).style.unityBackgroundScaleMode = StyleEnum<ScaleMode>.op_Implicit((ScaleMode)1);
((VisualElement)val).style.backgroundColor = StyleColor.op_Implicit(Color.clear);
((VisualElement)val).style.borderTopWidth = StyleFloat.op_Implicit(-3f);
((VisualElement)val).style.borderBottomWidth = StyleFloat.op_Implicit(-3f);
((VisualElement)val).style.borderLeftWidth = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.borderRightWidth = StyleFloat.op_Implicit(0f);
}
else if ((Object)(object)stolenBtnTexture != (Object)null)
{
((VisualElement)val).style.backgroundImage = new StyleBackground(stolenBtnTexture);
((VisualElement)val).style.unityBackgroundScaleMode = StyleEnum<ScaleMode>.op_Implicit((ScaleMode)0);
((VisualElement)val).style.backgroundColor = StyleColor.op_Implicit(Color.clear);
((VisualElement)val).style.borderTopWidth = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.borderBottomWidth = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.borderLeftWidth = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.borderRightWidth = StyleFloat.op_Implicit(0f);
}
else
{
((VisualElement)val).style.backgroundColor = new StyleColor(new Color(0.2f, 0.2f, 0.2f));
}
((VisualElement)val).style.color = StyleColor.op_Implicit(Color.white);
if ((Object)(object)baseFont != (Object)null)
{
((VisualElement)val).style.unityFont = StyleFont.op_Implicit(baseFont);
((VisualElement)val).style.unityFontDefinition = new StyleFontDefinition(baseFont);
}
return val;
}
private void OnSortClicked(int sortId)
{
if (currentSortMode == sortId && sortId != 0)
{
sortAscending = !sortAscending;
}
else
{
currentSortMode = sortId;
if (sortId == 1)
{
sortAscending = false;
}
if (sortId == 2)
{
sortAscending = true;
}
if (sortId == 3)
{
sortAscending = true;
}
}
UpdateSortButtonsVisuals();
AutoRefresh();
}
private void UpdateSortButtonsVisuals()
{
//IL_0017: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
Color val = default(Color);
((Color)(ref val))..ctor(0.5f, 1f, 0.5f);
Color white = Color.white;
((VisualElement)sortDefaultBtn).style.unityBackgroundImageTintColor = StyleColor.op_Implicit((currentSortMode == 0) ? val : white);
((VisualElement)sortPingBtn).style.unityBackgroundImageTintColor = StyleColor.op_Implicit((currentSortMode == 3) ? val : white);
((VisualElement)sortPlayersBtn).style.unityBackgroundImageTintColor = StyleColor.op_Implicit((currentSortMode == 1) ? val : white);
((VisualElement)sortNameBtn).style.unityBackgroundImageTintColor = StyleColor.op_Implicit((currentSortMode == 2) ? val : white);
string text = (sortAscending ? " ↑" : " ↓");
((TextElement)sortDefaultBtn).text = (string)((VisualElement)sortDefaultBtn).userData;
((TextElement)sortPingBtn).text = (string)((VisualElement)sortPingBtn).userData + ((currentSortMode == 3) ? text : "");
((TextElement)sortPlayersBtn).text = (string)((VisualElement)sortPlayersBtn).userData + ((currentSortMode == 1) ? text : "");
((TextElement)sortNameBtn).text = (string)((VisualElement)sortNameBtn).userData + ((currentSortMode == 2) ? text : "");
}
private void UpdateFilterButtonsVisuals()
{
//IL_0017: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
Color val = default(Color);
((Color)(ref val))..ctor(0.5f, 1f, 0.5f);
Color white = Color.white;
((VisualElement)filterOpenBtn).style.unityBackgroundImageTintColor = StyleColor.op_Implicit(filterOpenOnly ? val : white);
((TextElement)filterOpenBtn).text = (filterOpenOnly ? "[ON] " : "[OFF] ") + (string)((VisualElement)filterOpenBtn).userData;
((VisualElement)filterThreePlusBtn).style.unityBackgroundImageTintColor = StyleColor.op_Implicit(filterThreePlusPlayers ? val : white);
((TextElement)filterThreePlusBtn).text = (filterThreePlusPlayers ? "[ON] " : "[OFF] ") + (string)((VisualElement)filterThreePlusBtn).userData;
}
public void DestroyCustomUI()
{
if (uiRootElement != null)
{
uiRootElement.RemoveFromHierarchy();
uiRootElement = null;
}
}
private void AutoRefresh()
{
if ((Object)(object)currentMenuController != (Object)null)
{
AccessTools.Method(typeof(MenuController), "RefreshLobbyList", (Type[])null, (Type[])null)?.Invoke(currentMenuController, null);
}
}
public async void DoCustomRefresh(MenuController menuController)
{
currentMenuController = menuController;
try
{
object? value = AccessTools.Field(typeof(MenuController), "serverListRefreshButton").GetValue(menuController);
GameObject refreshBtn = (GameObject)((value is GameObject) ? value : null);
object? value2 = AccessTools.Field(typeof(MenuController), "serverListElementParent").GetValue(menuController);
Transform listParent = (Transform)((value2 is Transform) ? value2 : null);
object? value3 = AccessTools.Field(typeof(MenuController), "serverListElementPrefab").GetValue(menuController);
GameObject prefab = (GameObject)((value3 is GameObject) ? value3 : null);
LobbyManager lobbyManager = Object.FindAnyObjectByType<LobbyManager>();
if ((Object)(object)refreshBtn != (Object)null)
{
refreshBtn.SetActive(false);
}
Lobby[] result = await lobbyManager.GetLobbyList();
if ((Object)(object)refreshBtn != (Object)null)
{
refreshBtn.SetActive(true);
}
foreach (Transform item2 in listParent)
{
Transform child = item2;
Object.Destroy((Object)(object)((Component)child).gameObject);
}
if (result == null || result.Length == 0)
{
return;
}
List<ServerListItem> processedLobbies = new List<ServerListItem>();
Lobby[] array = result;
for (int i = 0; i < array.Length; i++)
{
Lobby lobbyRef = array[i];
bool.TryParse(((Lobby)(ref lobbyRef)).GetData("hasPassword"), out var hasPass);
int currentPlayers = ((Lobby)(ref lobbyRef)).MemberCount;
if (!(filterOpenOnly && hasPass) && (!filterThreePlusPlayers || currentPlayers >= 3))
{
processedLobbies.Add(new ServerListItem
{
steamId = ((Lobby)(ref lobbyRef)).Id,
serverName = ((Lobby)(ref lobbyRef)).GetData("gnomeGameLobbyName"),
maxPlayers = ((Lobby)(ref lobbyRef)).MaxMembers,
currentPlayers = currentPlayers,
hasPass = hasPass,
lobbyRef = lobbyRef
});
}
}
IEnumerable<ServerListItem> query = processedLobbies;
if (currentSortMode == 1)
{
query = (sortAscending ? query.OrderBy((ServerListItem l) => l.currentPlayers) : query.OrderByDescending((ServerListItem l) => l.currentPlayers));
}
else if (currentSortMode == 2)
{
query = (sortAscending ? query.OrderBy((ServerListItem l) => l.serverName) : query.OrderByDescending((ServerListItem l) => l.serverName));
}
else if (currentSortMode == 3 && !sortAscending)
{
query = query.Reverse();
}
processedLobbies = query.OrderByDescending(delegate(ServerListItem l)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
Friend owner2 = ((Lobby)(ref l.lobbyRef)).Owner;
return ((Friend)(ref owner2)).IsFriend;
}).ToList();
foreach (ServerListItem item in processedLobbies)
{
GameObject go = Object.Instantiate<GameObject>(prefab, listParent, false);
go.GetComponent<ServerListElement>().SetData(item, menuController);
Friend owner = ((Lobby)(ref item.lobbyRef)).Owner;
if (((Friend)(ref owner)).IsFriend)
{
Transform obj = go.transform.Find("GameObject/Graphic");
Image bg = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
if ((Object)(object)bg == (Object)null)
{
bg = go.GetComponent<Image>();
}
if ((Object)(object)bg != (Object)null)
{
((Graphic)bg).color = new Color(1f, 0.9f, 0.5f, 1f);
}
}
}
}
catch (Exception ex)
{
Exception ex2 = ex;
((BaseUnityPlugin)this).Logger.LogError((object)$"Error refreshing server list: {ex2}");
}
}
}
[HarmonyPatch(typeof(MenuController), "Start")]
public class MenuController_Start_Patch
{
private static void Postfix(MenuController __instance)
{
ServerSorterPlugin.Instance.currentMenuController = __instance;
ServerSorterPlugin.Instance.BuildCustomUI();
}
}
[HarmonyPatch(typeof(MenuController), "ActivatePanel")]
public class MenuController_ActivatePanel_Patch
{
private static void Postfix(MenuController __instance, GameObject panel)
{
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Expected O, but got Unknown
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Expected O, but got Unknown
object? value = AccessTools.Field(typeof(MenuController), "serverListPanel").GetValue(__instance);
GameObject val = (GameObject)((value is GameObject) ? value : null);
if (!((Object)(object)panel != (Object)null) || !((Object)(object)panel == (Object)(object)val))
{
return;
}
object? value2 = AccessTools.Field(typeof(MenuController), "serverListRefreshButton").GetValue(__instance);
GameObject val2 = (GameObject)((value2 is GameObject) ? value2 : null);
if (!((Object)(object)val2 != (Object)null))
{
return;
}
Transform val3 = val2.transform.parent.Find("ModCloseButton");
if (!((Object)(object)val3 == (Object)null))
{
return;
}
RectTransform component = val2.GetComponent<RectTransform>();
Vector2 anchoredPosition = component.anchoredPosition;
component.anchoredPosition = new Vector2(anchoredPosition.x - 70f, anchoredPosition.y);
GameObject val4 = Object.Instantiate<GameObject>(val2, val2.transform.parent);
((Object)val4).name = "ModCloseButton";
RectTransform component2 = val4.GetComponent<RectTransform>();
component2.anchoredPosition = anchoredPosition;
foreach (Transform item in val4.transform)
{
Transform val5 = item;
Object.Destroy((Object)(object)((Component)val5).gameObject);
}
Image component3 = val4.GetComponent<Image>();
if ((Object)(object)component3 != (Object)null)
{
((Graphic)component3).color = Color.white;
}
GameObject val6 = new GameObject("XText");
val6.SetActive(false);
val6.transform.SetParent(val4.transform, false);
RectTransform val7 = val6.AddComponent<RectTransform>();
val7.anchorMin = Vector2.zero;
val7.anchorMax = Vector2.one;
val7.sizeDelta = Vector2.zero;
TextMeshProUGUI val8 = val6.AddComponent<TextMeshProUGUI>();
((TMP_Text)val8).text = "X";
((Graphic)val8).color = Color.red;
((TMP_Text)val8).alignment = (TextAlignmentOptions)514;
((TMP_Text)val8).fontSize = 28f;
((TMP_Text)val8).fontStyle = (FontStyles)1;
((TMP_Text)val8).font = TMP_Settings.defaultFontAsset;
val6.SetActive(true);
Button component4 = val4.GetComponent<Button>();
if ((Object)(object)component4 != (Object)null)
{
((UnityEventBase)component4.onClick).RemoveAllListeners();
((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
{
__instance.CloseAllPanels();
});
}
}
}
[HarmonyPatch(typeof(MenuController), "RefreshLobbyList")]
public class MenuController_RefreshLobbyList_Patch
{
private static bool Prefix(MenuController __instance)
{
ServerSorterPlugin.Instance.DoCustomRefresh(__instance);
return false;
}
}
}
namespace DirectConnectMod
{
[BepInPlugin("com.Antro.DirectConnect", "Direct Connect Mod", "1.9.6")]
public class DirectConnectPlugin : BaseUnityPlugin
{
public static DirectConnectPlugin Instance;
private VisualElement directConnectRoot;
private TextField codeInput;
private GameObject pauseCanvasObj;
private TextMeshProUGUI pauseCodeLabel;
private TextMeshProUGUI toggleCodeBtnText;
private Image uguiBgImage;
private Image uguiShowBtnImage;
private Image uguiCopyBtnImage;
private bool isCodeVisible = false;
private Texture2D stolenBgTexture;
private Texture2D stolenBtnTexture;
private Sprite stolenBgSprite;
private TMP_FontAsset baseTMPFont;
private Font baseFont;
private Sprite inGameBgSprite;
private Sprite inGameBtnSprite;
private GameObject cachedServerListPanel;
public MenuController currentMenuController;
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.Antro.DirectConnect");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Direct Connect Mod loaded!");
}
private void Update()
{
//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_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
bool flag = ((Scene)(ref activeScene)).name == "MainMenu";
if (directConnectRoot != null)
{
if ((Object)(object)cachedServerListPanel == (Object)null && (Object)(object)currentMenuController != (Object)null)
{
ref GameObject reference = ref cachedServerListPanel;
object? value = AccessTools.Field(typeof(MenuController), "serverListPanel").GetValue(currentMenuController);
reference = (GameObject)((value is GameObject) ? value : null);
}
bool flag2 = flag && (Object)(object)cachedServerListPanel != (Object)null && cachedServerListPanel.activeInHierarchy;
directConnectRoot.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag2));
}
if (!((Object)(object)pauseCanvasObj != (Object)null))
{
return;
}
bool flag3 = false;
if (!flag)
{
SteamId id = ((Lobby)(ref LobbyManager.instance)).Id;
if (((SteamId)(ref id)).IsValid)
{
GameObject val = GameObject.Find("PlayerPuppet(Clone)");
if ((Object)(object)val != (Object)null)
{
Transform val2 = val.transform.Find("Canvas in front/Menu");
if ((Object)(object)val2 != (Object)null && ((Component)val2).gameObject.activeInHierarchy)
{
Transform val3 = val2.Find("Buttons");
if ((Object)(object)val3 != (Object)null && ((Component)val3).gameObject.activeSelf)
{
flag3 = true;
}
}
}
}
}
if (flag3)
{
TryStealInGameAssets();
if (!pauseCanvasObj.activeSelf)
{
pauseCanvasObj.SetActive(true);
isCodeVisible = false;
UpdatePauseMenuCodeDisplay();
}
}
else if (pauseCanvasObj.activeSelf)
{
pauseCanvasObj.SetActive(false);
}
}
public void BuildCustomUI()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0044: 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_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Expected O, but got Unknown
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
DestroyCustomUI();
UIDocument val = Object.FindFirstObjectByType<UIDocument>((FindObjectsInactive)1);
if ((Object)(object)val == (Object)null)
{
return;
}
StealTexturesOnly();
LoadBaseFonts();
directConnectRoot = new VisualElement();
directConnectRoot.style.position = StyleEnum<Position>.op_Implicit((Position)1);
directConnectRoot.style.left = StyleLength.op_Implicit(1359f);
directConnectRoot.style.top = StyleLength.op_Implicit(Length.Percent(50f));
directConnectRoot.style.translate = new StyleTranslate(new Translate(Length.op_Implicit(0f), Length.op_Implicit(-420f)));
directConnectRoot.style.width = StyleLength.op_Implicit(360f);
directConnectRoot.style.height = StyleLength.op_Implicit(110f);
directConnectRoot.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)0);
directConnectRoot.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
directConnectRoot.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
ApplyBackground(directConnectRoot);
directConnectRoot.Add(CreateNonClickableLabel("DIRECT CONNECT:"));
codeInput = new TextField();
((VisualElement)codeInput).style.width = StyleLength.op_Implicit(260f);
((VisualElement)codeInput).style.height = StyleLength.op_Implicit(30f);
((VisualElement)codeInput).style.marginTop = StyleLength.op_Implicit(2f);
((VisualElement)codeInput).style.fontSize = StyleLength.op_Implicit(20f);
((VisualElement)codeInput).style.color = StyleColor.op_Implicit(Color.black);
((VisualElement)codeInput).style.backgroundColor = new StyleColor(new Color(0.9f, 0.9f, 0.9f, 1f));
((VisualElement)codeInput).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
if ((Object)(object)baseFont != (Object)null)
{
((VisualElement)codeInput).style.unityFont = StyleFont.op_Implicit(baseFont);
((VisualElement)codeInput).style.unityFontDefinition = new StyleFontDefinition(baseFont);
}
((CallbackEventHandler)codeInput).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
VisualElement val3 = UQueryExtensions.Q((VisualElement)(object)codeInput, "unity-text-input", (string)null);
if (val3 != null)
{
val3.style.borderTopWidth = StyleFloat.op_Implicit(0f);
val3.style.borderBottomWidth = StyleFloat.op_Implicit(0f);
val3.style.borderLeftWidth = StyleFloat.op_Implicit(0f);
val3.style.borderRightWidth = StyleFloat.op_Implicit(0f);
val3.style.backgroundColor = StyleColor.op_Implicit(Color.clear);
val3.style.color = StyleColor.op_Implicit(Color.black);
val3.style.paddingTop = StyleLength.op_Implicit(0f);
val3.style.paddingBottom = StyleLength.op_Implicit(0f);
}
}, (TrickleDown)0);
Button val2 = CreateCustomButton("Connect to Lobby", ConnectByCode, 35);
directConnectRoot.Add((VisualElement)(object)codeInput);
directConnectRoot.Add((VisualElement)(object)val2);
directConnectRoot.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
val.rootVisualElement.Add(directConnectRoot);
CreatePauseMenuUGUI();
}
private void CreatePauseMenuUGUI()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Expected O, but got Unknown
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Expected O, but got Unknown
pauseCanvasObj = new GameObject("DirectConnectPauseCanvas");
Object.DontDestroyOnLoad((Object)(object)pauseCanvasObj);
Canvas val = pauseCanvasObj.AddComponent<Canvas>();
val.renderMode = (RenderMode)0;
val.sortingOrder = 9999;
CanvasScaler val2 = pauseCanvasObj.AddComponent<CanvasScaler>();
val2.uiScaleMode = (ScaleMode)1;
val2.referenceResolution = new Vector2(1920f, 1080f);
pauseCanvasObj.AddComponent<GraphicRaycaster>();
GameObject val3 = new GameObject("Panel");
val3.transform.SetParent(pauseCanvasObj.transform, false);
RectTransform val4 = val3.AddComponent<RectTransform>();
val4.anchorMin = new Vector2(0f, 1f);
val4.anchorMax = new Vector2(0f, 1f);
val4.pivot = new Vector2(0f, 1f);
val4.anchoredPosition = new Vector2(65f, -110f);
val4.sizeDelta = new Vector2(360f, 140f);
uguiBgImage = val3.AddComponent<Image>();
((Graphic)uguiBgImage).color = new Color(0.15f, 0.1f, 0.05f, 0.95f);
CreateUGUILabel(val3.transform, "LOBBY CODE:", new Vector2(0f, -25f), 20f, isBold: true, (TextAlignmentOptions)514);
pauseCodeLabel = CreateUGUILabel(val3.transform, "***************************", new Vector2(0f, -60f), 18f, isBold: false, (TextAlignmentOptions)514);
uguiShowBtnImage = CreateUGUIButton(val3.transform, "Show", new Vector2(10f, 10f), new Vector2(165f, 40f), (TextAnchor)6, (UnityAction)delegate
{
isCodeVisible = !isCodeVisible;
UpdatePauseMenuCodeDisplay();
}, out toggleCodeBtnText);
uguiCopyBtnImage = CreateUGUIButton(val3.transform, "Copy", new Vector2(-10f, 10f), new Vector2(165f, 40f), (TextAnchor)8, new UnityAction(CopyLobbyCode), out var _);
pauseCanvasObj.SetActive(false);
}
private void TryStealInGameAssets()
{
if ((Object)(object)inGameBgSprite != (Object)null && (Object)(object)inGameBtnSprite != (Object)null)
{
return;
}
GameObject val = GameObject.Find("PlayerPuppet(Clone)");
if ((Object)(object)val == (Object)null)
{
return;
}
if ((Object)(object)inGameBgSprite == (Object)null)
{
Transform val2 = val.transform.Find("Canvas in front/Menu/Settings/Image");
if ((Object)(object)val2 != (Object)null)
{
Image component = ((Component)val2).GetComponent<Image>();
if ((Object)(object)component != (Object)null && (Object)(object)component.sprite != (Object)null)
{
inGameBgSprite = component.sprite;
}
}
}
if ((Object)(object)inGameBtnSprite == (Object)null)
{
Transform val3 = val.transform.Find("Canvas in front/Menu/Buttons/SGButtonPrimaryUGUI (save) (1)/Bg");
if ((Object)(object)val3 != (Object)null)
{
Image component2 = ((Component)val3).GetComponent<Image>();
if ((Object)(object)component2 != (Object)null && (Object)(object)component2.sprite != (Object)null)
{
inGameBtnSprite = component2.sprite;
}
}
}
ApplyInGameAssetsToUGUI();
}
private void ApplyInGameAssetsToUGUI()
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)uguiBgImage != (Object)null)
{
if ((Object)(object)inGameBgSprite != (Object)null)
{
uguiBgImage.sprite = inGameBgSprite;
uguiBgImage.type = (Type)1;
((Graphic)uguiBgImage).color = Color.white;
}
else if ((Object)(object)stolenBgSprite != (Object)null)
{
uguiBgImage.sprite = stolenBgSprite;
uguiBgImage.type = (Type)1;
((Graphic)uguiBgImage).color = Color.white;
}
}
if ((Object)(object)uguiShowBtnImage != (Object)null && (Object)(object)inGameBtnSprite != (Object)null)
{
uguiShowBtnImage.sprite = inGameBtnSprite;
uguiShowBtnImage.type = (Type)1;
((Graphic)uguiShowBtnImage).color = Color.white;
}
if ((Object)(object)uguiCopyBtnImage != (Object)null && (Object)(object)inGameBtnSprite != (Object)null)
{
uguiCopyBtnImage.sprite = inGameBtnSprite;
uguiCopyBtnImage.type = (Type)1;
((Graphic)uguiCopyBtnImage).color = Color.white;
}
}
private string EncodeSteamIdTo27Digits(ulong steamId)
{
Random random = new Random(steamId.GetHashCode());
ulong num = (ulong)random.Next(100, 999);
ulong num2 = (ulong)random.Next(100000, 999999);
ulong num3 = num * 857391264 + num2;
ulong num4 = steamId ^ num3;
string text = $"{num:D3}{num4:D18}{num2:D6}";
return text.Substring(0, 9) + "-" + text.Substring(9, 9) + "-" + text.Substring(18, 9);
}
private ulong Decode27DigitCode(string code)
{
code = code.Replace(" ", "").Replace("-", "");
if (code.Length != 27)
{
return 0uL;
}
if (!ulong.TryParse(code.Substring(0, 3), out var result))
{
return 0uL;
}
if (!ulong.TryParse(code.Substring(3, 18), out var result2))
{
return 0uL;
}
if (!ulong.TryParse(code.Substring(21, 6), out var result3))
{
return 0uL;
}
ulong num = result * 857391264 + result3;
return result2 ^ num;
}
private async void ConnectByCode()
{
if (string.IsNullOrWhiteSpace(((BaseField<string>)(object)codeInput).value))
{
return;
}
ulong lobbyIdRaw = Decode27DigitCode(((BaseField<string>)(object)codeInput).value);
if (lobbyIdRaw == 0)
{
return;
}
SteamId steamId = new SteamId
{
Value = lobbyIdRaw
};
try
{
Lobby? result = await SteamMatchmaking.JoinLobbyAsync(steamId);
if (!result.HasValue)
{
return;
}
Lobby lobby = result.Value;
bool.TryParse(((Lobby)(ref lobby)).GetData("hasPassword"), out var hasPass);
ServerListItem dummyItem = new ServerListItem
{
steamId = ((Lobby)(ref lobby)).Id,
serverName = ((Lobby)(ref lobby)).GetData("gnomeGameLobbyName"),
maxPlayers = ((Lobby)(ref lobby)).MaxMembers,
currentPlayers = ((Lobby)(ref lobby)).MemberCount,
hasPass = hasPass,
lobbyRef = lobby
};
if ((Object)(object)currentMenuController != (Object)null)
{
directConnectRoot.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
MethodInfo confirmJoin = AccessTools.Method(typeof(MenuController), "OnPlayerConfirmPublicLobbyJoin", (Type[])null, (Type[])null);
if (confirmJoin != null)
{
confirmJoin.Invoke(currentMenuController, new object[1] { dummyItem });
}
else
{
Object.FindAnyObjectByType<LobbyManager>().JoinLobby(lobby, "");
}
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Connection error: " + ex.Message));
}
}
private void UpdatePauseMenuCodeDisplay()
{
//IL_000e: 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_002f: Unknown result type (might be due to invalid IL or missing references)
if (isCodeVisible)
{
SteamId id = ((Lobby)(ref LobbyManager.instance)).Id;
if (((SteamId)(ref id)).IsValid)
{
((TMP_Text)pauseCodeLabel).text = EncodeSteamIdTo27Digits(((Lobby)(ref LobbyManager.instance)).Id.Value);
((TMP_Text)toggleCodeBtnText).text = "Hide";
return;
}
}
((TMP_Text)pauseCodeLabel).text = "***************************";
((TMP_Text)toggleCodeBtnText).text = "Show";
}
private void CopyLobbyCode()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
SteamId id = ((Lobby)(ref LobbyManager.instance)).Id;
if (((SteamId)(ref id)).IsValid)
{
GUIUtility.systemCopyBuffer = EncodeSteamIdTo27Digits(((Lobby)(ref LobbyManager.instance)).Id.Value);
}
}
private TextMeshProUGUI CreateUGUILabel(Transform parent, string text, Vector2 pos, float fontSize, bool isBold, TextAlignmentOptions alignment)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0034: 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)
//IL_0060: 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)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Label");
val.SetActive(false);
val.transform.SetParent(parent, false);
RectTransform val2 = val.AddComponent<RectTransform>();
val2.anchorMin = new Vector2(0.5f, 1f);
val2.anchorMax = new Vector2(0.5f, 1f);
val2.pivot = new Vector2(0.5f, 1f);
val2.anchoredPosition = pos;
val2.sizeDelta = new Vector2(300f, 40f);
TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
if ((Object)(object)baseTMPFont != (Object)null)
{
((TMP_Text)val3).font = baseTMPFont;
}
((TMP_Text)val3).text = text;
((TMP_Text)val3).fontSize = fontSize;
((TMP_Text)val3).alignment = alignment;
((Graphic)val3).color = Color.white;
((Graphic)val3).raycastTarget = false;
if (isBold)
{
((TMP_Text)val3).fontStyle = (FontStyles)1;
}
val.SetActive(true);
return val3;
}
private Image CreateUGUIButton(Transform parent, string text, Vector2 posOffset, Vector2 size, TextAnchor anchorPos, UnityAction onClick, out TextMeshProUGUI tmpText)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Invalid comparison between Unknown and I4
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Invalid comparison between Unknown and I4
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Expected O, but got Unknown
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Button");
val.transform.SetParent(parent, false);
RectTransform val2 = val.AddComponent<RectTransform>();
if ((int)anchorPos == 6)
{
val2.anchorMin = new Vector2(0f, 0f);
val2.anchorMax = new Vector2(0f, 0f);
val2.pivot = new Vector2(0f, 0f);
}
else if ((int)anchorPos == 8)
{
val2.anchorMin = new Vector2(1f, 0f);
val2.anchorMax = new Vector2(1f, 0f);
val2.pivot = new Vector2(1f, 0f);
}
val2.anchoredPosition = posOffset;
val2.sizeDelta = size;
Image val3 = val.AddComponent<Image>();
((Graphic)val3).color = new Color(0.2f, 0.2f, 0.2f, 1f);
Button val4 = val.AddComponent<Button>();
((UnityEvent)val4.onClick).AddListener(onClick);
GameObject val5 = new GameObject("Text");
val5.SetActive(false);
val5.transform.SetParent(val.transform, false);
RectTransform val6 = val5.AddComponent<RectTransform>();
val6.anchorMin = Vector2.zero;
val6.anchorMax = Vector2.one;
val6.sizeDelta = Vector2.zero;
tmpText = val5.AddComponent<TextMeshProUGUI>();
if ((Object)(object)baseTMPFont != (Object)null)
{
((TMP_Text)tmpText).font = baseTMPFont;
}
((TMP_Text)tmpText).text = text;
((TMP_Text)tmpText).fontSize = 20f;
((TMP_Text)tmpText).alignment = (TextAlignmentOptions)514;
((Graphic)tmpText).color = Color.white;
((Graphic)tmpText).raycastTarget = false;
val5.SetActive(true);
return val3;
}
private void ApplyBackground(VisualElement el)
{
//IL_0070: 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_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: 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_0048: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)stolenBgTexture != (Object)null)
{
el.style.backgroundImage = new StyleBackground(stolenBgTexture);
el.style.backgroundSize = new StyleBackgroundSize(new BackgroundSize(Length.Percent(100f), Length.Percent(100f)));
}
else
{
el.style.backgroundColor = new StyleColor(new Color(0.15f, 0.1f, 0.05f, 0.95f));
}
}
private VisualElement CreateNonClickableLabel(string text)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Expected O, but got Unknown
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
VisualElement val = new VisualElement();
val.style.width = StyleLength.op_Implicit(280f);
val.style.height = StyleLength.op_Implicit(50f);
val.style.minHeight = StyleLength.op_Implicit(50f);
val.style.flexShrink = StyleFloat.op_Implicit(0f);
val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
val.style.marginTop = StyleLength.op_Implicit(5f);
val.style.marginBottom = StyleLength.op_Implicit(5f);
if ((Object)(object)stolenBtnTexture != (Object)null)
{
val.style.backgroundImage = new StyleBackground(stolenBtnTexture);
val.style.unityBackgroundImageTintColor = StyleColor.op_Implicit(new Color(0.5f, 0.5f, 0.5f));
val.style.backgroundSize = new StyleBackgroundSize(new BackgroundSize(Length.Percent(100f), Length.Percent(100f)));
}
else
{
val.style.backgroundColor = new StyleColor(new Color(0.3f, 0.3f, 0.3f));
}
Label val2 = new Label(text);
((VisualElement)val2).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
((VisualElement)val2).style.paddingTop = StyleLength.op_Implicit(0f);
((VisualElement)val2).style.paddingBottom = StyleLength.op_Implicit(0f);
((VisualElement)val2).style.marginTop = StyleLength.op_Implicit(0f);
((VisualElement)val2).style.marginBottom = StyleLength.op_Implicit(0f);
((VisualElement)val2).style.color = StyleColor.op_Implicit(Color.white);
((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(20f);
((VisualElement)val2).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
if ((Object)(object)baseFont != (Object)null)
{
((VisualElement)val2).style.unityFont = StyleFont.op_Implicit(baseFont);
((VisualElement)val2).style.unityFontDefinition = new StyleFontDefinition(baseFont);
}
val.Add((VisualElement)(object)val2);
val.style.translate = new StyleTranslate(new Translate(Length.op_Implicit(0f), Length.op_Implicit(-20f)));
return val;
}
private Button CreateCustomButton(string baseText, Action onClick, int customHeight = 50)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0023: 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_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
Button val = new Button(onClick);
((TextElement)val).text = baseText;
((Focusable)val).focusable = false;
((VisualElement)val).style.width = StyleLength.op_Implicit(320f);
((VisualElement)val).style.height = StyleLength.op_Implicit((float)customHeight);
((VisualElement)val).style.marginTop = StyleLength.op_Implicit(2f);
((VisualElement)val).style.marginBottom = StyleLength.op_Implicit(2f);
((VisualElement)val).style.fontSize = StyleLength.op_Implicit(20f);
((VisualElement)val).style.color = StyleColor.op_Implicit(Color.white);
if ((Object)(object)stolenBtnTexture != (Object)null)
{
((VisualElement)val).style.backgroundImage = new StyleBackground(stolenBtnTexture);
((VisualElement)val).style.backgroundSize = new StyleBackgroundSize(new BackgroundSize(Length.Percent(100f), Length.Percent(100f)));
((VisualElement)val).style.backgroundColor = StyleColor.op_Implicit(Color.clear);
((VisualElement)val).style.borderTopWidth = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.borderBottomWidth = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.borderLeftWidth = StyleFloat.op_Implicit(0f);
((VisualElement)val).style.borderRightWidth = StyleFloat.op_Implicit(0f);
}
else
{
((VisualElement)val).style.backgroundColor = new StyleColor(new Color(0.2f, 0.2f, 0.2f));
}
if ((Object)(object)baseFont != (Object)null)
{
((VisualElement)val).style.unityFont = StyleFont.op_Implicit(baseFont);
((VisualElement)val).style.unityFontDefinition = new StyleFontDefinition(baseFont);
}
((VisualElement)val).style.translate = new StyleTranslate(new Translate(Length.op_Implicit(0f), Length.op_Implicit(10f)));
return val;
}
private void LoadBaseFonts()
{
baseFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
if ((Object)(object)baseFont == (Object)null)
{
baseFont = Font.CreateDynamicFontFromOSFont("Arial", 24);
}
baseTMPFont = TMP_Settings.defaultFontAsset;
}
private void StealTexturesOnly()
{
if ((Object)(object)currentMenuController == (Object)null)
{
return;
}
ref GameObject reference = ref cachedServerListPanel;
object? value = AccessTools.Field(typeof(MenuController), "serverListPanel").GetValue(currentMenuController);
reference = (GameObject)((value is GameObject) ? value : null);
if ((Object)(object)cachedServerListPanel != (Object)null)
{
Image val = cachedServerListPanel.GetComponent<Image>() ?? cachedServerListPanel.GetComponentInChildren<Image>(true);
if ((Object)(object)val != (Object)null && (Object)(object)val.sprite != (Object)null)
{
stolenBgTexture = val.sprite.texture;
stolenBgSprite = val.sprite;
}
}
object? value2 = AccessTools.Field(typeof(MenuController), "serverListRefreshButton").GetValue(currentMenuController);
GameObject val2 = (GameObject)((value2 is GameObject) ? value2 : null);
if ((Object)(object)val2 != (Object)null)
{
Image component = val2.GetComponent<Image>();
if ((Object)(object)component != (Object)null && (Object)(object)component.sprite != (Object)null)
{
stolenBtnTexture = component.sprite.texture;
}
}
}
public void DestroyCustomUI()
{
if (directConnectRoot != null)
{
directConnectRoot.RemoveFromHierarchy();
}
if ((Object)(object)pauseCanvasObj != (Object)null)
{
Object.Destroy((Object)(object)pauseCanvasObj);
}
directConnectRoot = null;
pauseCanvasObj = null;
}
}
[HarmonyPatch(typeof(MenuController), "Start")]
public class DirectConnect_MenuController_Start_Patch
{
private static void Postfix(MenuController __instance)
{
DirectConnectPlugin.Instance.currentMenuController = __instance;
DirectConnectPlugin.Instance.BuildCustomUI();
}
}
}