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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LeKAKiD")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Replace in-game font with other things")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: AssemblyInformationalVersion("1.2.4+d5fa67705b60c049a3e31d66d30cc939edaa91fb")]
[assembly: AssemblyProduct("FontPatcher")]
[assembly: AssemblyTitle("FontPatcher")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.4.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 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_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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 FontPatcher
{
[HarmonyPatch]
internal class FontLoader
{
private class FontBundle
{
public string BundleName;
public TMP_FontAsset Normal;
public TMP_FontAsset Transmit;
}
private static List<FontBundle> fontBundles = new List<FontBundle>();
private static Regex normalRegex;
private static Regex transmitRegex;
public static void Load()
{
try
{
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Config.ConfigFilePath), Plugin.configFontAssetPath.Value);
Plugin.LogInfo("Font path: " + text);
FileInfo[] files = new DirectoryInfo(text).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"),
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(Plugin.configNormalRegexPattern.Value);
transmitRegex = new Regex(Plugin.configTransmitRegexPattern.Value);
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", 1f);
((TMP_Asset)__instance).material.SetFloat("_UnderlayOffsetX", 0.1f);
string name = ((Object)__instance).name;
if (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 (transmitRegex.IsMatch(name))
{
if (!Plugin.configTransmitIngameFont.Value)
{
DisableFont(__instance);
}
int num2 = 0;
foreach (FontBundle fontBundle2 in fontBundles)
{
if (Object.op_Implicit((Object)(object)fontBundle2.Transmit) && !__instance.fallbackFontAssetTable.Contains(fontBundle2.Transmit))
{
__instance.fallbackFontAssetTable.Add(fontBundle2.Transmit);
num2++;
}
}
if (num2 > 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 = "lekakid.lcfontpatcher";
public const string Name = "FontPatcher";
public const string Version = "1.2.4";
}
[BepInPlugin("lekakid.lcfontpatcher", "FontPatcher", "1.2.4")]
internal class Plugin : BaseUnityPlugin
{
public static ConfigEntry<bool> configNormalIngameFont;
public static ConfigEntry<bool> configTransmitIngameFont;
public static ConfigEntry<string> configNormalRegexPattern;
public static ConfigEntry<string> configTransmitRegexPattern;
public static ConfigEntry<string> configFontAssetPath;
public static ConfigEntry<bool> configDebugLog;
public static Plugin Instance;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
configNormalIngameFont = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UsingNormalIngameFont", true, "Using in-game default normal font");
configTransmitIngameFont = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UsingTransmitIngameFont", true, "Using in-game default normal font");
configNormalRegexPattern = ((BaseUnityPlugin)this).Config.Bind<string>("Regex", "NormalFontNameRegex", "^(b|DialogueText|3270.*)$", "Normally, you don't neet to change it");
configTransmitRegexPattern = ((BaseUnityPlugin)this).Config.Bind<string>("Regex", "TransmitFontNameRegex", "^edunline.*$", "Normally, you don't neet to change it");
configFontAssetPath = ((BaseUnityPlugin)this).Config.Bind<string>("Path", "FontAssetsPath", "FontPatcher\\default", (ConfigDescription)null);
configDebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log", false, (ConfigDescription)null);
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 = "FontPatcher";
public const string PLUGIN_NAME = "FontPatcher";
public const string PLUGIN_VERSION = "1.2.4";
}
}