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 System.Text;
using System.Text.RegularExpressions;
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 = "")]
[assembly: AssemblyCompany("rectorado")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Updates LC's font, adding the expanded latin unicode characters list.")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyInformationalVersion("0.7.0")]
[assembly: AssemblyProduct("FontUpdate")]
[assembly: AssemblyTitle("FontUpdate")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.7.0.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 NormalFont = "Normal";
public const string NoDollarFont = "NoDollar";
public const string TransmitFont = "Transmit";
}
[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 FontUpdate
{
[HarmonyPatch]
internal class FontLoader
{
private class FontBundle
{
public string BundleName;
public TMP_FontAsset Normal;
public TMP_FontAsset NoDollar;
public TMP_FontAsset Transmit;
}
private static List<FontBundle> fontBundles = new List<FontBundle>();
private static Regex normalRegex;
private static Regex transmitRegex;
private static Regex noDollarRegex;
public static void Load()
{
try
{
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Config.ConfigFilePath);
string text = Path.Combine(directoryName, "FontUpdate");
Plugin.LogInfo("Font path: " + text);
DirectoryInfo directoryInfo = new DirectoryInfo(text);
FileInfo[] files = directoryInfo.GetFiles("*");
int num = 0;
int num2 = 0;
FileInfo[] array = files;
foreach (FileInfo fileInfo in array)
{
try
{
AssetBundle val = AssetBundle.LoadFromFile(fileInfo.FullName);
Plugin.LogInfo("[" + fileInfo.Name + "] loaded");
FontBundle fontBundle = new FontBundle
{
Normal = val.LoadAsset<TMP_FontAsset>("Normal"),
NoDollar = val.LoadAsset<TMP_FontAsset>("NoDollar"),
Transmit = val.LoadAsset<TMP_FontAsset>("Transmit")
};
if (Object.op_Implicit((Object)(object)fontBundle.Normal))
{
fontBundle.BundleName = fileInfo.Name;
((Object)fontBundle.Normal).name = fileInfo.Name + "(Normal)";
Plugin.LogInfo("[" + fileInfo.Name + "] Normal font found (" + ((Object)fontBundle.Normal).name + ")");
}
if (Object.op_Implicit((Object)(object)fontBundle.Transmit))
{
fontBundle.BundleName = fileInfo.Name;
((Object)fontBundle.Transmit).name = fileInfo.Name + "(Transmit)";
Plugin.LogInfo("[" + fileInfo.Name + "] Transmit font found (" + ((Object)fontBundle.Transmit).name + ")");
}
if (fontBundle.BundleName == null)
{
throw new Exception("Not included recognizable font");
}
fontBundles.Add(fontBundle);
num++;
}
catch (Exception ex)
{
Plugin.LogError("[" + fileInfo.Name + "] load failed: " + ex.Message);
num2++;
}
}
normalRegex = new Regex("^(b|DialogueText|3270.*)$");
noDollarRegex = new Regex("^(b|DialogueText|3270.*)$");
transmitRegex = new Regex("^edunline.*$");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append($"{num} fonts loaded");
if (num2 > 0)
{
stringBuilder.Append($", {num2} fonts load failed");
}
Plugin.LogInfo(stringBuilder.ToString());
}
catch (Exception ex2)
{
Plugin.LogError(ex2.ToString());
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(TMP_FontAsset), "Awake")]
private static void PatchFontAwake(TMP_FontAsset __instance)
{
((TMP_Asset)__instance).material.SetFloat("_UnderlayDilate", 0.8f);
((TMP_Asset)__instance).material.SetFloat("_UnderlayOffsetX", 0.01f);
string name = ((Object)__instance).name;
if (Plugin.configFontMode.Value == FontMode.Normal && normalRegex.IsMatch(name))
{
if (!Plugin.configNormalIngameFont.Value)
{
DisableFont(__instance);
}
int num = 0;
foreach (FontBundle fontBundle in fontBundles)
{
if (Object.op_Implicit((Object)(object)fontBundle.Normal) && !__instance.fallbackFontAssetTable.Contains(fontBundle.Normal))
{
__instance.fallbackFontAssetTable.Add(fontBundle.Normal);
num++;
}
}
if (num > 0)
{
Plugin.LogInfo("[" + name + "] font patched (Normal)");
}
}
else if (Plugin.configFontMode.Value == FontMode.NoDollar && noDollarRegex.IsMatch(name))
{
int num2 = 0;
foreach (FontBundle fontBundle2 in fontBundles)
{
if (Object.op_Implicit((Object)(object)fontBundle2.NoDollar) && !__instance.fallbackFontAssetTable.Contains(fontBundle2.NoDollar))
{
__instance.fallbackFontAssetTable.Add(fontBundle2.NoDollar);
num2++;
}
}
if (num2 > 0)
{
Plugin.LogInfo("[" + name + "] font patched (NoDollar)");
}
}
else if (transmitRegex.IsMatch(name))
{
if (!Plugin.configTransmitIngameFont.Value)
{
DisableFont(__instance);
}
int num3 = 0;
foreach (FontBundle fontBundle3 in fontBundles)
{
if (Object.op_Implicit((Object)(object)fontBundle3.Transmit) && !__instance.fallbackFontAssetTable.Contains(fontBundle3.Transmit))
{
__instance.fallbackFontAssetTable.Add(fontBundle3.Transmit);
num3++;
}
}
if (num3 > 0)
{
Plugin.LogInfo("[" + name + "] font patched (Transmit)");
}
}
else
{
Plugin.LogWarning("[" + name + "] not patched");
}
}
[HarmonyPostfix]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static void PatchTextFontSetter(TMP_FontAsset value)
{
PatchFontAwake(value);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
private static void PatchTextAwake(TextMeshProUGUI __instance)
{
if (!((Object)(object)((TMP_Text)__instance).font == (Object)null))
{
PatchFontAwake(((TMP_Text)__instance).font);
}
}
private static void DisableFont(TMP_FontAsset font)
{
font.characterLookupTable.Clear();
font.atlasPopulationMode = (AtlasPopulationMode)0;
}
}
internal class PluginInfo
{
public const string GUID = "rectorado.FontUpdate";
public const string Name = "FontUpdate";
public const string Version = "0.7.0";
}
public enum FontMode
{
Normal,
NoDollar
}
public static class FontRegexPatterns
{
public const string NormalRegexPattern = "^(b|DialogueText|3270.*)$";
public const string NoDollarRegexPattern = "^(b|DialogueText|3270.*)$";
public const string TransmitRegexPattern = "^edunline.*$";
}
public static class FontPaths
{
public const string FontAssetPath = "FontUpdate";
}
[BepInPlugin("rectorado.FontUpdate", "FontUpdate", "0.7.0")]
internal class Plugin : BaseUnityPlugin
{
public static ConfigEntry<bool> configNormalIngameFont;
public static ConfigEntry<bool> configTransmitIngameFont;
public static ConfigEntry<FontMode> configFontMode;
public static ConfigEntry<bool> configDebugLog;
public static Plugin Instance;
private void Awake()
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
configFontMode = ((BaseUnityPlugin)this).Config.Bind<FontMode>("General", "FontMode", FontMode.Normal, "Normal: Updated font, NoDollar: Updated font without dollar sign, might fix some compatibility issues with other mods");
configNormalIngameFont = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Use Default Font", false, "Uses the vanilla font, mainly for testing purposes");
configTransmitIngameFont = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UsingTransmitIngameFont", true, "Uses the vanilla font, don't deactivate this as it will break the font");
configDebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log", false, new ConfigDescription("", (AcceptableValueBase)null, Array.Empty<object>()));
FontLoader.Load();
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
}
public static void LogInfo(string msg)
{
if (configDebugLog.Value)
{
((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
}
}
public static void LogWarning(string msg)
{
if (configDebugLog.Value)
{
((BaseUnityPlugin)Instance).Logger.LogWarning((object)msg);
}
}
public static void LogError(string msg)
{
((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "FontUpdate";
public const string PLUGIN_NAME = "FontUpdate";
public const string PLUGIN_VERSION = "0.7.0";
}
}