Decompiled source of LobbyOffensiveNames v1.0.5

BepInEx/plugins/LobbyOffensiveNames/LobbyOffensiveNames.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("LobbyOffensiveNames")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+964cfe48072290f8bd413b8e4e2d434232cd885a")]
[assembly: AssemblyProduct("LobbyOffensiveNames")]
[assembly: AssemblyTitle("LobbyOffensiveNames")]
[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 LobbyOffensiveNames
{
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LobbyOffensiveNames";

		public const string PLUGIN_NAME = "LobbyOffensiveNames";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
namespace LobbyInviteOnly
{
	[BepInPlugin("Dev1A3.LobbyOffensiveNames", "LobbyOffensiveNames", "1.0.1")]
	internal class PluginLoader : BaseUnityPlugin
	{
		private const string modGUID = "Dev1A3.LobbyOffensiveNames";

		private readonly Harmony harmony = new Harmony("Dev1A3.LobbyOffensiveNames");

		private const string modVersion = "1.0.1";

		private static bool initialized;

		public static PluginLoader Instance { get; private set; }

		private void Awake()
		{
			if (!initialized)
			{
				initialized = true;
				Instance = this;
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				harmony.PatchAll(executingAssembly);
				OffensiveNamesConfig.InitConfig();
			}
		}

		public void BindConfig<T>(ref ConfigEntry<T> config, string section, string key, T defaultValue, string description = "")
		{
			config = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description);
		}
	}
	internal class OffensiveNamesConfig
	{
		public static ConfigEntry<bool> FilterEnabled;

		public static ConfigEntry<string> FilterTerms;

		public static string[] BlockedTermsRaw;

		public static void InitConfig()
		{
			PluginLoader.Instance.BindConfig(ref FilterEnabled, "Settings", "Filter Enabled", defaultValue: true, "Should the offensive lobby name filter be enabled?");
			PluginLoader.Instance.BindConfig(ref FilterTerms, "Settings", "Filter Terms", "nigger,nigga,n1g,nigers,negro,faggot,minors,chink,buttrape,molest,beastiality,cocks,cumshot,ejaculate,pedophile,furfag,necrophilia,yiff", "This should be a comma-separated list. Leaving this blank will also disable the filter.");
			BlockedTermsRaw = (from x in FilterTerms.Value.Split(',')
				select x.Trim() into x
				where x.Length > 0
				select x).ToArray();
		}
	}
	[HarmonyPatch]
	internal static class SteamLobbyManagerStart_Patch
	{
		[HarmonyPatch(typeof(SteamLobbyManager), "OnEnable")]
		[HarmonyPrefix]
		private static void Prefix(ref SteamLobbyManager __instance)
		{
			__instance.censorOffensiveLobbyNames = OffensiveNamesConfig.FilterEnabled.Value && OffensiveNamesConfig.BlockedTermsRaw.Length != 0;
		}
	}
	[HarmonyPatch]
	public static class loadLobbyListAndFilter_Patch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> TranspileMoveNext(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>();
			int num = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (num-- <= 0)
				{
					int num2 = 23;
					if (instruction.opcode == OpCodes.Ldc_I4_S && (sbyte)instruction.operand == num2)
					{
						Debug.Log((object)"Replaced offensiveWords");
						list.Add(new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(OffensiveNamesConfig), "BlockedTermsRaw")));
						num = num2 * 4 + 1;
					}
					else
					{
						list.Add(instruction);
					}
				}
			}
			return list.AsEnumerable();
		}
	}
}