using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[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.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("StuntedRaccoon.ServerBlocker")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.5.5.0")]
[assembly: AssemblyInformationalVersion("1.5.5+66f36a68e181bc51b2b2407350610a49a4741183")]
[assembly: AssemblyProduct("SrvrBlckr")]
[assembly: AssemblyTitle("StuntedRaccoon.ServerBlocker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 BlockServersByHost
{
[BepInPlugin("StuntedRaccoon.ServerBlocker", "SrvrBlckr", "1.5.5")]
public class Plugin : BaseUnityPlugin
{
[Serializable]
public class StringArrayWrapper
{
public string[] items;
public StringArrayWrapper(string[] _items)
{
items = _items;
}
}
[HarmonyPatch(typeof(LobbyDataEntry), "Awake")]
public static class LobbyDataEntry_Awake
{
public static void Postfix(LobbyDataEntry __instance)
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: 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_015b: Expected O, but got Unknown
//IL_0106: 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_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
Button joinLobbyButton = __instance._joinLobbyButton;
GameObject val = Object.Instantiate<GameObject>(((Component)joinLobbyButton).gameObject);
((Object)val).name = "BlockServerButton";
val.transform.SetParent(((Component)joinLobbyButton).gameObject.transform.parent, false);
Button component = val.GetComponent<Button>();
RectTransform component2 = val.GetComponent<RectTransform>();
val.transform.position = new Vector3(val.transform.position.x - 30f, val.transform.position.y + component2.sizeDelta.y - 6f, val.transform.position.z);
Text componentInChildren = val.GetComponentInChildren<Text>();
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.text = "Block Server";
}
if ((Object)(object)joinLobbyButton != (Object)null)
{
RectTransform component3 = ((Component)joinLobbyButton).GetComponent<RectTransform>();
if ((Object)(object)component3 != (Object)null)
{
component2.sizeDelta = component3.sizeDelta;
component2.sizeDelta = new Vector2(component2.sizeDelta.x - 4f, component2.sizeDelta.y - 12f);
}
}
((UnityEvent)component.onClick).AddListener((UnityAction)delegate
{
OnBlockButtonClick(__instance);
});
}
private static void OnBlockButtonClick(LobbyDataEntry lobbyData)
{
AddBlockedName(lobbyData._lobbyName);
LobbyListManager._current.Init_RefreshLobbyList();
}
}
[HarmonyPatch(typeof(SteamLobby), "GetLobbiesList")]
public static class SteamLobby_GetLobbiesList
{
public static void Prefix(ref SteamLobby __instance)
{
string[] blockedServerNames = BlockedServerNames;
foreach (string text in blockedServerNames)
{
SteamMatchmaking.AddRequestLobbyListStringFilter(SteamMatchmakingServerNameKey, text, (ELobbyComparison)3);
}
}
}
internal static ManualLogSource Logger;
private static HashSet<string> _blockedServerNames = new HashSet<string>();
private static string BlockedServerNamesFileName => "blockedServerNames.json";
public static string SteamMatchmakingServerNameKey => "name";
public static string[] BlockedServerNames => _blockedServerNames.ToArray();
public static void AddBlockedName(string serverName)
{
if (serverName == null)
{
Logger.LogError((object)"Server name was null");
return;
}
_blockedServerNames.Add(serverName);
Logger.LogMessage((object)(serverName + " added to blocked servers list."));
}
private bool LoadBlockedServerNames()
{
if (!File.Exists(BlockedServerNamesFileName))
{
FileStream fileStream = File.OpenWrite(BlockedServerNamesFileName);
fileStream.Close();
return false;
}
try
{
string text = File.ReadAllText(BlockedServerNamesFileName);
StringArrayWrapper stringArrayWrapper = JsonUtility.FromJson<StringArrayWrapper>(text);
string[] items = stringArrayWrapper.items;
string[] array = items;
foreach (string serverName in array)
{
AddBlockedName(serverName);
}
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to read " + BlockedServerNamesFileName + ": " + ex.Message));
FileStream fileStream = File.OpenWrite(BlockedServerNamesFileName);
fileStream.Close();
return false;
}
return true;
}
private void Awake()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin StuntedRaccoon.ServerBlocker is loaded!");
LoadBlockedServerNames();
Logger.LogWarning((object)("To stop blocking server(s), remove the server from '" + BlockedServerNamesFileName + "' OR delete file '" + BlockedServerNamesFileName + "' from your ATLYSS root directory to unblock all."));
Harmony val = new Harmony("StuntedRaccoon.ServerBlocker");
val.PatchAll();
}
private void OnDestroy()
{
try
{
StreamWriter streamWriter = new StreamWriter(BlockedServerNamesFileName);
string[] items = BlockedServerNames.ToArray();
StringArrayWrapper stringArrayWrapper = new StringArrayWrapper(items);
string value = JsonUtility.ToJson((object)stringArrayWrapper);
streamWriter.Write(value);
streamWriter.Close();
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to read " + BlockedServerNamesFileName + ": " + ex.Message));
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "StuntedRaccoon.ServerBlocker";
public const string PLUGIN_NAME = "SrvrBlckr";
public const string PLUGIN_VERSION = "1.5.5";
}
}