Decompiled source of LethalCompanyLAT v0.6.0

BepInEx/plugins/RTLC/RTLC.Font.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("RTLC.Font")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Replace in-game font with other things")]
[assembly: AssemblyFileVersion("1.1.5.0")]
[assembly: AssemblyInformationalVersion("1.1.5")]
[assembly: AssemblyProduct("RTLC.Font")]
[assembly: AssemblyTitle("RTLC.Font")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.5.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;
		}
	}
}
internal class ResourcePath
{
	public const string FontPath = "Bundles";

	public const string NormalFont = "3270_font";

	public const string TransmitFont = "eduline_font";
}
[HarmonyPatch(typeof(HUDManager))]
internal class HUDManagerPatch
{
	[HarmonyPostfix]
	[HarmonyPatch("OnEnable")]
	private static void PostfixOnEnable()
	{
		((UnityEvent<string>)(object)HUDManager.Instance.chatTextField.onSubmit).AddListener((UnityAction<string>)OnSubmitChat);
	}

	[HarmonyPostfix]
	[HarmonyPatch("OnDisable")]
	private static void PrefixOnDisable()
	{
		((UnityEvent<string>)(object)HUDManager.Instance.chatTextField.onSubmit).RemoveListener((UnityAction<string>)OnSubmitChat);
	}

	private static void OnSubmitChat(string chatString)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		if (!string.IsNullOrEmpty(chatString) && chatString.Length < 50)
		{
			HUDManager.Instance.AddTextToChatOnServer(chatString, (int)localPlayerController.playerClientId);
		}
		for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
		{
			if (StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled && Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)StartOfRound.Instance.allPlayerScripts[i]).transform.position) > 24.4f && (!GameNetworkManager.Instance.localPlayerController.holdingWalkieTalkie || !StartOfRound.Instance.allPlayerScripts[i].holdingWalkieTalkie))
			{
				HUDManager.Instance.playerCouldRecieveTextChatAnimator.SetTrigger("ping");
				break;
			}
		}
		localPlayerController.isTypingChat = false;
		HUDManager.Instance.chatTextField.text = "";
		EventSystem.current.SetSelectedGameObject((GameObject)null);
		HUDManager.Instance.PingHUDElement(HUDManager.Instance.Chat, 2f, 1f, 0.2f);
		((Behaviour)HUDManager.Instance.typingIndicator).enabled = false;
	}

	[HarmonyPrefix]
	[HarmonyPatch("SubmitChat_performed")]
	private static void PrefixSubmitChat_performed(ref bool __runOriginal)
	{
		__runOriginal = false;
	}
}
namespace RTLC.Font
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RTLC.Font";

		public const string PLUGIN_NAME = "RTLC.Font";

		public const string PLUGIN_VERSION = "1.1.5";
	}
}
namespace FontPatcher
{
	[HarmonyPatch]
	internal class FontLoader
	{
		private class FontBundle
		{
			public TMP_FontAsset Normal;

			public TMP_FontAsset Transmit;
		}

		private static List<FontBundle> fontBundles = new List<FontBundle>();

		public static void Load(string location)
		{
			try
			{
				string directoryName = Path.GetDirectoryName(location);
				string path = Path.Combine(directoryName, "Bundles");
				DirectoryInfo directoryInfo = new DirectoryInfo(path);
				FileInfo[] files = directoryInfo.GetFiles("rtlc.font");
				FileInfo[] array = files;
				foreach (FileInfo fileInfo in array)
				{
					AssetBundle val = AssetBundle.LoadFromFile(fileInfo.FullName);
					FontBundle fontBundle = new FontBundle
					{
						Normal = val.LoadAsset<TMP_FontAsset>("3270_font"),
						Transmit = val.LoadAsset<TMP_FontAsset>("eduline_font")
					};
					if (Object.op_Implicit((Object)(object)fontBundle.Normal))
					{
						((Object)fontBundle.Normal).name = fileInfo.Name + "(3270_font)";
					}
					if (Object.op_Implicit((Object)(object)fontBundle.Transmit))
					{
						((Object)fontBundle.Transmit).name = fileInfo.Name + "(eduline_font)";
					}
					fontBundles.Add(fontBundle);
				}
				Plugin.Instance.LogInfo("Font loaded!");
			}
			catch (Exception ex)
			{
				Plugin.Instance.LogError(ex.Message);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TMP_FontAsset), "Awake")]
		private static void PrefixAwake(TMP_FontAsset __instance)
		{
			switch (((Object)__instance).name.Split(new char[1] { ' ' })[0])
			{
			case "3270-Regular":
			case "3270-HUDIngame":
			case "3270-HUDIngameB":
			case "DialogueText":
			case "b":
				if (!Plugin.Instance.configNormalIngameFont.Value)
				{
					DisableFont(__instance);
				}
				{
					foreach (FontBundle fontBundle in fontBundles)
					{
						if (Object.op_Implicit((Object)(object)fontBundle.Normal))
						{
							__instance.fallbackFontAssetTable.Add(fontBundle.Normal);
						}
					}
					break;
				}
			case "edunline":
				if (!Plugin.Instance.configTransmitIngameFont.Value)
				{
					DisableFont(__instance);
				}
				{
					foreach (FontBundle fontBundle2 in fontBundles)
					{
						if (Object.op_Implicit((Object)(object)fontBundle2.Transmit))
						{
							__instance.fallbackFontAssetTable.Add(fontBundle2.Transmit);
						}
					}
					break;
				}
			}
		}

		private static void DisableFont(TMP_FontAsset font)
		{
			font.characterLookupTable.Clear();
			font.atlasPopulationMode = (AtlasPopulationMode)0;
		}
	}
	internal class PluginInfo
	{
		public const string GUID = "RTLC.Font";

		public const string Name = "RTLC.Font";

		public const string Version = "1.1.2";
	}
	[BepInPlugin("RTLC.Font", "RTLC.Font", "1.1.2")]
	internal class Plugin : BaseUnityPlugin
	{
		public ConfigEntry<bool> configNormalIngameFont;

		public ConfigEntry<bool> configTransmitIngameFont;

		public static Plugin Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			configNormalIngameFont = ((BaseUnityPlugin)this).Config.Bind<bool>("Шрифты", "Стандартный шрифт", false, "Вкл/Выкл стандартный игровой шрифт.");
			configTransmitIngameFont = ((BaseUnityPlugin)this).Config.Bind<bool>("Шрифты", "Шрифт транслятора", false, "Вкл/Выкл стандартный шрифт транслятора сигналов.");
			FontLoader.Load(((BaseUnityPlugin)this).Info.Location);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}

		public void LogInfo(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)msg);
		}

		public void LogWarning(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)msg);
		}

		public void LogError(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)msg);
		}
	}
}