Decompiled source of ModdersToolKit v0.0.2

ModdersToolKit.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using HarmonyLib;
using MelonLoader;
using ModdersToolKit;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ModdersToolKit")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModdersToolKit")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: MelonInfo(typeof(Main), "Modder's Tool Kit", "0.0.2", "Zetalasis", null)]
[assembly: MelonGame("ZeekerssRBLX", "Lethal Company")]
[assembly: Guid("0116f259-7730-4782-a69b-0a1c5632f1f4")]
[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 ModdersToolKit;

public class Hook
{
	public string HookName { get; private set; }

	public string HookType { get; private set; }

	public string[] Arguments { get; private set; }

	public Action<string[]> Action { get; private set; }

	public Hook(string _name, string _type, Action<string[]> _action)
	{
		HookName = _name;
		HookType = _type;
		Action = _action;
	}
}
public class Hooks : MelonMod
{
	private static Hook[] hooks = new Hook[0];

	public static GameObject GetChatTextObject()
	{
		GameObject val = GameObject.Find("Systems");
		if ((Object)(object)val != (Object)null)
		{
			GameObject gameObject = ((Component)val.transform.Find("UI")).gameObject;
			if ((Object)(object)gameObject != (Object)null)
			{
				GameObject gameObject2 = ((Component)gameObject.transform.Find("Canvas")).gameObject;
				if ((Object)(object)gameObject2 != (Object)null)
				{
					GameObject gameObject3 = ((Component)gameObject2.transform.Find("IngamePlayerHUD")).gameObject;
					if ((Object)(object)gameObject3 != (Object)null)
					{
						GameObject gameObject4 = ((Component)gameObject3.transform.Find("BottomLeftCorner")).gameObject;
						if ((Object)(object)gameObject4 != (Object)null)
						{
							return ((Component)gameObject4.transform.Find("ChatText")).gameObject;
						}
					}
				}
			}
		}
		return null;
	}

	private static void AddHookToTable(Hook hook)
	{
		Array.Resize(ref hooks, hooks.Length + 1);
		hooks[hooks.Length - 1] = hook;
	}

	public override void OnInitializeMelon()
	{
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
	}

	public static void FireHook(string HookFireOn, string[] args)
	{
		Hook[] array = hooks;
		foreach (Hook hook in array)
		{
			if (hook.HookType == HookFireOn)
			{
				hook.Action(args);
			}
		}
	}

	public static MatchCollection getAllMessages(string currentText)
	{
		string pattern = "'.*'";
		return Regex.Matches(currentText, pattern);
	}

	public static MatchCollection getUsername(string currentText)
	{
		string pattern = ">.*\\b<";
		return Regex.Matches(currentText, pattern);
	}

	public static void AddHook(Action<string[]> HookFunction, string HookName, string FireOn)
	{
		Hook hook = new Hook(HookName, FireOn, HookFunction);
		AddHookToTable(hook);
	}
}
public class Loaders
{
	public void LoadSound(string name, AudioType type, AudioClip[] reference)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		MelonCoroutines.Start(LoadSoundCoroutine(name, type, reference, delegate(Main.AudioClipData audioClipData, AudioClip[] yourNewArgument)
		{
			OnSoundLoaded(audioClipData, yourNewArgument);
		}));
	}

	private void OnSoundLoaded(Main.AudioClipData audioClipData, AudioClip[] refr)
	{
		AudioClip clip = audioClipData.Clip;
		Array.Resize(ref Main.moddedMusic, Main.moddedMusic.Length + 1);
		Main.moddedMusic[Main.moddedMusic.Length - 1] = clip;
	}

	private IEnumerator LoadSoundCoroutine(string name, AudioType type, AudioClip[] reference, Action<Main.AudioClipData, AudioClip[]> onComplete)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		string path = "file://" + Application.streamingAssetsPath + "/CustomSounds/" + name;
		WWW url = new WWW(path);
		yield return url;
		if (string.IsNullOrEmpty(url.error))
		{
			AudioClip loadedClip = url.GetAudioClip();
			((Object)loadedClip).name = name;
			MelonLogger.Msg("Loaded " + name + " as an audio clip");
			Main.AudioClipData audioClipData = new Main.AudioClipData(loadedClip, reference);
			onComplete?.Invoke(audioClipData, reference);
		}
		else
		{
			MelonLogger.Error("Error loading sound: " + url.error);
		}
	}
}
public class ChatColors
{
	public string Value { get; private set; }

	public static string Red => "red_color";

	public static string Green => "green_color";

	public static string Blue => "blue_color";

	public static string Orange => "orange_color";

	public static string Purple => "purple_color";

	private ChatColors(string value)
	{
		Value = value;
	}

	public override string ToString()
	{
		return Value;
	}
}
public class Main : MelonMod
{
	public class AudioClipData
	{
		public AudioClip Clip { get; private set; }

		public AudioClip[] ClipArray { get; private set; }

		public AudioClipData(AudioClip singleClip, AudioClip[] clipArray)
		{
			Clip = singleClip;
			ClipArray = clipArray;
		}
	}

	public static AudioClip[] moddedMusic = (AudioClip[])(object)new AudioClip[0];

	private GameObject chatObject = null;

	private string currentText = "";

	private string oldText = "";

	public string sceneName = "";

	public static void SetModdedMusic(AudioClip[] setTo)
	{
		foreach (AudioClip val in setTo)
		{
			if (!moddedMusic.Contains(val))
			{
				int num = moddedMusic.Length;
				if (num < 0)
				{
					num = 0;
				}
				Array.Resize(ref moddedMusic, num + 1);
				moddedMusic[num] = val;
			}
		}
	}

	public override void OnInitializeMelon()
	{
	}

	public override void OnUpdate()
	{
		chatObject = Hooks.GetChatTextObject();
		if ((Object)(object)chatObject != (Object)null)
		{
			currentText = ((TMP_Text)chatObject.GetComponent<TextMeshProUGUI>()).text;
			MatchCollection allMessages = Hooks.getAllMessages(currentText);
			MatchCollection username = Hooks.getUsername(currentText);
			if (allMessages.Count > 0)
			{
				int num = allMessages.Count - 1;
				if (num < 0)
				{
					num = 0;
				}
				string text = username[num].ToString();
				text = text.Remove(0, 1);
				text = text.Remove(text.Length - 1);
				string text2 = allMessages[num].ToString();
				text2 = text2.Remove(0, 1);
				text2 = text2.Remove(text2.Length - 1);
				if (text2 != oldText)
				{
					string[] args = new string[2] { text, text2 };
					Hooks.FireHook("ChatMessageSend", args);
				}
				oldText = text2;
			}
		}
		PatchBoomboxes(moddedMusic);
	}

	public static void WriteToChat(string text)
	{
		GameObject chatTextObject = Hooks.GetChatTextObject();
		if ((Object)(object)chatTextObject != (Object)null)
		{
			((TMP_Text)chatTextObject.GetComponent<TextMeshProUGUI>()).text = text + "<br>" + text;
		}
	}

	public static bool IsIngame()
	{
		GameObject val = GameObject.Find("Environment");
		if ((Object)(object)val != (Object)null)
		{
			return true;
		}
		return false;
	}

	public override void OnSceneWasLoaded(int buildIndex, string _sceneName)
	{
		sceneName = _sceneName;
	}

	public static MenuManager GetMenuManager()
	{
		GameObject val = GameObject.Find("Canvas");
		if ((Object)(object)val != (Object)null)
		{
			GameObject val2 = GameObject.Find("MenuManager");
			if ((Object)(object)val2 != (Object)null)
			{
				return val2.GetComponent<MenuManager>();
			}
		}
		return null;
	}

	public static Item CreateItem(string name, int batteryUsage, Mesh itemMesh, AudioClip grabSFX, int itemID, int price)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		Item val = new Item();
		((Object)val).name = name;
		val.batteryUsage = batteryUsage;
		val.itemName = name;
		Mesh[] meshVariants = (Mesh[])(object)new Mesh[1] { itemMesh };
		val.meshVariants = meshVariants;
		val.grabSFX = grabSFX;
		val.itemId = itemID;
		val.creditsWorth = price;
		return val;
	}

	public static void RegisterItemInTerminal(Item itemToRegister)
	{
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Expected O, but got Unknown
		GameObject gameObject = ((Component)GameObject.Find("Environment").transform.Find("HangarShip").Find("Terminal").Find("TerminalTrigger")
			.Find("TerminalScript")).gameObject;
		Terminal component = gameObject.GetComponent<Terminal>();
		int num = component.buyableItemsList.Length;
		int num2 = component.itemSalesPercentages.Length;
		int num3 = component.terminalNodes.allKeywords.Length;
		if (num < 0)
		{
			num = 0;
		}
		if (num2 < 0)
		{
			num2 = 0;
		}
		if (num3 < 0)
		{
			num3 = 0;
		}
		Array.Resize(ref component.buyableItemsList, num + 1);
		Array.Resize(ref component.itemSalesPercentages, num2 + 1);
		Array.Resize(ref component.terminalNodes.allKeywords, num3 + 1);
		component.buyableItemsList[num] = itemToRegister;
		component.itemSalesPercentages[num2] = 100;
		TerminalKeyword val = new TerminalKeyword();
		val.word = itemToRegister.itemName.ToLower();
		component.terminalNodes.allKeywords[num3] = val;
		MelonLogger.Msg("Registered Item " + itemToRegister.itemName + " to terminal.");
	}

	public static void PatchBoomboxes(AudioClip[] moddedMusic)
	{
		BoomboxItem[] array = Object.FindObjectsOfType<BoomboxItem>();
		BoomboxItem[] array2 = array;
		foreach (BoomboxItem val in array2)
		{
			foreach (AudioClip val2 in moddedMusic)
			{
				if (!val.musicAudios.Contains(val2))
				{
					try
					{
						int num = val.musicAudios.Length;
						Array.Resize(ref val.musicAudios, val.musicAudios.Length + 1);
						val.musicAudios[num - 1] = val2;
						MelonLogger.Msg(((Object)val2).name);
					}
					catch (Exception ex)
					{
						string text = "Error: ";
						MelonLogger.Error(text + ex);
					}
				}
			}
		}
	}
}
public class Mixins
{
	public enum MixinType
	{
		Inject,
		Overwrite
	}

	public enum MixinInjectionPosition
	{
		Head,
		Tail
	}

	private static Harmony harmony = new Harmony("com.zetalasis.lethal_company_mtk_patches");

	public static void CreateMixin(MixinType type, MixinInjectionPosition position, object mixInto, object mixFrom)
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(mixInto.GetType(), "mixInto", (Type[])null, (Type[])null);
		if (type != 0)
		{
			return;
		}
		if (position == MixinInjectionPosition.Head)
		{
			MethodInfo methodInfo2 = SymbolExtensions.GetMethodInfo((Expression<Action>)(() => mixFrom.GetType()));
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		if (position == MixinInjectionPosition.Head)
		{
			MethodInfo methodInfo3 = SymbolExtensions.GetMethodInfo((Expression<Action>)(() => mixFrom.GetType()));
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo3), (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
}