Decompiled source of NoServerPassword v1.0.3

IronLabs.NoServerPassword.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GUIFramework;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("IronLabs.NoServerPassword")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IronLabs.NoServerPassword")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("C424AE43-8596-4E8C-9517-0B4BF2927364")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.3.0")]
namespace IronLabs.NoServerPassword;

[HarmonyPatch(typeof(FejdStartup), "GetPublicPasswordError")]
internal static class PublicPasswordErrorPatch
{
	private static bool Prefix(string password, ref string __result)
	{
		if (!string.IsNullOrEmpty(password))
		{
			return true;
		}
		__result = string.Empty;
		return false;
	}
}
[HarmonyPatch(typeof(FejdStartup), "IsPublicPasswordValid")]
internal static class PublicPasswordValidationPatch
{
	private static bool Prefix(string password, ref bool __result)
	{
		if (!string.IsNullOrEmpty(password))
		{
			return true;
		}
		__result = true;
		return false;
	}
}
[HarmonyPatch(typeof(FejdStartup), "CanStartServer")]
internal static class CanStartServerPatch
{
	private static void Postfix(GuiInputField ___m_serverPassword, World ___m_world, ref bool __result)
	{
		if (!__result && IsEmpty(___m_serverPassword) && CanStartWorld(___m_world))
		{
			__result = true;
		}
	}

	private static bool IsEmpty(GuiInputField passwordField)
	{
		return string.IsNullOrEmpty((passwordField != null) ? ((TMP_InputField)passwordField).text : null);
	}

	private static bool CanStartWorld(World world)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Invalid comparison between Unknown and I4
		if (world != null)
		{
			return (int)world.m_dataError == 0;
		}
		return false;
	}
}
[HarmonyPatch(typeof(FejdStartup), "UpdatePasswordError")]
internal static class PasswordErrorDisplayPatch
{
	private static void Postfix(GuiInputField ___m_serverPassword, TMP_Text ___m_passwordError)
	{
		if (string.IsNullOrEmpty((___m_serverPassword != null) ? ((TMP_InputField)___m_serverPassword).text : null) && (Object)(object)___m_passwordError != (Object)null)
		{
			___m_passwordError.text = string.Empty;
		}
	}
}
internal static class ModLog
{
	private static ManualLogSource _logger;

	private static string _pluginName;

	internal static void Initialize(ManualLogSource logger, string pluginName)
	{
		_logger = logger;
		_pluginName = pluginName;
	}

	internal static void Clear()
	{
		_logger = null;
		_pluginName = null;
	}

	internal static void LogDebug(object message)
	{
		Write((LogLevel)32, message);
	}

	internal static void LogInfo(object message)
	{
		Write((LogLevel)16, message);
	}

	private static void Write(LogLevel level, object message)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource logger = _logger;
		if (logger != null)
		{
			logger.Log(level, message);
		}
	}
}
[BepInPlugin("IronLabs.NoServerPassword", "IronLabs.NoServerPassword", "1.0.3")]
public sealed class NoServerPasswordPlugin : BaseUnityPlugin
{
	private const string PluginGuid = "IronLabs.NoServerPassword";

	private const string PluginName = "IronLabs.NoServerPassword";

	private const string PluginVersion = "1.0.3";

	private readonly Harmony _harmony = new Harmony("IronLabs.NoServerPassword");

	private static bool _patchesApplied;

	private void Awake()
	{
		ModLog.Initialize(((BaseUnityPlugin)this).Logger, "IronLabs.NoServerPassword");
		PatchOwnNamespace();
		ModLog.LogInfo("IronLabs.NoServerPassword 1.0.3 is loaded.");
	}

	private void PatchOwnNamespace()
	{
		if (_patchesApplied)
		{
			ModLog.LogDebug("Harmony patches are already active; skipping registration.");
			return;
		}
		string text = typeof(NoServerPasswordPlugin).Namespace;
		Type[] types = Assembly.GetExecutingAssembly().GetTypes();
		foreach (Type type in types)
		{
			if (type.Namespace == text)
			{
				_harmony.CreateClassProcessor(type).Patch();
			}
		}
		_patchesApplied = true;
		ModLog.LogDebug("Harmony patches were applied for the plugin namespace.");
	}

	private void OnDestroy()
	{
		if (_patchesApplied)
		{
			_harmony.UnpatchSelf();
			_patchesApplied = false;
		}
		ModLog.Clear();
	}
}