using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ue.Peak.TcnPatch")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5f3841d884cb9d6bf420b0e1b92c02cffc8f5ccf")]
[assembly: AssemblyProduct("ue.Peak.TcnPatch")]
[assembly: AssemblyTitle("ue.Peak.TcnPatch")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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;
}
}
}
namespace ue.Peak.TcnPatch
{
[BepInPlugin("ue.Peak.TcnPatch", "ue.Peak.TcnPatch", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
private const string ModGuid = "ue.Peak.TcnPatch";
private const string ModName = "ue.Peak.TcnPatch";
private const string ModVersion = "1.0.2";
internal static ManualLogSource Logger;
private static FileSystemWatcher _watcher;
private const string TcnTranslationFileName = "Viossa.json";
private static SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Starting mod");
Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
string path = Path.Combine(Paths.ConfigPath, "ue.Peak.TcnPatch");
Directory.CreateDirectory(path);
_watcher = new FileSystemWatcher(path, "*.json");
_watcher.NotifyFilter = NotifyFilters.LastWrite;
_watcher.Changed += delegate(object sender, FileSystemEventArgs args)
{
if (args.Name == "Viossa.json")
{
Logger.LogInfo((object)"reloaded translations");
UpdateMainTable();
}
};
UpdateMainTable();
_watcher.EnableRaisingEvents = true;
}
private static void UpdateMainTable()
{
_lock.Wait();
Dictionary<string, string> result;
try
{
if (!TryReadFromJson("Viossa.json", out result, () => new Dictionary<string, string>()))
{
return;
}
}
finally
{
_lock.Release();
}
Dictionary<string, List<string>> mainTable = LocalizedText.mainTable;
HashSet<string> hashSet = mainTable.Keys.ToHashSet();
foreach (var (text3, value) in result)
{
if (!mainTable.TryGetValue(text3, out var value2))
{
Logger.LogWarning((object)("unknown key: " + text3));
Logger.LogWarning((object)"Adding key");
LocalizedText.mainTable[text3] = new List<string>(16)
{
result[text3],
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
null
};
}
else
{
value2[0] = value;
hashSet.Remove(text3);
}
}
foreach (string item in hashSet)
{
List<string> value3;
bool flag = mainTable.TryGetValue(item, out value3);
Logger.LogWarning((object)("Missing key '" + item + "', original value '" + value3[0] + "'"));
}
}
private static bool TryReadFromJson<T>(string fileName, out T result, Func<T> defaultContent) where T : class
{
string text = Path.Combine(Paths.ConfigPath, "ue.Peak.TcnPatch");
Directory.CreateDirectory(text);
string path = Path.Combine(text, fileName);
if (!File.Exists(path))
{
string contents = JsonConvert.SerializeObject((object)defaultContent());
File.WriteAllText(path, contents);
}
try
{
using FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using StreamReader streamReader = new StreamReader(stream);
result = JsonConvert.DeserializeObject<T>(streamReader.ReadToEnd());
return true;
}
catch (Exception ex)
{
Logger.LogError((object)("json error for file: " + fileName));
Logger.LogError((object)ex);
result = null;
return false;
}
}
[HarmonyPatch(typeof(LoadingScreenAnimation), "Start")]
[HarmonyPostfix]
private static void PatchLoadingAnimation(LoadingScreenAnimation __instance)
{
string text = LocalizedText.GetText("LOADING", true);
FieldInfo field = typeof(LoadingScreenAnimation).GetField("loadingString", BindingFlags.Instance | BindingFlags.NonPublic);
FieldInfo field2 = typeof(LoadingScreenAnimation).GetField("defaultLoadingStringLength", BindingFlags.Instance | BindingFlags.NonPublic);
if (field == null)
{
Logger.LogWarning((object)"error patching loading screen");
return;
}
if (field2 == null)
{
Logger.LogWarning((object)"error patching loading screen");
return;
}
Logger.LogInfo((object)"patching loading screen");
string text2 = text + "..." + text + "..." + text + "..." + text + "...";
field.SetValue(__instance, text2);
field2.SetValue(__instance, (float)text2.Length);
}
[HarmonyPatch(typeof(DevMessageUI), "Update")]
[HarmonyPrefix]
private static bool Update(DevMessageUI __instance)
{
__instance.parent.SetActive(true);
TextMeshProUGUI[] texts = __instance.texts;
foreach (TextMeshProUGUI val in texts)
{
((TMP_Text)val).text = LocalizedText.GetText("MOD_ANUNSHA", true);
}
return false;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ue.Peak.TcnPatch";
public const string PLUGIN_NAME = "ue.Peak.TcnPatch";
public const string PLUGIN_VERSION = "1.0.0";
}
}