using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json.Nodes;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LTFO")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LTFO")]
[assembly: AssemblyTitle("LTFO")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace LTFO
{
[BepInPlugin("Frosth.LTFO", "LTFO", "1.0.0")]
public class Plugin : BasePlugin
{
internal static Plugin Instance;
private Harmony _harmony;
internal static PluginMapping Mapping { get; private set; } = new PluginMapping();
public override void Load()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
Instance = this;
((BasePlugin)this).Log.LogInfo((object)"GTFO Fandub cargado.");
LoadMapping();
_harmony = new Harmony("Frosth.LTFO.fandub");
_harmony.PatchAll();
}
private void LoadMapping()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
//IL_05af: Expected O, but got Unknown
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Expected O, but got Unknown
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_0335: Expected O, but got Unknown
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Expected O, but got Unknown
//IL_053f: Unknown result type (might be due to invalid IL or missing references)
//IL_0545: Expected O, but got Unknown
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Expected O, but got Unknown
//IL_039d: Unknown result type (might be due to invalid IL or missing references)
//IL_03a3: Expected O, but got Unknown
//IL_0402: Unknown result type (might be due to invalid IL or missing references)
//IL_0409: Expected O, but got Unknown
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Expected O, but got Unknown
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Expected O, but got Unknown
//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
//IL_04db: Expected O, but got Unknown
//IL_0469: Unknown result type (might be due to invalid IL or missing references)
//IL_0470: Expected O, but got Unknown
string text = Path.Combine(Path.GetDirectoryName(((object)this).GetType().Assembly.Location), "mapping.json");
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] Buscando mapping en ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
}
log.LogInfo(val);
Mapping = new PluginMapping();
if (!File.Exists(text))
{
((BasePlugin)this).Log.LogWarning((object)"[LTFO] mapping.json no encontrado, usando mapping vacio.");
return;
}
try
{
string text2 = File.ReadAllText(text);
ManualLogSource log2 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] mapping.json length = ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(text2?.Length ?? 0);
}
log2.LogInfo(val);
if (string.IsNullOrWhiteSpace(text2))
{
((BasePlugin)this).Log.LogWarning((object)"[LTFO] mapping.json esta vacio, usando mapping vacio");
return;
}
JsonNode jsonNode = JsonNode.Parse(text2);
JsonNode jsonNode2 = jsonNode["EventMapping"];
ManualLogSource log3 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(32, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] EventMapping node type = ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(jsonNode2?.GetType().FullName ?? "null");
}
log3.LogInfo(val);
if (jsonNode2 is JsonObject jsonObject)
{
foreach (KeyValuePair<string, JsonNode> item in jsonObject)
{
ManualLogSource log4 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(44, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] EventMapping raw kv: key='");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item.Key);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("', value='");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<JsonNode>(item.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
}
log4.LogInfo(val);
if (!uint.TryParse(item.Key, out var result))
{
ManualLogSource log5 = ((BasePlugin)this).Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(38, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[LTFO] Clave EventMapping invalida: '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item.Key);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
}
log5.LogWarning(val2);
continue;
}
string text3 = item.Value?.ToString();
if (uint.TryParse(text3, out var result2))
{
ManualLogSource log6 = ((BasePlugin)this).Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(46, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[LTFO] Valor EventMapping invalido para '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item.Key);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("': '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text3);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
}
log6.LogWarning(val2);
Mapping.EventMapping[result] = result2;
}
Mapping.EventMapping[result] = result2;
ManualLogSource log7 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("EventMapping agregado: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(result);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(result2);
}
log7.LogInfo(val);
}
}
else
{
((BasePlugin)this).Log.LogWarning((object)"[LTFO] EventMapping no es JsonObject o es null");
}
JsonNode jsonNode3 = jsonNode["SubtitleMapping"];
ManualLogSource log8 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(35, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] SubtitleMapping node type = ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(jsonNode3?.GetType().FullName ?? "null");
}
log8.LogInfo(val);
if (jsonNode3 is JsonObject jsonObject2)
{
foreach (KeyValuePair<string, JsonNode> item2 in jsonObject2)
{
ManualLogSource log9 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(47, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] SubtitleMapping raw kv: key='");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item2.Key);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("', value='");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<JsonNode>(item2.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
}
log9.LogInfo(val);
if (!uint.TryParse(item2.Key, out var result3))
{
ManualLogSource log10 = ((BasePlugin)this).Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[LTFO] Clave SubtitleMapping invalida: '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item2.Key);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
}
log10.LogWarning(val2);
continue;
}
string text4 = item2.Value?.ToString();
if (!uint.TryParse(text4, out var result4))
{
ManualLogSource log11 = ((BasePlugin)this).Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(49, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[LTFO] Valor SubtitleMapping invalido para '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item2.Key);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("': '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text4);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
}
log11.LogWarning(val2);
}
else
{
Mapping.SubtitleMapping[result3] = result4;
ManualLogSource log12 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(37, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] SubtitleMapping agregado: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(result3);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(result4);
}
log12.LogInfo(val);
}
}
}
else
{
((BasePlugin)this).Log.LogWarning((object)"[LTFO] SubtitleMapping no es JsonObject o es null");
}
ManualLogSource log13 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(46, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[LTFO] Mapping cargado: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Mapping.EventMapping.Count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" eventos, ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Mapping.SubtitleMapping.Count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" subtitulos.");
}
log13.LogInfo(val);
}
catch (Exception ex)
{
ManualLogSource log14 = ((BasePlugin)this).Log;
BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Error cargando mapping.json ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
}
log14.LogError(val3);
Mapping = new PluginMapping();
}
}
}
public class PluginMapping
{
public Dictionary<uint, uint> EventMapping { get; } = new Dictionary<uint, uint>();
public Dictionary<uint, uint> SubtitleMapping { get; } = new Dictionary<uint, uint>();
}
[HarmonyPatch(typeof(GameDataInit), "Initialize")]
public static class GameDataInitPatch
{
private static void Postfix()
{
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
PluginMapping mapping = Plugin.Mapping;
bool flag = default(bool);
foreach (PlayerDialogDataBlock allBlock in GameDataBlockBase<PlayerDialogDataBlock>.GetAllBlocks())
{
try
{
Enumerator<DialogStructureHolder> enumerator2 = allBlock.dialogAlternatives.GetEnumerator();
while (enumerator2.MoveNext())
{
DialogStructure structure = enumerator2.Current.structure;
if (((structure != null) ? structure.lines : null) == null)
{
continue;
}
Enumerator<DialogLine> enumerator3 = structure.lines.GetEnumerator();
while (enumerator3.MoveNext())
{
DialogLine current2 = enumerator3.Current;
if (mapping.EventMapping.TryGetValue(current2.lineEvent, out var value))
{
ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(8, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(current2.lineEvent);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" en ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((GameDataBlockBase<PlayerDialogDataBlock>)(object)allBlock).name);
}
log.LogInfo(val);
current2.lineEvent = value;
}
}
}
}
catch (Exception ex)
{
ManualLogSource log2 = ((BasePlugin)Plugin.Instance).Log;
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(19, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error procesando ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((GameDataBlockBase<PlayerDialogDataBlock>)(object)allBlock).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
}
log2.LogError(val2);
}
}
}
}
}