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.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime.Injection; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; using Il2CppSystem.Reflection; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("Translator")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("Translator")] [assembly: AssemblyTitle("Translator")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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; } } } [BepInPlugin("com.pickteam.translator", "ProjectGorgon Translator", "0.2.0")] public class ModMain : BasePlugin { internal static ManualLogSource Logger; internal static Harmony HarmonyInstance; internal static string ModFolder; internal static ConfigEntry LanguageConfig; internal static ConfigEntry EnableTranslationTools; internal static ConfigEntry EnableDebugMenu; public override void Load() { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) Logger = ((BasePlugin)this).Log; ModFolder = Path.GetDirectoryName(((object)this).GetType().Assembly.Location); LanguageConfig = ((BasePlugin)this).Config.Bind("General", "Language", "ru", "Translation language code. Translations are loaded from translations// folder (e.g. ru, de, fr)."); EnableTranslationTools = ((BasePlugin)this).Config.Bind("DevTools", "EnableTranslationTools", false, "Enable F10 (reload translations) and F11 (export untranslated) hotkeys."); EnableDebugMenu = ((BasePlugin)this).Config.Bind("DevTools", "EnableDebugMenu", false, "Enable F7 scene debugger overlay."); ManualLogSource log = ((BasePlugin)this).Log; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(50, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("=== ProjectGorgon Translator v0.2.0 === Language: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(LanguageConfig.Value); } log.LogInfo(val); TranslationDictionary.Load(ModFolder, LanguageConfig.Value); ManualLogSource log2 = ((BasePlugin)this).Log; val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(TranslationDictionary.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" translations."); } log2.LogInfo(val); HarmonyInstance = new Harmony("com.pickteam.russifier"); HarmonyInstance.PatchAll(); ((BasePlugin)this).Log.LogInfo((object)"Harmony patches applied."); ClassInjector.RegisterTypeInIl2Cpp(); ClassInjector.RegisterTypeInIl2Cpp(); GameObject val2 = new GameObject("Tranlator_Components"); Object.DontDestroyOnLoad((Object)val2); ((Object)val2).hideFlags = (HideFlags)61; val2.AddComponent(); val2.AddComponent(); } } [HarmonyPatch(typeof(UIInventoryController), "IsItemInSearch")] public static class Patch_InventorySearch { public static void Postfix(UIInventoryController __instance, Item item, ref bool __result) { if (__result) { return; } string value = Traverse.Create((object)__instance).Field("lastItemSearchTerm").GetValue(); if (!string.IsNullOrEmpty(value)) { string name = item.Name; if (!string.IsNullOrEmpty(name) && TranslationDictionary.TryTranslate(name, out var russian) && !string.IsNullOrEmpty(russian) && russian.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) { __result = true; } } } } [HarmonyPatch(typeof(UIInteractionController), "ShowTalk")] public static class Patch_ShowTalk { public static void Prefix(ref string __1, ref string __2, ref string __3, Il2CppStringArray __5) { if (TranslationDictionary.TryTranslate(__1, out var russian)) { __1 = russian; } if (TranslationDictionary.TryTranslate(__2, out var russian2)) { __2 = russian2; } if (TranslationDictionary.TryTranslate(__3, out var russian3)) { __3 = russian3; } if (__5 == null) { return; } for (int i = 0; i < ((Il2CppArrayBase)(object)__5).Length; i++) { if (TranslationDictionary.TryTranslate(((Il2CppArrayBase)(object)__5)[i], out var russian4)) { ((Il2CppArrayBase)(object)__5)[i] = russian4; } } } } [HarmonyPatch(typeof(TMP_Text), "SetText", new Type[] { typeof(string) })] public static class Patch_TMP_SetText_String { public static void Prefix(ref string sourceText) { if (!string.IsNullOrEmpty(sourceText) && TranslationDictionary.TryTranslate(sourceText, out var russian)) { sourceText = russian; } } } [HarmonyPatch(typeof(TMP_Text), "set_text")] public static class Patch_TMP_Text_SetText { [ThreadStatic] private static bool _translating; private static readonly Dictionary _autoSizedInstances = new Dictionary(); private static readonly HashSet _fittedContainers = new HashSet(); private static ManualLogSource Log => ModMain.Logger; public static void Prefix(TMP_Text __instance, ref string value) { //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Expected O, but got Unknown if (_translating || string.IsNullOrEmpty(value)) { return; } _translating = true; try { int instanceID = ((Object)__instance).GetInstanceID(); if (_autoSizedInstances.TryGetValue(instanceID, out var value2)) { try { __instance.enableAutoSizing = false; __instance.fontSize = value2; __instance.textWrappingMode = (TextWrappingModes)1; } catch { } _autoSizedInstances.Remove(instanceID); } if (!TranslationDictionary.TryTranslate(value, out var russian)) { return; } string text = value; value = russian; if (!((float)russian.Length > (float)text.Length * 1.3f) || russian.Contains('\n')) { return; } try { if (IsInsideTooltip(__instance.transform)) { return; } if (IsInRigidLayout(__instance.transform)) { if (!__instance.enableAutoSizing) { float num = __instance.fontSize; if (num <= 0f) { num = __instance.fontSizeMax; } if (num <= 0f) { num = 24f; } __instance.enableAutoSizing = true; __instance.fontSizeMin = Math.Max(num * 0.45f, 5f); __instance.fontSizeMax = num; __instance.textWrappingMode = (TextWrappingModes)0; _autoSizedInstances[instanceID] = num; } } else { TryExpandContainer(__instance); } } catch (Exception ex) { ManualLogSource log = Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(16, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Resize] Error: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex.Message); } log.LogWarning(val); } } finally { _translating = false; } } private static void TryExpandContainer(TMP_Text text) { //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) RectTransform val = null; Transform val2 = text.transform; int num = 0; while (num < 3 && (Object)(object)val2 != (Object)null) { if ((Object)(object)((Component)val2).GetComponent