using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[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("HoleBuffsSpanish")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+27b7eff785341e3721b642d7f2ac76d1e6177b93")]
[assembly: AssemblyProduct("HoleBuffsSpanish")]
[assembly: AssemblyTitle("HoleBuffsSpanish")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 HoleBuffsSpanish
{
[BepInPlugin("leonardozerpa.holebuffs.spanish", "HoleBuffs en Espanol", "0.1.0")]
[BepInDependency("com.yourname.holebuffs", "0.48.0")]
[BepInDependency("local.sbg.compat", "0.1.0")]
public sealed class Spanish : BaseUnityPlugin
{
private static readonly Dictionary<string, string> Text = Rows("ui.es.tsv").ToDictionary<string[], string, string>((string[] r) => r[0], (string[] r) => r[1], StringComparer.Ordinal);
private readonly List<Action> restore = new List<Action>();
private Harmony harmony;
private static string[][] Rows(string name)
{
Assembly assembly = typeof(Spanish).Assembly;
using Stream stream = assembly.GetManifestResourceStream(assembly.GetManifestResourceNames().Single((string n) => n.EndsWith("." + name, StringComparison.Ordinal)));
using StreamReader streamReader = new StreamReader(stream);
return (from l in streamReader.ReadToEnd().Split('\n')
select l.TrimEnd('\r') into l
where l.Length > 0
select l.Split('\t')).ToArray();
}
private static string Read(object obj, string field)
{
return (string)obj.GetType().GetField(field).GetValue(obj);
}
private void Set(object obj, string field, object value)
{
FieldInfo f = obj.GetType().GetField(field);
object previous = f.GetValue(obj);
restore.Add(delegate
{
f.SetValue(obj, previous);
});
f.SetValue(obj, value);
}
private void Awake()
{
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Expected O, but got Unknown
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_0290: Expected O, but got Unknown
//IL_048a: Unknown result type (might be due to invalid IL or missing references)
//IL_0497: Expected O, but got Unknown
//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
//IL_04c9: Expected O, but got Unknown
try
{
Type type = AccessTools.TypeByName("HoleBuffs.Buffs") ?? throw new Exception("HoleBuffs unavailable");
Dictionary<string, object> pool = ((IEnumerable)type.GetField("Pool").GetValue(null)).Cast<object>().ToDictionary((object o) => Read(o, "Id"));
Dictionary<string, object> classes = ((IEnumerable)type.GetField("Classes").GetValue(null)).Cast<object>().ToDictionary((object o) => Read(o, "Id"));
string[][] array = Rows("cards.es.tsv");
string[][] array2 = Rows("classes.es.tsv");
if (array.Length != 136 || pool.Count != 136 || array.Any((string[] r) => r.Length != 4 || !pool.ContainsKey(r[0])) || array.Select((string[] r) => r[0]).Distinct().Count() != 136)
{
throw new Exception("Unsupported HoleBuffs card catalog");
}
if (array2.Length != 6 || classes.Count != 6 || array2.Any((string[] r) => r.Length != 6 || !classes.ContainsKey(r[0])))
{
throw new Exception("Unsupported class catalog");
}
string[][] array3 = array;
foreach (string[] array4 in array3)
{
object obj = pool[array4[0]];
Set(obj, "Name", array4[1]);
Set(obj, "Description", array4[2]);
Set(obj, "Flavor", array4[3]);
}
string[][] array5 = array2;
foreach (string[] array6 in array5)
{
object obj2 = classes[array6[0]];
Set(obj2, "Name", array6[1]);
Set(obj2, "Short", array6[2]);
Set(obj2, "Mechanic", array6[3]);
Set(obj2, "Gains", new string[2]
{
array6[4],
array6[5]
});
}
harmony = new Harmony("leonardozerpa.holebuffs.spanish");
HarmonyMethod val = new HarmonyMethod(typeof(Spanish), "TranslateLiterals", (Type[])null);
int num3 = 0;
Type[] types = type.Assembly.GetTypes();
foreach (Type type2 in types)
{
string text = type2.FullName.Split('+')[0];
bool flag = new string[3] { "HoleBuffs.BuffsScreen", "HoleBuffs.CardOverlay", "HoleBuffs.SettingsScreen" }.Contains(text);
bool flag2 = text == "HoleBuffs.Buffs" && type2 != type;
MethodInfo[] methods = type2.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
if ((flag || flag2 || (type2 == type && new string[3] { "On", "GroupName", "Ch" }.Contains(methodInfo.Name)) || (text == "HoleBuffs.Ui" && methodInfo.Name == "TierName") || (text == "HoleBuffs.Minigames" && methodInfo.Name == "Title") || (text == "HoleBuffs.Plugin" && methodInfo.Name == "WaitingText") || (text == "HoleBuffs.Offers" && new string[2] { "ScheduleText", "ClassSummary" }.Contains(methodInfo.Name))) && methodInfo.GetMethodBody() != null && !methodInfo.ContainsGenericParameters)
{
harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
num3++;
}
}
}
harmony.Patch((MethodBase)AccessTools.Method(AccessTools.TypeByName("HoleBuffs.ItemOdds"), "Pretty", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Spanish), "Pretty", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)AccessTools.Method(type, "GroupName", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Spanish), "Pretty", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
object obj3 = AccessTools.Field(AccessTools.TypeByName("HoleBuffs.BuffsScreen"), "DuoHeader")?.GetValue(null);
if (obj3 != null)
{
string[] array7 = new string[4] { "Name", "Mechanic", "Short", "Loss" };
foreach (string field in array7)
{
string text2 = Read(obj3, field);
if (text2 != null && Text.TryGetValue(text2, out var value))
{
Set(obj3, field, value);
}
}
string[] array8 = (string[])obj3.GetType().GetField("Gains").GetValue(obj3);
if (array8 != null)
{
Set(obj3, "Gains", array8.Select(Translate).ToArray());
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Spanish ready: {array.Length} cards, {array2.Length} classes, {num3} presentation methods. Gameplay identifiers unchanged.");
}
catch (Exception ex)
{
Rollback();
((BaseUnityPlugin)this).Logger.LogError((object)("Spanish localization disabled: " + ex));
}
}
private static string Translate(string input)
{
string value;
return (input != null && Text.TryGetValue(input, out value)) ? value : input;
}
private static void Pretty(ref string __result)
{
__result = Translate(__result);
}
private static IEnumerable<CodeInstruction> TranslateLiterals(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
{
foreach (CodeInstruction code in instructions)
{
if (code.opcode == OpCodes.Ldstr)
{
string value = (string)code.operand;
code.operand = ((__originalMethod.Name == "WaitingText" && value == "s") ? "es" : Translate(value));
}
yield return code;
}
}
private void Rollback()
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
for (int num = restore.Count - 1; num >= 0; num--)
{
restore[num]();
}
restore.Clear();
}
private void OnDestroy()
{
Rollback();
}
}
}