using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BetterFont")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Troca a fonte do jogo por uma serifada (Times New Roman ou similar) preservando a estilizacao (cor, contorno, sombra) dos textos.")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("BetterFont")]
[assembly: AssemblyTitle("BetterFont")]
[assembly: AssemblyVersion("1.0.4.0")]
namespace BetterFont;
[BepInPlugin("com.gumatos.betterfont", "Better Font", "1.0.4")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log { get; private set; }
internal static ConfigEntry<bool> PreservarEstilo { get; private set; }
internal static ConfigEntry<bool> PularTextosEstilizados { get; private set; }
internal static ConfigEntry<bool> LogDiagnosticoEstilo { get; private set; }
internal static bool PreservarEstiloLigado
{
get
{
if (PreservarEstilo != null)
{
return PreservarEstilo.Value;
}
return true;
}
}
internal static bool PularEstilizadosLigado
{
get
{
if (PularTextosEstilizados != null)
{
return PularTextosEstilizados.Value;
}
return true;
}
}
internal static bool LogDiagnosticoLigado
{
get
{
if (LogDiagnosticoEstilo != null)
{
return LogDiagnosticoEstilo.Value;
}
return false;
}
}
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
PreservarEstilo = BindSeguro("Estilo", "PreservarEstilo", padrao: true, "true = antes de trocar a fonte, copia as propriedades de ESTILO do material que o texto ja usava (cor de face _FaceColor, contorno _OutlineWidth/_OutlineSoftness/_OutlineColor, sombra _UnderlayColor/_UnderlayOffsetX/_UnderlayOffsetY/_UnderlayDilate/_UnderlaySoftness, _FaceDilate) para o material POR COMPONENTE da fonte nova (t.fontMaterial -- nunca o material compartilhado), e liga as keywords OUTLINE_ON/UNDERLAY_ON que estavam ativas. Em TextMeshPro trocar 'font' troca o MATERIAL junto, e o estilo do jogo vive no material. false = troca a fonte deixando o material novo como veio (comportamento da 1.0.0, que apagava cor/contorno/sombra).");
PularTextosEstilizados = BindSeguro("Estilo", "PularTextosEstilizados", padrao: false, "false (padrao) = troca a fonte TAMBEM dos textos cujo material e estilizado (material proprio, diferente do material padrao da fonte daquele componente, ou de uma VARIANTE de shader diferente do material da fonte serifada) e REAPLICA neles os efeitos de material que ja estavam ali (cor de face, contorno _OutlineWidth/_OutlineSoftness/_OutlineColor, sombra _UnderlayColor/_UnderlayOffsetX/Y/_UnderlayDilate/_UnderlaySoftness/UNDERLAY_INNER, recorte _ClipRect, offsets _VertexOffsetX/Y e as keywords OUTLINE_ON/UNDERLAY_ON, propriedade por propriedade com HasProperty), copiando para o material POR COMPONENTE da fonte nova. Variante de shader diferente NAO e recusa: e o caso dos textos de combate do jogo (fonte serifada = 'Mobile/Distance Field'; os alvos de combate usam 'Distance Field Overlay'/'Distance Field (Surface)') e as propriedades de estilo existem nas duas. E o que faz QUALQUER mod que tenha aplicado efeito antes continuar funcionando. O texto so NAO e tocado quando o material em uso traz um efeito que a copia nao reproduz (textura de face _FaceTex, bevel _BumpMap, GLOW_ON/BEVEL_ON) - e ai o motivo sai NOMEADO no log. true = ESCAPE, comportamento antigo da 1.0.1: NAO troca a fonte de quem tem material estilizado (o visual original fica 100% intacto, so nao ganha a serifa). Sem entrada no config (falha ao ler/criar), o getter seguro vale true - o CONSERVADOR; chave ausente no .cfg NAO cai aqui (o BepInEx cria a entrada com este default false). Para ver o que foi pulado, ligue LogDiagnosticoEstilo.");
LogDiagnosticoEstilo = BindSeguro("Diagnostico", "LogDiagnosticoEstilo", padrao: false, "true = loga um bloco por texto tratado: objeto, fonte, material compartilhado, shader, quais propriedades de estilo foram copiadas e quais existiam na origem mas NAO podem ser transportadas (ex.: _FaceTex, GLOW_ON, _GradientScale do atlas). Serve para conferir um texto especifico e para saber se algo ainda ficou diferente do original. Padrao: false (sem spam no log).");
((BaseUnityPlugin)this).Logger.LogInfo((object)($"Better Font carregado (v{((BaseUnityPlugin)this).Info.Metadata.Version}): preservar estilo={PreservarEstiloLigado}, " + $"pular textos estilizados={PularEstilizadosLigado}, diagnostico={LogDiagnosticoLigado}."));
AplicarPatches();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Better Font: o updater sera criado de forma PREGUICOSA no primeiro OptionsManager.Localize da UI (nunca no Awake: a Unity destroi GameObject criado durante o chainloader do BepInEx).");
}
private ConfigEntry<T> BindSeguro<T>(string secao, string chave, T padrao, string descricao)
{
try
{
return ((BaseUnityPlugin)this).Config.Bind<T>(secao, chave, padrao, descricao);
}
catch (Exception ex)
{
ManualLogSource log = Log;
string[] obj = new string[6] { "Better Font: falha ao ler/criar a chave '", chave, "' do config — usando o padrao (", null, null, null };
T val = padrao;
obj[3] = val?.ToString();
obj[4] = "): ";
obj[5] = ex.Message;
log.LogError((object)string.Concat(obj));
return null;
}
}
private static void AplicarPatches()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
Harmony val = new Harmony("com.gumatos.betterfont");
List<string> list = new List<string>();
int num = 0;
int num2 = 0;
int num3 = 0;
Type[] types;
try
{
types = typeof(Plugin).Assembly.GetTypes();
}
catch (Exception ex)
{
Log.LogError((object)("Better Font: nao deu para listar os tipos do mod — nenhum gancho aplicado: " + ex));
return;
}
foreach (Type type in types)
{
if (EhClasseDeGancho(type))
{
num++;
try
{
int num4 = val.CreateClassProcessor(type).Patch()?.Count ?? 0;
num3 += num4;
num2++;
Log.LogInfo((object)("Better Font: gancho aplicado — " + type.Name + " (" + num4 + " metodo(s) do jogo)."));
}
catch (Exception ex2)
{
list.Add(type.Name);
Log.LogError((object)("Better Font: FALHA ao aplicar o gancho " + type.Name + " — " + ex2.Message));
}
}
}
string text = "Better Font: patches Harmony aplicados (" + num2 + "/" + num + " ganchos, " + num3 + " metodos do jogo).";
if (list.Count == 0)
{
Log.LogInfo((object)text);
}
else
{
Log.LogError((object)(text + " GANCHOS QUE FALHARAM: " + string.Join(", ", list.ToArray()) + ". O mod continua de pe, mas o recurso que dependia deles nao existe nesta sessao."));
}
}
private static bool EhClasseDeGancho(Type tipo)
{
try
{
if (tipo == null || !tipo.IsClass)
{
return false;
}
return tipo.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0;
}
catch (Exception)
{
return false;
}
}
}
[HarmonyPatch(typeof(OptionsManager), "Localize")]
public static class LocalizeFontTrigger
{
private static void Postfix()
{
try
{
FontUpdater.Ensure();
}
catch
{
}
}
}
public class FontUpdater : MonoBehaviour
{
internal enum TipoLinhaDiag
{
Rotina,
Efeito,
Escape
}
private static bool _everDestroyed;
private static readonly string[] PropsCor = new string[3] { "_FaceColor", "_OutlineColor", "_UnderlayColor" };
private static readonly string[] PropsFloat = new string[11]
{
"_FaceDilate", "_OutlineWidth", "_OutlineSoftness", "_UnderlayOffsetX", "_UnderlayOffsetY", "_UnderlayDilate", "_UnderlaySoftness", "_VertexOffsetX", "_VertexOffsetY", "_MaskSoftnessX",
"_MaskSoftnessY"
};
private static readonly string[] PropsVetor = new string[1] { "_ClipRect" };
private static readonly string[] KeywordsMascara = new string[3] { "MASK_SOFT", "MASK_HARD", "MASK_TEX" };
private static readonly string[] PropsDeFonteRegistradas = new string[2] { "_WeightNormal", "_WeightBold" };
private float _lastSweep = -99f;
private TMP_FontAsset _serifFont;
private readonly HashSet<TMP_Text> _seenTexts = new HashSet<TMP_Text>();
private readonly HashSet<string> _diagVistos = new HashSet<string>();
private readonly HashSet<int> _puladosContados = new HashSet<int>();
private bool _loggedFirstSweep;
internal const int TetoDiagRotina = 120;
internal const int TetoDiagEfeito = 300;
internal const int TetoDiagEscape = 900;
private int _diagLinhas;
private int _diagLinhasDeEfeito;
private int _diagLinhasDeEscape;
private string _diagCena;
private readonly HashSet<string> _diagCortesAvisados = new HashSet<string>();
private bool _catalogoDoMaterialNovo;
public static FontUpdater Instance { get; private set; }
public static void Create()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
if (!((Object)(object)Instance != (Object)null))
{
GameObject val = new GameObject("BetterFont_Updater");
Object.DontDestroyOnLoad((Object)val);
val.AddComponent<FontUpdater>();
}
}
public static void Ensure()
{
if ((Object)(object)Instance == (Object)null)
{
if (_everDestroyed)
{
Plugin.Log.LogWarning((object)"Better Font: updater ausente — recriando (a Unity destruiu o anterior).");
}
Create();
}
Instance?.MaybeSweep();
}
private void Awake()
{
Instance = this;
Plugin.Log.LogInfo((object)"Better Font: updater criado.");
FontSweep();
}
private void Start()
{
Plugin.Log.LogInfo((object)"Better Font: Start() do updater chamado (objeto vivo na cena).");
}
private void OnDestroy()
{
Plugin.Log.LogWarning((object)"Better Font: updater DESTRUÍDO pela Unity.");
_everDestroyed = true;
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
}
public void MaybeSweep()
{
try
{
if (Time.realtimeSinceStartup - _lastSweep >= 2f)
{
_lastSweep = Time.realtimeSinceStartup;
FontSweep();
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Better Font erro: " + ex.Message + "\n" + ex.StackTrace));
}
}
private void Update()
{
try
{
if (Time.realtimeSinceStartup - _lastSweep >= 2f)
{
_lastSweep = Time.realtimeSinceStartup;
FontSweep();
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Better Font erro no Update: " + ex.Message + "\n" + ex.StackTrace));
}
}
private void FontSweep()
{
try
{
if ((Object)(object)_serifFont == (Object)null)
{
_serifFont = CreateSerifFont();
if ((Object)(object)_serifFont == (Object)null)
{
Plugin.Log.LogWarning((object)"Better Font: nenhuma fonte serifada disponível no SO.");
return;
}
if (_serifFont.fallbackFontAssetTable == null)
{
_serifFont.fallbackFontAssetTable = new List<TMP_FontAsset>();
}
CatalogoDoMaterialNovo();
}
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
TMP_Text[] array = Resources.FindObjectsOfTypeAll<TMP_Text>();
foreach (TMP_Text val in array)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
RegistrarFallback(val);
if ((Object)(object)val.font == (Object)(object)_serifFont)
{
num5++;
continue;
}
try
{
Material fontSharedMaterial = val.fontSharedMaterial;
TMP_FontAsset font = val.font;
string motivo;
bool num6 = EhEstilizado(fontSharedMaterial, font, out motivo);
bool flag = TemEfeitoNoMaterial(fontSharedMaterial);
if (num6 && Plugin.PularEstilizadosLigado)
{
if (ContarPuloUmaVez(val))
{
num2++;
Diagnostico("PULADO (escape: material estilizado: " + motivo + ")", val, font, fontSharedMaterial, "n/a (texto pulado: fonte e material nao foram tocados)", "n/a (texto pulado: nada foi transportado)", null, TipoLinhaDiag.Escape);
}
continue;
}
string motivo2 = null;
if (flag && !EstiloTransportavel(fontSharedMaterial, Plugin.PreservarEstiloLigado, out motivo2))
{
if (ContarPuloUmaVez(val))
{
num3++;
Diagnostico("PULADO (efeito do material nao transportavel: " + motivo2 + ")", val, font, fontSharedMaterial, "n/a (texto pulado: fonte e material nao foram tocados)", "n/a (texto pulado: nada foi transportado)", null, TipoLinhaDiag.Efeito);
}
continue;
}
string copiados = null;
string naoTransportados = null;
string registros = null;
try
{
val.font = _serifFont;
if (Plugin.PreservarEstiloLigado && (Object)(object)fontSharedMaterial != (Object)null && UsaMaterialDaFonteNova(val))
{
Material fontMaterial = val.fontMaterial;
if ((Object)(object)fontMaterial != (Object)null)
{
copiados = CopiarEstilo(fontSharedMaterial, fontMaterial, out naoTransportados, out registros);
val.UpdateMeshPadding();
((Graphic)val).SetVerticesDirty();
}
}
}
catch (Exception ex)
{
ReverterTexto(val, font, fontSharedMaterial);
if (ContarPuloUmaVez(val))
{
num4++;
Diagnostico("REVERTIDO (falha ao trocar a fonte/transportar o estilo — texto devolvido ao original: " + ex.GetType().Name + ": " + ex.Message + ")", val, font, fontSharedMaterial, "n/a (texto revertido: nada ficou aplicado)", "n/a (texto revertido: nada foi transportado)", null, flag ? TipoLinhaDiag.Efeito : TipoLinhaDiag.Rotina);
}
goto end_IL_00b4;
}
num++;
Diagnostico(flag ? "CONVERTIDO (efeito do material anterior transportado)" : "CONVERTIDO", val, font, fontSharedMaterial, copiados, naoTransportados, registros, flag ? TipoLinhaDiag.Efeito : TipoLinhaDiag.Rotina);
end_IL_00b4:;
}
catch (Exception ex2)
{
Plugin.Log.LogWarning((object)("Better Font: falha ao tratar um texto: " + ex2.GetType().Name + ": " + ex2.Message));
}
}
if (!_loggedFirstSweep)
{
_loggedFirstSweep = true;
Plugin.Log.LogInfo((object)$"Better Font: varredura aplicada ({_seenTexts.Count} textos vistos).");
}
if (num > 0 || num2 > 0 || num3 > 0 || num4 > 0)
{
Plugin.Log.LogInfo((object)($"Better Font: varredura — {num} texto(s) convertidos para a serifa" + (Plugin.PreservarEstiloLigado ? " (efeitos do material anterior transportados)" : string.Empty) + $", {num2} pulado(s) pelo escape (PularTextosEstilizados " + (Plugin.PularEstilizadosLigado ? "ligado" : "desligado") + "), " + $"{num3} intocado(s) por efeito nao transportavel, " + $"{num4} revertido(s) por falha ao aplicar (nada ficou pela metade), {num5} ja na serifa."));
}
}
catch (Exception ex3)
{
Plugin.Log.LogWarning((object)("Better Font erro: " + ex3.Message + "\n" + ex3.StackTrace));
}
}
private void RegistrarFallback(TMP_Text t)
{
if (_seenTexts.Contains(t))
{
return;
}
_seenTexts.Add(t);
try
{
if (_serifFont.fallbackFontAssetTable == null)
{
_serifFont.fallbackFontAssetTable = new List<TMP_FontAsset>();
}
if ((Object)(object)t.font != (Object)null && (Object)(object)t.font != (Object)(object)_serifFont && !_serifFont.fallbackFontAssetTable.Contains(t.font))
{
_serifFont.fallbackFontAssetTable.Add(t.font);
}
}
catch
{
}
}
private bool EhEstilizado(Material antigo, TMP_FontAsset fonteAntiga, out string motivo)
{
motivo = null;
if ((Object)(object)antigo == (Object)null)
{
return false;
}
if ((Object)(object)fonteAntiga != (Object)null && (Object)(object)((TMP_Asset)fonteAntiga).material != (Object)null && (Object)(object)antigo != (Object)(object)((TMP_Asset)fonteAntiga).material)
{
motivo = "material proprio '" + ((Object)antigo).name + "' (padrao da fonte '" + ((Object)fonteAntiga).name + "' = '" + ((Object)((TMP_Asset)fonteAntiga).material).name + "')";
return true;
}
Material val = (((Object)(object)_serifFont != (Object)null) ? ((TMP_Asset)_serifFont).material : null);
if ((Object)(object)val != (Object)null && (Object)(object)antigo.shader != (Object)(object)val.shader)
{
motivo = "shader '" + Nome(antigo.shader) + "' != '" + Nome(val.shader) + "' da fonte serifada";
return true;
}
return false;
}
private bool EstiloTransportavel(Material antigo, bool transporteLigado, out string motivo)
{
motivo = null;
try
{
if ((Object)(object)antigo == (Object)null)
{
return true;
}
if (antigo.HasProperty("_FaceTex") && TexturaDeEfeito(antigo.GetTexture("_FaceTex")))
{
motivo = "_FaceTex (textura de face) em uso — a copia nao transporta textura";
return false;
}
if (antigo.HasProperty("_BumpMap") && TexturaDeEfeito(antigo.GetTexture("_BumpMap")))
{
motivo = "_BumpMap (bevel) em uso — a copia nao transporta bevel";
return false;
}
if (antigo.IsKeywordEnabled("GLOW_ON"))
{
motivo = "GLOW_ON ligado — glow nao e transportado";
return false;
}
if (antigo.IsKeywordEnabled("BEVEL_ON"))
{
motivo = "BEVEL_ON ligado — bevel nao e transportado";
return false;
}
if (!transporteLigado)
{
return true;
}
Material val = (((Object)(object)_serifFont != (Object)null) ? ((TMP_Asset)_serifFont).material : null);
if ((Object)(object)val == (Object)null)
{
motivo = "a fonte serifada ainda nao tem material";
return false;
}
if ((antigo.IsKeywordEnabled("OUTLINE_ON") || ValorAtivo(antigo, "_OutlineWidth")) && !val.HasProperty("_OutlineWidth"))
{
motivo = "contorno em uso e o material novo nao expoe _OutlineWidth (fonte bitmap)";
return false;
}
if (SombraDesenhada(antigo) && !val.HasProperty("_UnderlaySoftness"))
{
motivo = "sombra em uso e o material novo nao expoe underlay";
return false;
}
return true;
}
catch (Exception ex)
{
motivo = "nao deu para conferir o efeito (" + ex.GetType().Name + ")";
return false;
}
}
private static bool TemEfeitoNoMaterial(Material m)
{
try
{
if ((Object)(object)m == (Object)null)
{
return false;
}
if (m.HasProperty("_FaceTex") && TexturaDeEfeito(m.GetTexture("_FaceTex")))
{
return true;
}
if (m.HasProperty("_BumpMap") && TexturaDeEfeito(m.GetTexture("_BumpMap")))
{
return true;
}
if (m.IsKeywordEnabled("GLOW_ON") || m.IsKeywordEnabled("BEVEL_ON"))
{
return true;
}
if (m.IsKeywordEnabled("OUTLINE_ON") || ValorAtivo(m, "_OutlineWidth") || ValorAtivo(m, "_OutlineSoftness"))
{
return true;
}
if (SombraDesenhada(m))
{
return true;
}
return false;
}
catch
{
return true;
}
}
private static bool TexturaDeEfeito(Texture tex)
{
try
{
if ((Object)(object)tex == (Object)null)
{
return false;
}
if ((Object)(object)tex == (Object)(object)Texture2D.whiteTexture || (Object)(object)tex == (Object)(object)Texture2D.normalTexture || (Object)(object)tex == (Object)(object)Texture2D.blackTexture || (Object)(object)tex == (Object)(object)Texture2D.grayTexture)
{
return false;
}
string text = (((Object)tex).name ?? string.Empty).Trim().ToLowerInvariant();
if (text == "white" || text.StartsWith("white ") || text == "bump" || text.StartsWith("bump ") || text == "gray" || text.StartsWith("gray ") || text == "black" || text.StartsWith("black ") || text.StartsWith("unity_") || text.StartsWith("unity default"))
{
return false;
}
return tex.width > 8 || tex.height > 8;
}
catch
{
return true;
}
}
private static string CopiarEstilo(Material antigo, Material novo, out string naoTransportados, out string registros)
{
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
List<string> list = new List<string>();
List<string> list2 = new List<string>();
List<string> list3 = new List<string>();
try
{
if ((Object)(object)antigo.shader != (Object)(object)novo.shader)
{
list3.Add("variante de shader '" + Nome(antigo.shader) + "' -> '" + Nome(novo.shader) + "' (transporte best-effort: cada propriedade so entra se a variante nova a expuser)");
}
}
catch
{
}
for (int i = 0; i < PropsCor.Length; i++)
{
string text = PropsCor[i];
if (antigo.HasProperty(text) && novo.HasProperty(text))
{
novo.SetColor(text, antigo.GetColor(text));
list.Add(text);
}
else if (antigo.HasProperty(text))
{
list2.Add(text + " (shader novo nao expoe)");
}
}
for (int j = 0; j < PropsFloat.Length; j++)
{
string text2 = PropsFloat[j];
if (antigo.HasProperty(text2) && novo.HasProperty(text2))
{
novo.SetFloat(text2, antigo.GetFloat(text2));
list.Add(text2);
}
else if (antigo.HasProperty(text2))
{
list2.Add(text2 + " (shader novo nao expoe)");
}
}
for (int k = 0; k < PropsVetor.Length; k++)
{
string text3 = PropsVetor[k];
if (antigo.HasProperty(text3) && novo.HasProperty(text3))
{
novo.SetVector(text3, antigo.GetVector(text3));
list.Add(text3);
}
else if (antigo.HasProperty(text3))
{
list2.Add(text3 + " (shader novo nao expoe)");
}
}
bool flag = antigo.IsKeywordEnabled("OUTLINE_ON") || ValorAtivo(antigo, "_OutlineWidth");
bool flag2 = SombraDesenhada(antigo);
if (flag && novo.HasProperty("_OutlineWidth"))
{
novo.EnableKeyword("OUTLINE_ON");
list.Add("OUTLINE_ON");
}
else if (flag)
{
list2.Add("OUTLINE_ON (shader novo sem _OutlineWidth: fonte bitmap)");
}
if (flag2 && novo.HasProperty("_UnderlaySoftness"))
{
novo.EnableKeyword("UNDERLAY_ON");
list.Add("UNDERLAY_ON");
}
else if (flag2)
{
list2.Add("UNDERLAY_ON (shader novo sem underlay)");
}
if (antigo.IsKeywordEnabled("UNDERLAY_INNER"))
{
novo.EnableKeyword("UNDERLAY_INNER");
list.Add("UNDERLAY_INNER");
if ((Object)(object)antigo.shader != (Object)(object)novo.shader)
{
list3.Add("UNDERLAY_INNER: keyword transportada, mas so tem efeito se a variante '" + Nome(novo.shader) + "' a declarar (senao a sombra sai 'outer')");
}
}
for (int l = 0; l < KeywordsMascara.Length; l++)
{
string text4 = KeywordsMascara[l];
if (antigo.IsKeywordEnabled(text4))
{
novo.EnableKeyword(text4);
list.Add(text4);
list3.Add(text4 + ": keyword de masking transportada; so tem efeito se a variante '" + Nome(novo.shader) + "' a declarar");
}
}
for (int m = 0; m < PropsDeFonteRegistradas.Length; m++)
{
RegistrarDiferenca(antigo, novo, list3, PropsDeFonteRegistradas[m], "parametro da fonte/atlas: fica o do novo (nao e efeito do texto)");
}
if (antigo.HasProperty("_FaceTex") && TexturaDeEfeito(antigo.GetTexture("_FaceTex")))
{
list2.Add("_FaceTex (textura de face)");
}
if (antigo.HasProperty("_BumpMap") && TexturaDeEfeito(antigo.GetTexture("_BumpMap")))
{
list2.Add("_BumpMap (bevel)");
}
if (antigo.IsKeywordEnabled("GLOW_ON"))
{
list2.Add("GLOW_ON");
}
if (antigo.IsKeywordEnabled("BEVEL_ON"))
{
list2.Add("BEVEL_ON");
}
if (antigo.HasProperty("_GradientScale") && novo.HasProperty("_GradientScale") && !Mathf.Approximately(antigo.GetFloat("_GradientScale"), novo.GetFloat("_GradientScale")))
{
list2.Add("_GradientScale origem=" + antigo.GetFloat("_GradientScale").ToString("0.##") + " novo=" + novo.GetFloat("_GradientScale").ToString("0.##") + " (fica o do atlas novo)");
}
naoTransportados = ((list2.Count > 0) ? string.Join("; ", list2.ToArray()) : null);
registros = ((list3.Count > 0) ? string.Join("; ", list3.ToArray()) : null);
if (list.Count <= 0)
{
return null;
}
return string.Join(", ", list.ToArray());
}
private static void RegistrarDiferenca(Material antigo, Material novo, List<string> registros, string prop, string motivo)
{
if (!((Object)(object)antigo == (Object)null) && !((Object)(object)novo == (Object)null) && registros != null && antigo.HasProperty(prop))
{
float num = antigo.GetFloat(prop);
bool flag = novo.HasProperty(prop);
float num2 = (flag ? novo.GetFloat(prop) : 0f);
if (!flag || !Mathf.Approximately(num, num2))
{
registros.Add(prop + " origem=" + num.ToString("0.###") + " novo=" + (flag ? num2.ToString("0.###") : "(propriedade ausente)") + " (" + motivo + ")" + (flag ? string.Empty : " — o shader novo nao expoe a propriedade"));
}
}
}
private static bool ValorAtivo(Material m, string prop)
{
if (m.HasProperty(prop))
{
return m.GetFloat(prop) > 0.0001f;
}
return false;
}
private static bool SombraDesenhada(Material m)
{
try
{
if ((Object)(object)m == (Object)null)
{
return false;
}
if (m.IsKeywordEnabled("UNDERLAY_ON") || m.IsKeywordEnabled("UNDERLAY_INNER"))
{
return true;
}
if (m.HasProperty("_UnderlayOffsetX") && Mathf.Abs(m.GetFloat("_UnderlayOffsetX")) > 0.0001f)
{
return true;
}
if (m.HasProperty("_UnderlayOffsetY") && Mathf.Abs(m.GetFloat("_UnderlayOffsetY")) > 0.0001f)
{
return true;
}
if (m.HasProperty("_UnderlayDilate") && Mathf.Abs(m.GetFloat("_UnderlayDilate")) > 0.0001f)
{
return true;
}
return false;
}
catch
{
return false;
}
}
private bool ContarPuloUmaVez(TMP_Text t)
{
try
{
return _puladosContados.Add(((Object)t).GetInstanceID());
}
catch
{
return true;
}
}
private bool UsaMaterialDaFonteNova(TMP_Text t)
{
try
{
Material fontSharedMaterial = t.fontSharedMaterial;
Texture val = (Texture)(object)(((Object)(object)_serifFont != (Object)null) ? _serifFont.atlasTexture : null);
if ((Object)(object)fontSharedMaterial == (Object)null || (Object)(object)val == (Object)null || !fontSharedMaterial.HasProperty("_MainTex"))
{
return false;
}
Texture texture = fontSharedMaterial.GetTexture("_MainTex");
return (Object)(object)texture != (Object)null && ((Object)texture).GetInstanceID() == ((Object)val).GetInstanceID();
}
catch
{
return false;
}
}
private static string Nome(Shader s)
{
if (!((Object)(object)s != (Object)null))
{
return "(sem shader)";
}
return ((Object)s).name;
}
private static string NomeObjeto(TMP_Text t)
{
try
{
return ((Object)(object)t != (Object)null && (Object)(object)((Component)t).gameObject != (Object)null) ? ((Object)((Component)t).gameObject).name : "(?)";
}
catch
{
return "(?)";
}
}
private void OrcamentoDoDiagnosticoPorCena()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
string name;
try
{
Scene activeScene = SceneManager.GetActiveScene();
name = ((Scene)(ref activeScene)).name;
}
catch
{
return;
}
if (!(name == _diagCena))
{
_diagCena = name;
_diagLinhas = 0;
_diagLinhasDeEfeito = 0;
_diagLinhasDeEscape = 0;
_diagCortesAvisados.Clear();
Plugin.Log.LogInfo((object)("Better Font [diag]: cena '" + (string.IsNullOrEmpty(name) ? "(sem nome)" : name) + "' — orcamento de diagnostico zerado (os tetos sao por cena)."));
}
}
private void Diagnostico(string situacao, TMP_Text t, TMP_FontAsset fonteAntiga, Material antigo, string copiados, string naoTransportados, string registros, TipoLinhaDiag tipo)
{
if (!Plugin.LogDiagnosticoLigado)
{
return;
}
OrcamentoDoDiagnosticoPorCena();
switch (tipo)
{
case TipoLinhaDiag.Efeito:
if (_diagLinhasDeEfeito >= 300)
{
AvisoDeCorte("de efeito", 300);
return;
}
break;
case TipoLinhaDiag.Escape:
if (_diagLinhasDeEscape >= 900)
{
AvisoDeCorte("pulado pelo escape", 900);
return;
}
break;
default:
if (_diagLinhas >= 120)
{
AvisoDeCorte("de rotina", 120);
return;
}
break;
}
string item;
try
{
item = situacao + "#" + ((Object)t).GetInstanceID();
}
catch
{
item = situacao + "#" + NomeObjeto(t);
}
if (_diagVistos.Add(item))
{
switch (tipo)
{
case TipoLinhaDiag.Efeito:
_diagLinhasDeEfeito++;
break;
case TipoLinhaDiag.Escape:
_diagLinhasDeEscape++;
break;
default:
_diagLinhas++;
break;
}
string text;
try
{
text = (((Object)(object)antigo != (Object)null) ? Nome(antigo.shader) : "(sem material)");
}
catch
{
text = "(shader indisponivel)";
}
string text2;
try
{
bool num = !situacao.StartsWith("PULADO", StringComparison.Ordinal) && !situacao.StartsWith("REVERTIDO", StringComparison.Ordinal);
Material val = (((Object)(object)_serifFont != (Object)null) ? ((TMP_Asset)_serifFont).material : null);
text2 = ((!num) ? "(variante nao trocada: material intocado)" : (((Object)(object)val != (Object)null) ? Nome(val.shader) : "(fonte serifada sem material)"));
}
catch
{
text2 = "(shader indisponivel)";
}
bool flag = false;
try
{
flag = t.enableVertexGradient;
}
catch
{
}
Plugin.Log.LogInfo((object)("[diag] " + situacao + " | objeto='" + NomeObjeto(t) + "' (" + ((object)t).GetType().Name + ") | fonte='" + (((Object)(object)fonteAntiga != (Object)null) ? ((Object)fonteAntiga).name : "(nula)") + "' -> '" + (((Object)(object)_serifFont != (Object)null) ? ((Object)_serifFont).name : "(nula)") + "' | material compartilhado='" + (((Object)(object)antigo != (Object)null) ? ((Object)antigo).name : "(nulo)") + "' | shader='" + text + "' -> '" + text2 + "' | " + $"gradiente de vertice={flag} | " + "copiados: " + (string.IsNullOrEmpty(copiados) ? "nenhum" : copiados) + " | nao transportados: " + (string.IsNullOrEmpty(naoTransportados) ? "nenhum" : naoTransportados) + " | registros: " + (string.IsNullOrEmpty(registros) ? "nenhum" : registros)));
}
}
private void AvisoDeCorte(string qual, int teto)
{
if (_diagCortesAvisados.Add(qual))
{
Plugin.Log.LogInfo((object)("Better Font [diag]: limite de " + teto + " linhas " + qual + " atingido — restante omitido (o resumo da varredura continua valendo)."));
}
}
private static void ReverterTexto(TMP_Text t, TMP_FontAsset fonteAntiga, Material antigo)
{
try
{
if ((Object)(object)fonteAntiga != (Object)null)
{
t.font = fonteAntiga;
}
}
catch
{
}
try
{
if ((Object)(object)antigo != (Object)null)
{
t.fontSharedMaterial = antigo;
}
}
catch
{
}
try
{
t.UpdateMeshPadding();
((Graphic)t).SetVerticesDirty();
}
catch
{
}
}
private void CatalogoDoMaterialNovo()
{
if (!Plugin.LogDiagnosticoLigado || _catalogoDoMaterialNovo)
{
return;
}
_catalogoDoMaterialNovo = true;
try
{
Material val = (((Object)(object)_serifFont != (Object)null) ? ((TMP_Asset)_serifFont).material : null);
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogInfo((object)"Better Font [diag]: a fonte serifada nao tem material — nao ha o que catalogar.");
return;
}
List<string> list = new List<string>();
for (int i = 0; i < PropsCor.Length; i++)
{
list.Add(PropsCor[i] + "=" + SimNao(val.HasProperty(PropsCor[i])));
}
for (int j = 0; j < PropsFloat.Length; j++)
{
list.Add(PropsFloat[j] + "=" + SimNao(val.HasProperty(PropsFloat[j])));
}
for (int k = 0; k < PropsVetor.Length; k++)
{
list.Add(PropsVetor[k] + "=" + SimNao(val.HasProperty(PropsVetor[k])));
}
for (int l = 0; l < PropsDeFonteRegistradas.Length; l++)
{
list.Add(PropsDeFonteRegistradas[l] + "=" + SimNao(val.HasProperty(PropsDeFonteRegistradas[l])));
}
Plugin.Log.LogInfo((object)("[diag] catalogo do material da fonte nova: fonte='" + (((Object)(object)_serifFont != (Object)null) ? ((Object)_serifFont).name : "(nula)") + "' shader='" + Nome(val.shader) + "' | expoe: " + string.Join(", ", list.ToArray()) + " | keywords do TMP nesta versao sao declaradas no shader, nao em propriedade (ver 'registros' nas linhas de texto)"));
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Better Font [diag]: catalogo do material novo falhou: " + ex.Message));
}
}
private static string SimNao(bool v)
{
if (!v)
{
return "nao";
}
return "sim";
}
private static void NomearFonteSerifada(TMP_FontAsset asset, string origem)
{
try
{
((Object)asset).name = "BetterFont Serif (" + origem + ")";
}
catch
{
}
}
private static TMP_FontAsset CreateSerifFont()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
string[] array = new string[3] { "C:/Windows/Fonts/times.ttf", "C:/Windows/Fonts/georgia.ttf", "C:/Windows/Fonts/LiberationSerif-Regular.ttf" };
foreach (string text in array)
{
try
{
if (!File.Exists(text))
{
continue;
}
Font val = new Font(text);
if (!((Object)(object)val == (Object)null))
{
TMP_FontAsset val2 = TMP_FontAsset.CreateFontAsset(val);
if ((Object)(object)val2 != (Object)null)
{
NomearFonteSerifada(val2, Path.GetFileName(text));
Plugin.Log.LogInfo((object)("Better Font: usando '" + text + "' como fonte serifada."));
return val2;
}
Plugin.Log.LogWarning((object)("Better Font: '" + text + "' carregou mas CreateFontAsset retornou null."));
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Better Font: '" + text + "' falhou: " + ex.GetType().Name + ": " + ex.Message));
}
}
array = new string[4] { "Times New Roman", "Georgia", "Liberation Serif", "Cambria" };
foreach (string text2 in array)
{
try
{
Font val3 = Font.CreateDynamicFontFromOSFont(text2, 36);
if (!((Object)(object)val3 == (Object)null))
{
TMP_FontAsset val4 = TMP_FontAsset.CreateFontAsset(val3);
if ((Object)(object)val4 != (Object)null)
{
NomearFonteSerifada(val4, text2);
Plugin.Log.LogInfo((object)("Better Font: usando '" + text2 + "' (OS) como fonte serifada."));
return val4;
}
}
}
catch (Exception ex2)
{
Plugin.Log.LogWarning((object)("Better Font: '" + text2 + "' falhou: " + ex2.GetType().Name + ": " + ex2.Message));
}
}
return null;
}
}