using System;
using System.Collections;
using System.Collections.Generic;
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.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Ukrainian_BigWalk")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.5.1.0")]
[assembly: AssemblyInformationalVersion("1.5.1+f51dc90d15a0d09471af15d61a9fda850521955f")]
[assembly: AssemblyProduct("Ukrainian Language for Big Walk")]
[assembly: AssemblyTitle("Ukrainian_BigWalk")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Ukrainian_BigWalk
{
[BepInPlugin("Ukrainian_BigWalk", "Ukrainian Language for Big Walk", "1.5.1")]
public class Plugin : BasePlugin
{
internal static ManualLogSource Log;
public static ConfigEntry<string> TranslationFilePath;
public static ConfigEntry<string> TargetLanguage;
public override void Load()
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
TranslationFilePath = ((BasePlugin)this).Config.Bind<string>("Translation", "TranslationFilePath", "translations.json", "Path to the translations file.");
TargetLanguage = ((BasePlugin)this).Config.Bind<string>("Translation", "TargetLanguage", "english", "Language that will be replaced with Ukrainian. Valid options: english, french, german, europeanSpanish, russian, korean, japanese, brazilianPortuguese, simplifiedChinese, italian, polish, latinAmericanSpanish, turkish, traditionalChinese.");
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(11, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Ukrainian_BigWalk");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
ManualLogSource log2 = Log;
val = new BepInExInfoLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Target translation language: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(TargetLanguage.Value);
}
log2.LogInfo(val);
((BasePlugin)this).AddComponent<TranslationLoader>();
}
}
public class TranslationLoader : MonoBehaviour
{
private void Start()
{
((MonoBehaviour)this).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(WaitForLocalization()));
}
private IEnumerator WaitForLocalization()
{
Plugin.Log.LogInfo((object)"Waiting for a LocalizationDataSet instance...");
LocalizationDataSet dataSet = null;
while ((Object)(object)dataSet == (Object)null)
{
try
{
dataSet = LocalizationDataSet.instance;
}
catch
{
}
yield return null;
}
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Found a LocalizationDataSet with ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(((Il2CppArrayBase<LocalizationEntry>)(object)dataSet.items).Length);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" entries.");
}
log.LogInfo(val);
Dictionary<string, string> translations = LoadTranslations();
string language = Plugin.TargetLanguage.Value;
int replaced = 0;
foreach (LocalizationEntry item in (Il2CppArrayBase<LocalizationEntry>)(object)dataSet.items)
{
if (translations.TryGetValue(item.key, out var translatedText))
{
if (SetTranslation(item, language, translatedText))
{
replaced++;
}
else
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(64, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Could not find language field '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(language);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' on LocalizationDataSet item '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item.key);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'.");
}
log2.LogWarning(val2);
}
}
translatedText = null;
}
LocalizedText.RefreshAll();
ManualLogSource log3 = Plugin.Log;
val = new BepInExInfoLogInterpolatedStringHandler(23, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Applied ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(replaced);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("/");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(((Il2CppArrayBase<LocalizationEntry>)(object)dataSet.items).Length);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" translations.");
}
log3.LogInfo(val);
}
private Dictionary<string, string> LoadTranslations()
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string text = Path.Combine(directoryName, Plugin.TranslationFilePath.Value);
bool flag = default(bool);
if (!File.Exists(text))
{
ManualLogSource log = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Translation file not found: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
}
log.LogWarning(val);
return new Dictionary<string, string>();
}
try
{
string json = File.ReadAllText(text);
return JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(34, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load translations.json: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
}
log2.LogError(val2);
return new Dictionary<string, string>();
}
}
private bool SetTranslation(LocalizationEntry item, string language, string translatedText)
{
//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Expected O, but got Unknown
switch (language.ToLower())
{
case "english":
item.english = translatedText;
return true;
case "french":
item.french = translatedText;
return true;
case "german":
item.german = translatedText;
return true;
case "europeanspanish":
item.europeanSpanish = translatedText;
return true;
case "russian":
item.russian = translatedText;
return true;
case "korean":
item.korean = translatedText;
return true;
case "japanese":
item.japanese = translatedText;
return true;
case "braziliansortuguese":
item.brazilianPortuguese = translatedText;
return true;
case "simplifiedchinese":
item.simplifiedChinese = translatedText;
return true;
case "italian":
item.italian = translatedText;
return true;
case "polish":
item.polish = translatedText;
return true;
case "latinamericanspanish":
item.latinAmericanSpanish = translatedText;
return true;
case "turkish":
item.turkish = translatedText;
return true;
case "traditionalchinese":
item.traditionalChinese = translatedText;
return true;
default:
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(63, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Unsupported language: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(language);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(". Defaulting to replacing English fields.");
}
log.LogWarning(val);
item.english = translatedText;
return true;
}
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Ukrainian_BigWalk";
public const string PLUGIN_NAME = "Ukrainian Language for Big Walk";
public const string PLUGIN_VERSION = "1.5.1";
}
}