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 BepInEx;
using HarmonyLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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("KRW's Zort Episode 3 Tomorrow Mod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KRW's Zort Episode 3 Tomorrow Mod")]
[assembly: AssemblyTitle("KRW's Zort Episode 3 Tomorrow Mod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KRWSoundReplaceMod;
public static class PluginInfo
{
public const string PLUGIN_GUID = "mods.krwclassic.zortep3tmrw";
public const string PLUGIN_NAME = "KRW's Zort Episode 3 Tomorrow Mod";
public const string PLUGIN_VERSION = "1.0.0";
}
[BepInPlugin("mods.krwclassic.zortep3tmrw", "KRW's Zort Episode 3 Tomorrow Mod", "1.0.0")]
public class ZortEpisode3TomorrowMod : BaseUnityPlugin
{
[HarmonyPatch]
private static class Patch_SetLanguage
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("LocalizationSystem"), "SetLanguage", new Type[1] { typeof(string) }, (Type[])null);
}
private static bool Prefix(ref bool __result)
{
try
{
if (_customLang == null)
{
return true;
}
Type type = AccessTools.TypeByName("LocalizationSystem");
PropertyInfo propertyInfo = AccessTools.Property(type, "CurrentLocalization");
object value = propertyInfo.GetValue(null);
Type type2 = AccessTools.TypeByName("Localization");
object obj = Activator.CreateInstance(type2);
FieldInfo fieldInfo = AccessTools.Field(type2, "lang");
Dictionary<string, string> dictionary = new Dictionary<string, string>((value != null) ? ((Dictionary<string, string>)fieldInfo.GetValue(value)) : new Dictionary<string, string>());
foreach (KeyValuePair<string, string> item in _customLang)
{
dictionary[item.Key] = item.Value;
}
fieldInfo.SetValue(obj, dictionary);
PropertyInfo propertyInfo2 = AccessTools.Property(type, "CurrentLocalizationName");
propertyInfo.SetValue(null, obj);
propertyInfo2.SetValue(null, "ep3tmrw");
__result = true;
Debug.Log((object)string.Format("[{0}] Successfully merged {1} custom entries with original localization.", "KRW's Zort Episode 3 Tomorrow Mod", _customLang.Count));
return false;
}
catch (Exception arg)
{
Debug.LogError((object)string.Format("[{0}] Merge patch failed: {1}", "KRW's Zort Episode 3 Tomorrow Mod", arg));
return true;
}
}
}
private static Dictionary<string, string> _customLang;
private void Awake()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
LoadEmbeddedJson();
new Harmony("mods.krwclassic.zortep3tmrw").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"[KRW's Zort Episode 3 Tomorrow Mod] Loaded and patched successfully.");
}
private void LoadEmbeddedJson()
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith("ep3tmrw.json", StringComparison.OrdinalIgnoreCase));
if (text == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"[KRW's Zort Episode 3 Tomorrow Mod] Embedded resource '*.ep3tmrw.json' not found!");
return;
}
using Stream stream = executingAssembly.GetManifestResourceStream(text);
using StreamReader streamReader = new StreamReader(stream);
string text2 = streamReader.ReadToEnd();
try
{
_customLang = JsonConvert.DeserializeObject<Dictionary<string, string>>(text2);
}
catch
{
JObject val = JObject.Parse(text2);
JToken obj = val["lang"] ?? val["Lang"] ?? val["LANG"];
if (obj == null)
{
throw new Exception("JSON root is not a dictionary and 'lang' property not found.");
}
_customLang = obj.ToObject<Dictionary<string, string>>();
}
if (_customLang == null || _customLang.Count == 0)
{
throw new Exception("Parsed localization dictionary is empty.");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("[{0}] Loaded {1} entries from '{2}'.", "KRW's Zort Episode 3 Tomorrow Mod", _customLang.Count, text));
}
}