Decompiled source of FixGameTranslate v1.0.0

FixGameTranslate.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using GameTranslator;
using HarmonyLib;
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("FixGameTranslate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FixGameTranslate")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6964290d-06d4-4810-84f0-aaf3de08e041")]
[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 FixGameTranslate;

[BepInPlugin("FixGameTranslate", "FixGameTranslate", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class FixGameTranslatePlugin : BaseUnityPlugin
{
	public static ManualLogSource ManualLog;

	public void Awake()
	{
		ManualLog = ((BaseUnityPlugin)this).Logger;
		Harmony.CreateAndPatchAll(typeof(TranslateImmediatePatch), (string)null);
	}
}
[HarmonyPatch]
public class TranslateImmediatePatch
{
	public static List<TMP_FontAsset> TMP_Font { get; set; }

	private static MethodBase TargetMethod()
	{
		Type type = AccessTools.TypeByName("GameTranslator.Patches.Utils.TextTranslate");
		return AccessTools.Method(type, "TranslateImmediate", (Type[])null, (Type[])null);
	}

	private static void Postfix(string text, ref string __result)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		if (TranslatePlugin.changeFont != null && TranslatePlugin.changeFont.Value && TMP_Font == null)
		{
			Type type = AccessTools.TypeByName("GameTranslator.Patches.Utils.FontCache");
			TMP_FontAsset val = (TMP_FontAsset)AccessTools.Method(type, "GetOrCreateOverrideFontTextMeshPro", (Type[])null, (Type[])null).Invoke(null, null);
			TMP_Font = new List<TMP_FontAsset>();
			Dictionary<uint, TMP_Character> characterLookupTable = val.characterLookupTable;
			TMP_Font.Add(val);
			if (val.fallbackFontAssetTable != null)
			{
				foreach (TMP_FontAsset item2 in val.fallbackFontAssetTable)
				{
					if (!TMP_Font.Any((TMP_FontAsset x) => ((Object)x).name == ((Object)item2).name))
					{
						characterLookupTable = item2.characterLookupTable;
						TMP_Font.Add(item2);
					}
				}
			}
		}
		if (TMP_Font != null)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (char item in text)
			{
				if (TMP_Font.Any((TMP_FontAsset x) => x.HasCharacter((int)item)))
				{
					stringBuilder.Append(item);
				}
				else
				{
					stringBuilder.Append("□");
				}
			}
			__result = stringBuilder.ToString();
		}
		else
		{
			__result = text;
		}
	}
}