Decompiled source of ModdedServerDependency v1.0.1

ModdedServerDependency.dll

Decompiled 6 hours ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using UnityEngine;
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: AssemblyTitle("ModdedServerDependency")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModdedServerDependency")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f3995401-5056-4609-908d-f77c5092ebb2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ModdedServerDependency;

[BepInPlugin("com.morsecodeguy.moddedserverdependency", "ModdedServerDependency", "1.0.0")]
public class ModdedServerDependency : BaseUnityPlugin
{
	private const string targetPanelName = "GameNameTextPanel";

	private const string moddedSuffix = "   [MODDED]";

	private InputField inputField;

	private void Start()
	{
		((MonoBehaviour)this).InvokeRepeating("CheckForGameNameTextPanel", 0f, 0.5f);
	}

	private void CheckForGameNameTextPanel()
	{
		if (!((Object)(object)inputField == (Object)null))
		{
			return;
		}
		GameObject val = GameObject.Find("GameNameTextPanel");
		if ((Object)(object)val != (Object)null)
		{
			Transform val2 = val.transform.Find("InputField (Legacy)");
			if ((Object)(object)val2 != (Object)null)
			{
				inputField = ((Component)val2).GetComponent<InputField>();
			}
		}
	}

	private void Update()
	{
		if ((Object)(object)inputField != (Object)null)
		{
			EnsureModdedText();
			RestrictCaretPosition();
		}
	}

	private void EnsureModdedText()
	{
		string text = inputField.text;
		if (text.Contains("   [MODDED]"))
		{
			text = text.Replace("   [MODDED]", "");
		}
		inputField.text = text + "   [MODDED]";
		inputField.caretPosition = Mathf.Clamp(inputField.text.Length - "   [MODDED]".Length, 0, inputField.text.Length);
	}

	private void RestrictCaretPosition()
	{
		int num = inputField.text.Length - "   [MODDED]".Length;
		if (inputField.caretPosition > num)
		{
			inputField.caretPosition = Mathf.Clamp(num, 0, num);
		}
		if (inputField.selectionAnchorPosition > num)
		{
			inputField.selectionAnchorPosition = num;
		}
		if (inputField.selectionFocusPosition > num)
		{
			inputField.selectionFocusPosition = num;
		}
	}
}