Decompiled source of Belarusian Translation v1.0.2

BelarusianTranslation.dll

Decompiled 2 weeks ago
using System;
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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BelarusianTranslation")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BelarusianTranslation")]
[assembly: AssemblyTitle("BelarusianTranslation")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace BelarusianTranslation
{
	[BepInPlugin("com.yourname.peak.belarusian", "Belarusian Translation", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private readonly Harmony harmony = new Harmony("com.yourname.peak.belarusian");

		internal static string? TranslationJson;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "translation.json");
			if (File.Exists(text))
			{
				TranslationJson = File.ReadAllText(text, Encoding.UTF8);
				Logger.LogInfo((object)$"translation.json loaded ({TranslationJson.Length} chars).");
			}
			else
			{
				Logger.LogError((object)("translation.json NOT FOUND at: " + text));
			}
			harmony.PatchAll();
			Logger.LogInfo((object)"Belarusian Translation plugin loaded. Patches applied.");
		}
	}
	[HarmonyPatch(typeof(TextAsset), "get_text")]
	public static class TextAssetPatch
	{
		[HarmonyPostfix]
		public static void Postfix(TextAsset __instance, ref string __result)
		{
			if (__result != null && __result.Length > 20 && __result.StartsWith("{\"CURRENT_LANGUAGE\"", StringComparison.Ordinal) && Plugin.TranslationJson != null)
			{
				Plugin.Logger.LogInfo((object)("Intercepted SerializedTermsData (asset name: '" + ((Object)__instance).name + "'). Replacing with translation."));
				__result = Plugin.TranslationJson;
			}
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.yourname.peak.belarusian";

		public const string PLUGIN_NAME = "Belarusian Translation";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}