Decompiled source of LethalLanFix v1.1.0

MLLoader/Mods/LanFix.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using LanFix;
using MelonLoader;
using TMPro;
using Unity.Netcode.Transports.UTP;
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: MelonInfo(typeof(LanFixMod), "LethalLanFix", "0.2.0", "jghhh", null)]
[assembly: MelonGame("ZeekerssRBLX", "Lethal Company")]
[assembly: AssemblyTitle("LanFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LanFix")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("32477e43-d5ae-4828-b4d0-50d8ee7b5f92")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LanFix;

public static class Global
{
	public static string address = "127.0.0.1";

	public static GameObject addressInput;
}
public class LanFixMod : MelonMod
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static UnityAction <>9__1_0;

		internal void <OnSceneWasInitialized>b__1_0()
		{
			Global.addressInput.SetActive(true);
		}
	}

	public override void OnLateInitializeMelon()
	{
		((MelonBase)this).LoggerInstance.Msg("LanFix Loaded");
		((MelonBase)this).LoggerInstance.Msg("Host Address = " + Global.address);
	}

	public override void OnSceneWasInitialized(int buildIndex, string sceneName)
	{
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Expected O, but got Unknown
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Expected O, but got Unknown
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Expected O, but got Unknown
		if (!(sceneName == "MainMenu") || !((Object)(object)GameObject.Find("LaunchedInLanModeText") != (Object)null))
		{
			return;
		}
		if ((Object)(object)GameObject.Find("AddressInput") == (Object)null)
		{
			GameObject val = GameObject.Find("LANWarning");
			Global.addressInput = Object.Instantiate<GameObject>(val, val.transform.position, val.transform.rotation, GameObject.Find("MenuContainer").transform);
			Global.addressInput.SetActive(false);
			((Object)Global.addressInput).name = "AddressInput";
			Image val2 = Global.addressInput.GetComponentsInChildren<Image>()[2];
			((TMP_Text)Global.addressInput.GetComponentInChildren<TextMeshProUGUI>()).text = "Type Server Address";
			Button componentInChildren = Global.addressInput.GetComponentInChildren<Button>();
			((Object)componentInChildren).name = "Cancel";
			((TMP_Text)((Component)componentInChildren).GetComponentInChildren<TextMeshProUGUI>()).text = "[ Cancel ]";
			Button val3 = Object.Instantiate<Button>(componentInChildren, ((Component)componentInChildren).transform.position, ((Component)componentInChildren).transform.rotation, ((Component)val2).transform);
			((Object)val3).name = "Connect";
			RectTransform component = ((Component)val3).GetComponent<RectTransform>();
			((Transform)component).localPosition = Vector2.op_Implicit(new Vector2(0f, -15f));
			((TMP_Text)((Component)val3).GetComponentInChildren<TextMeshProUGUI>()).text = "[ Connect ]";
			((UnityEvent)((Component)val3).GetComponent<Button>().onClick).AddListener(new UnityAction(ConnectToServer));
			TMP_InputField[] array = Resources.FindObjectsOfTypeAll<TMP_InputField>();
			GameObject val4 = null;
			TMP_InputField[] array2 = array;
			foreach (TMP_InputField val5 in array2)
			{
				if (((Object)((Component)((Component)val5).transform).gameObject).name == "ServerNameField")
				{
					val4 = ((Component)((Component)val5).transform).gameObject;
					break;
				}
			}
			GameObject val6 = Object.Instantiate<GameObject>(val4, val4.transform.position, val.transform.rotation, ((Component)val2).transform);
			((Object)val6).name = "AddressField";
			RectTransform component2 = val6.GetComponent<RectTransform>();
			((Transform)component2).localPosition = Vector2.op_Implicit(new Vector2(0f, 30f));
			TMP_InputField component3 = val6.GetComponent<TMP_InputField>();
			component3.placeholder = null;
			component3.text = Global.address;
			component3.onValueChanged = new OnChangeEvent();
			((UnityEvent<string>)(object)component3.onValueChanged).AddListener((UnityAction<string>)ChangeAddressValue);
		}
		Button component4 = GameObject.Find("StartLAN").GetComponent<Button>();
		component4.onClick = new ButtonClickedEvent();
		ButtonClickedEvent onClick = component4.onClick;
		object obj = <>c.<>9__1_0;
		if (obj == null)
		{
			UnityAction val7 = delegate
			{
				Global.addressInput.SetActive(true);
			};
			<>c.<>9__1_0 = val7;
			obj = (object)val7;
		}
		((UnityEvent)onClick).AddListener((UnityAction)obj);
	}

	public void ChangeAddressValue(string value)
	{
		Global.address = value;
	}

	public void ConnectToServer()
	{
		GameObject.Find("MenuManager").GetComponent<MenuManager>().StartAClient();
	}
}
[HarmonyPatch(typeof(MenuManager), "LAN_HostSetAllowRemoteConnections")]
public static class Patch
{
	private static void Postfix()
	{
		GameObject.Find("NetworkManager").GetComponent<UnityTransport>().ConnectionData.Address = Global.address;
	}
}