Decompiled source of Localizator v1.0.0

Plugins/Localizator.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Localizator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Localizator")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("07c80bb0-bdb0-41d2-b5f9-db058337097e")]
[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")]
[BepInPlugin("com.roma.localizator", "Localizator", "0.0.3")]
public class TextReplaceMod : BaseUnityPlugin
{
	public static Dictionary<string, string> translations = new Dictionary<string, string>();

	private string filePath;

	private void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		filePath = Path.Combine(Paths.ConfigPath, "translations.txt");
		LoadTranslations();
		Harmony val = new Harmony("com.roma.localizator");
		val.PatchAll();
	}

	private void LoadTranslations()
	{
		if (!File.Exists(filePath))
		{
			File.WriteAllText(filePath, "Simple Bag=Простой рюкзак\r\nHitch=Привязать\r\nUnhitch=Отвязать\r\nCancel Hitching=Отменить привязку\r\n");
		}
		translations.Clear();
		string[] array = File.ReadAllLines(filePath);
		foreach (string text in array)
		{
			if (!string.IsNullOrWhiteSpace(text) && text.Contains("="))
			{
				string[] array2 = text.Split(new char[1] { '=' }, 2);
				translations[array2[0].Trim()] = array2[1].Trim();
			}
		}
	}
}
[HarmonyPatch]
public class LocalizationPatch
{
	private static MethodBase TargetMethod()
	{
		Type type = AccessTools.TypeByName("Localization");
		return AccessTools.Method(type, "Localize", new Type[1] { typeof(string) }, (Type[])null);
	}

	private static void Postfix(ref string __result)
	{
		if (string.IsNullOrEmpty(__result))
		{
			return;
		}
		foreach (KeyValuePair<string, string> translation in TextReplaceMod.translations)
		{
			__result = __result.Replace(translation.Key, translation.Value);
		}
	}
}
[HarmonyPatch(typeof(Text), "set_text")]
public class UITextPatch
{
	private static void Prefix(ref string value)
	{
		if (string.IsNullOrEmpty(value))
		{
			return;
		}
		foreach (KeyValuePair<string, string> translation in TextReplaceMod.translations)
		{
			value = value.Replace(translation.Key, translation.Value);
		}
	}
}
[HarmonyPatch(typeof(TMP_Text), "set_text")]
public class TMPTextPatch
{
	private static void Prefix(ref string value)
	{
		if (string.IsNullOrEmpty(value))
		{
			return;
		}
		foreach (KeyValuePair<string, string> translation in TextReplaceMod.translations)
		{
			value = value.Replace(translation.Key, translation.Value);
		}
	}
}