using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UKMod template")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UKMod template")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3d018c2f-f5bc-47be-a844-3e9888579d1f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TranslationsAPI;
[HarmonyPatch(typeof(TMP_Text))]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class TMP_Text_SetText_Patch
{
private static void Prefix(ref string value)
{
if (TranslationRegistry.HasTranslations)
{
value = TranslationRegistry.Apply(value);
}
}
}
[BepInPlugin("com.nico.translationapi", "Translation API", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "com.nico.translationapi";
public const string NAME = "Translation API";
public const string VERSION = "0.1.0";
internal static ManualLogSource Logger;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("com.nico.translationapi");
val.PatchAll();
Logger.LogInfo((object)"Translation API v0.1.0 loaded.");
}
}
public static class TranslationRegistry
{
private static readonly List<string> _order = new List<string>();
private static readonly Dictionary<string, string> _replacements = new Dictionary<string, string>();
internal static bool HasTranslations => _replacements.Count > 0;
public static void RegisterTranslation(string source, string replacement)
{
if (string.IsNullOrEmpty(source))
{
ManualLogSource logger = Plugin.Logger;
if (logger != null)
{
logger.LogWarning((object)"[TranslationsAPI] Ignored RegisterTranslation call with a null/empty source string.");
}
return;
}
if (replacement == null)
{
replacement = string.Empty;
}
if (_replacements.ContainsKey(source))
{
ManualLogSource logger2 = Plugin.Logger;
if (logger2 != null)
{
logger2.LogWarning((object)("[TranslationsAPI] \"" + source + "\" is already registered — overwriting previous replacement (last registered wins)."));
}
_replacements[source] = replacement;
}
else
{
_replacements.Add(source, replacement);
_order.Add(source);
Plugin.Logger.LogInfo((object)("Registered translation: " + source));
}
}
public static void UnregisterTranslation(string source)
{
if (!string.IsNullOrEmpty(source) && _replacements.Remove(source))
{
_order.Remove(source);
Plugin.Logger.LogInfo((object)("Unregistered translation: " + source));
}
}
internal static string Apply(string text)
{
if (string.IsNullOrEmpty(text) || _replacements.Count == 0)
{
return text;
}
for (int i = 0; i < _order.Count; i++)
{
string text2 = _order[i];
if (text.IndexOf(text2, StringComparison.Ordinal) >= 0)
{
text = text.Replace(text2, _replacements[text2]);
}
}
return text;
}
}