using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Threading.Tasks; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using PurrLobby; using Steamworks; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ServerFavorites")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.7.0")] [assembly: AssemblyInformationalVersion("1.1.7")] [assembly: AssemblyProduct("ServerFavorites")] [assembly: AssemblyTitle("ServerFavorites")] [assembly: AssemblyVersion("1.1.7.0")] [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 ServerFavorites { [BepInPlugin("com.ontogether.serverfavorites", "ServerFavorites", "1.1.7")] public class ServerFavoritesPlugin : BaseUnityPlugin { public const string PluginGuid = "com.ontogether.serverfavorites"; public const string PluginName = "ServerFavorites"; public const string PluginVersion = "1.1.7"; internal static ServerFavoritesPlugin Instance; internal static ManualLogSource Log; internal static FavoriteStore Store; internal static FavoritesTabController TabController; private Harmony _harmony; private void Awake() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; Store = new FavoriteStore(); TabController = new FavoritesTabController(); _harmony = new Harmony("com.ontogether.serverfavorites"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} loaded ({2} saved host(s), Harmony patched)", "ServerFavorites", "1.1.7", Store.Count)); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal sealed class FavoriteStore { private readonly string _filePath; private readonly Dictionary _hosts = new Dictionary(); public int Count => _hosts.Count; public IEnumerable All => _hosts.Values.OrderBy((FavoriteHost h) => h.Label, StringComparer.OrdinalIgnoreCase); public FavoriteStore() { _filePath = Path.Combine(Paths.ConfigPath, "com.ontogether.serverfavorites.txt"); Load(); } public bool Contains(string steamId) { if (!string.IsNullOrEmpty(steamId)) { return _hosts.ContainsKey(steamId.Trim()); } return false; } public void Toggle(string steamId, string label) { string text = steamId.Trim(); if (_hosts.ContainsKey(text)) { _hosts.Remove(text); } else { _hosts[text] = new FavoriteHost { SteamId = text, Label = (string.IsNullOrWhiteSpace(label) ? text : label.Trim()) }; } Save(); } private void Load() { _hosts.Clear(); if (!File.Exists(_filePath)) { return; } string[] array = File.ReadAllLines(_filePath); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length != 0 && !text.StartsWith("#", StringComparison.Ordinal)) { int num = text.IndexOf('|'); string text2; string label; if (num >= 0) { text2 = text.Substring(0, num).Trim(); label = text.Substring(num + 1).Trim(); } else { text2 = text; label = text; } if (ulong.TryParse(text2, NumberStyles.Integer, CultureInfo.InvariantCulture, out var _)) { _hosts[text2] = new FavoriteHost { SteamId = text2, Label = label }; } } } } private void Save() { Directory.CreateDirectory(Path.GetDirectoryName(_filePath)); IEnumerable contents = from h in _hosts.Values.OrderBy((FavoriteHost h) => h.Label, StringComparer.OrdinalIgnoreCase) select h.SteamId + "|" + h.Label; File.WriteAllLines(_filePath, contents, Encoding.UTF8); } } internal sealed class FavoriteHost { public string SteamId; public string Label; } internal static class LobbyHostUtility { private const uint OnTogetherAppId = 3707400u; public static bool TryGetHostSteamId(string lobbyId, out string hostSteamId) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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) hostSteamId = null; if (!ulong.TryParse(lobbyId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return false; } CSteamID val = default(CSteamID); ((CSteamID)(ref val))..ctor(result); string lobbyData = SteamMatchmaking.GetLobbyData(val, "owner"); if (!string.IsNullOrEmpty(lobbyData) && ulong.TryParse(lobbyData, NumberStyles.Integer, CultureInfo.InvariantCulture, out var _)) { hostSteamId = lobbyData; return true; } CSteamID lobbyOwner = SteamMatchmaking.GetLobbyOwner(val); if (((CSteamID)(ref lobbyOwner)).IsValid()) { hostSteamId = lobbyOwner.m_SteamID.ToString(CultureInfo.InvariantCulture); return true; } return false; } public static string ResolveLabel(string hostSteamId, string fallbackName) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrWhiteSpace(fallbackName)) { return fallbackName.Trim(); } if (SteamManager.Initialized && ulong.TryParse(hostSteamId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { string friendPersonaName = SteamFriends.GetFriendPersonaName(new CSteamID(result)); if (!string.IsNullOrWhiteSpace(friendPersonaName)) { return friendPersonaName; } } return hostSteamId; } public static bool TryFindViaFriends(string hostSteamId, out Lobby lobby) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) lobby = default(Lobby); if (!ulong.TryParse(hostSteamId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return false; } return TryFindViaFriends(result, out lobby); } public static Task> SearchPublicLobbiesAsync(int distance) { MultiplayerManager i = MonoSingleton.I; if ((Object)(object)i == (Object)null || (Object)(object)i._lobbyManager == (Object)null || i._lobbyManager.CurrentProvider == null) { return Task.FromResult>(null); } Dictionary dictionary = new Dictionary { { "public", "t" }, { "version", ConstData.Version.ToLower() } }; return i._lobbyManager.CurrentProvider.SearchLobbiesAsync(distance, 50, dictionary); } private unsafe static bool TryFindViaFriends(ulong hostNumeric, out Lobby lobby) { //IL_0001: 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) //IL_0022: 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) //IL_002c: 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_0065: 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_0078: 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) lobby = default(Lobby); if (!SteamManager.Initialized) { return false; } int friendCount = SteamFriends.GetFriendCount((EFriendFlags)4); FriendGameInfo_t val = default(FriendGameInfo_t); for (int i = 0; i < friendCount; i++) { CSteamID friendByIndex = SteamFriends.GetFriendByIndex(i, (EFriendFlags)4); if (friendByIndex.m_SteamID == hostNumeric) { if (!SteamFriends.GetFriendGamePlayed(friendByIndex, ref val)) { return false; } if (((object)(*(CGameID*)(&val.m_gameID))/*cast due to .constrained prefix*/).ToString() != 3707400u.ToString(CultureInfo.InvariantCulture) || val.m_steamIDLobby == CSteamID.Nil) { return false; } return TryBuildLobby(val.m_steamIDLobby, out lobby); } } return false; } private static bool TryBuildLobby(CSteamID steamLobby, out Lobby lobby) { //IL_0001: 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_0016: 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) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_0075: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) lobby = default(Lobby); if (steamLobby == CSteamID.Nil) { return false; } SteamMatchmaking.RequestLobbyData(steamLobby); int num = SteamMatchmaking.GetLobbyMemberLimit(steamLobby); int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(steamLobby); if (num <= 0) { num = numLobbyMembers + 1; } Dictionary dictionary = new Dictionary(); int lobbyDataCount = SteamMatchmaking.GetLobbyDataCount(steamLobby); string key = default(string); string value = default(string); for (int i = 0; i < lobbyDataCount; i++) { if (SteamMatchmaking.GetLobbyDataByIndex(steamLobby, i, ref key, 256, ref value, 256)) { dictionary[key] = value; } } lobby = new Lobby { Name = SteamMatchmaking.GetLobbyData(steamLobby, "Name"), IsValid = true, lobbyId = steamLobby.m_SteamID.ToString(CultureInfo.InvariantCulture), MaxPlayers = num, Properties = dictionary, Members = new List() }; return true; } } internal sealed class FavoritesTabController { private const float ActiveTabHeight = 106.5f; private const float InactiveTabHeight = 81.4f; private MainMenuUIController _menu; private RectTransform _buttonJoinAll; private RectTransform _buttonJoinFriends; private RectTransform _buttonJoinFavorites; private GameObject _panelJoinAll; private GameObject _panelJoinFriends; private GameObject _panelJoinFavorites; private Transform _contentFavorites; private Color _activeColor; private Color _inactiveColor; private readonly List _favoriteRows = new List(); private bool _initialized; private bool _refreshRunning; private int _refreshToken; public bool IsFavoritesActive { get; private set; } public void EnsureInitialized(MainMenuUIController menu) { //IL_0065: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) if (_initialized || (Object)(object)menu == (Object)null) { return; } try { _menu = menu; _buttonJoinAll = GetField(menu, "_buttonJoinAll"); _buttonJoinFriends = GetField(menu, "_buttonJoinFriends"); _panelJoinAll = GetField(menu, "_panelJoinAll"); _panelJoinFriends = GetField(menu, "_panelJoinFriends"); _activeColor = GetField(menu, "_buttonActiveColor"); _inactiveColor = GetField(menu, "_buttonDeactiveColor"); if ((Object)(object)_buttonJoinAll == (Object)null || (Object)(object)_buttonJoinFriends == (Object)null || (Object)(object)_panelJoinAll == (Object)null || (Object)(object)_panelJoinFriends == (Object)null) { ServerFavoritesPlugin.Log.LogWarning((object)"Favorites tab init failed: missing join tab objects."); return; } CreateTabButton(); CreatePanel(menu); _initialized = true; ServerFavoritesPlugin.Log.LogInfo((object)"ServerFavorites Favorites tab created."); } catch (Exception ex) { ServerFavoritesPlugin.Log.LogError((object)("Favorites tab init error: " + ex)); } } private void CreateTabButton() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown _buttonJoinFavorites = Object.Instantiate(_buttonJoinAll, ((Transform)_buttonJoinAll).parent); ((Object)_buttonJoinFavorites).name = "ButtonJoinFavorites"; Rect rect = _buttonJoinAll.rect; float num = ((Rect)(ref rect)).width + 14f; Vector2 anchoredPosition = _buttonJoinAll.anchoredPosition; _buttonJoinFavorites.anchoredPosition = anchoredPosition; _buttonJoinAll.anchoredPosition = anchoredPosition + new Vector2(0f - num, 0f); _buttonJoinFavorites.sizeDelta = new Vector2(_buttonJoinAll.sizeDelta.x, 81.4f); SendTabToBack(_buttonJoinFavorites); StripLocalizers(((Component)_buttonJoinFavorites).gameObject); SetButtonLabel(_buttonJoinFavorites, "Favorites"); StyleTab(_buttonJoinFavorites, active: false); Button component = ((Component)_buttonJoinFavorites).GetComponent