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 BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("LCWhitelist")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LCWhitelist")]
[assembly: AssemblyTitle("LCWhitelist")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 Eyan17
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "LCWhitelist";
public const string PLUGIN_NAME = "LCWhitelist";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace LethalCompanyTemplate
{
[BepInPlugin("Eyan17.whitelist", "Whitelist", "1.1.2")]
internal class Whitelist : BaseUnityPlugin
{
private const string modGUID = "Eyan17.whitelist";
private const string modName = "Whitelist";
private const string modVersion = "1.1.2";
internal static Whitelist instance;
internal static ManualLogSource mls;
public static List<string> loadedWhitelist;
internal ConfigEntry<bool> configWhitelistToggle;
internal ConfigEntry<string> configWhitelist;
private void Awake()
{
instance = this;
mls = Logger.CreateLogSource("Whitelist");
mls.LogInfo((object)"The whitelist has been initiated.");
configWhitelistToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "isWhitelistOn", true, "Toggles whether the whitelist is on. (Value can be changed mid-game)");
configWhitelist = ((BaseUnityPlugin)this).Config.Bind<string>("Whitelist", "allowedUsenames", "Player", "A list of usernames seperated by a semicolon. All spaces before and after the name are trimmed and the username should be written without any numbers, underscores etc. (Value can be changed mid-game)");
ReadConfigFile();
Harmony.CreateAndPatchAll(typeof(PlayerControllerPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(GameNetworkManagerPatch), (string)null);
mls.LogInfo((object)"Patches were applied.");
}
internal void ReadConfigFile()
{
mls.LogMessage((object)"Reading config file.");
((BaseUnityPlugin)this).Config.Reload();
loadedWhitelist = splitString(configWhitelist.Value);
mls.LogMessage((object)"Whitelisted players:");
for (int i = 0; i < loadedWhitelist.Count; i++)
{
mls.LogMessage((object)loadedWhitelist[i]);
}
}
private static List<string> splitString(string input)
{
List<string> list = new List<string>();
string text = "";
bool flag = false;
for (int i = 0; i < input.Length; i++)
{
char c = input[i];
if (c == '\\' && !flag)
{
flag = true;
}
else if (c == ';' && !flag)
{
list.Add(text.Trim());
text = "";
}
else if (c == '\\' && flag)
{
text += c;
flag = false;
}
else
{
text += c;
flag = false;
}
}
list.Add(text.Trim());
return list;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerPatch
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void UpdatePatch(ref string ___playerUsername, ref ulong ___actualClientId, ref bool ___isPlayerControlled)
{
if (___actualClientId != 0L && ___isPlayerControlled && Whitelist.instance.configWhitelistToggle.Value && !NetworkManager.Singleton.IsClient && !Enumerable.Contains(Whitelist.loadedWhitelist, ___playerUsername))
{
NetworkManager.Singleton.DisconnectClient(___actualClientId, "Not on whitelist.");
Whitelist.mls.LogInfo((object)("Disconnected " + ___playerUsername + "; Client id: " + ___actualClientId));
}
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPatch("ConnectionApproval")]
[HarmonyPostfix]
private static void ConnectionApprovalPatch(ConnectionApprovalResponse __0)
{
Whitelist.instance.ReadConfigFile();
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}