using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TFAOneClickUnlocker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TFAOneClickUnlocker")]
[assembly: AssemblyTitle("TFAOneClickUnlocker")]
[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 TFAOneClickUnlocker
{
[BepInPlugin("com.chatgpt.peak.tfaoneclickunlocker", "TFA One-Click Unlocker", "0.1.0")]
public sealed class Plugin : BaseUnityPlugin
{
private void Update()
{
if (Input.GetKeyDown((KeyCode)289))
{
try
{
UnlockAttempt();
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Unlock attempt failed: " + ex));
}
}
}
private void UnlockAttempt()
{
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => string.Equals(a.GetName().Name, "TrueFinalAscent", StringComparison.OrdinalIgnoreCase));
if (assembly == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"TrueFinalAscent assembly is not loaded.");
return;
}
Type type = assembly.GetType("FinalAscentBadges", throwOnError: false) ?? GetTypesSafely(assembly).FirstOrDefault((Type t) => t != null && t.Name == "FinalAscentBadges");
if (type == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Could not find TFA type FinalAscentBadges.");
return;
}
FieldInfo field = type.GetField("All", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
MethodInfo method = type.GetMethod("Earn", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null);
MethodInfo methodInfo = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(delegate(MethodInfo m)
{
if (m.Name != "Owned")
{
return false;
}
ParameterInfo[] parameters = m.GetParameters();
return parameters.Length == 1 && parameters[0].ParameterType.Name == "FinalAscentBadge";
});
if (field == null || method == null || methodInfo == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"TFA adapter failed. All, Earn(string), or Owned(FinalAscentBadge) is missing.");
return;
}
if (!(field.GetValue(null) is IEnumerable enumerable))
{
((BaseUnityPlugin)this).Logger.LogError((object)"TFA FinalAscentBadges.All is unavailable.");
return;
}
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
int num6 = 0;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Starting TFA native badge unlock.");
foreach (object item in enumerable)
{
if (item == null)
{
continue;
}
Type type2 = item.GetType();
string text = null;
bool flag = false;
try
{
FieldInfo field2 = type2.GetField("Key", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
PropertyInfo property = type2.GetProperty("Key", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo field3 = type2.GetField("Special", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
PropertyInfo property2 = type2.GetProperty("Special", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field2 != null)
{
text = field2.GetValue(item) as string;
}
else if (property != null)
{
text = property.GetValue(item, null) as string;
}
if (field3 != null)
{
flag = Convert.ToBoolean(field3.GetValue(item));
}
else if (property2 != null)
{
flag = Convert.ToBoolean(property2.GetValue(item, null));
}
}
catch (Exception ex)
{
num6++;
((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not read badge metadata: " + ex.Message));
continue;
}
if (string.IsNullOrEmpty(text))
{
num6++;
((BaseUnityPlugin)this).Logger.LogWarning((object)"Skipped badge with unreadable Key.");
continue;
}
if (flag)
{
num5++;
((BaseUnityPlugin)this).Logger.LogInfo((object)("Skipped special badge: " + text));
continue;
}
num++;
try
{
if (Convert.ToBoolean(methodInfo.Invoke(null, new object[1] { item })))
{
num3++;
((BaseUnityPlugin)this).Logger.LogInfo((object)("Already unlocked: " + text));
continue;
}
method.Invoke(null, new object[1] { text });
if (Convert.ToBoolean(methodInfo.Invoke(null, new object[1] { item })))
{
num2++;
((BaseUnityPlugin)this).Logger.LogInfo((object)("Unlock confirmed: " + text));
}
else
{
num4++;
((BaseUnityPlugin)this).Logger.LogWarning((object)("Earn was called, but ownership was not confirmed: " + text + ". TFA may be blocking achievements or manual mode may be active."));
}
}
catch (TargetInvocationException ex2)
{
num6++;
((BaseUnityPlugin)this).Logger.LogError((object)("TFA threw an exception for " + text + ": " + (ex2.InnerException ?? ex2)));
}
catch (Exception ex3)
{
num6++;
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to process " + text + ": " + ex3));
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("TFA unlock finished. Confirmed unlocked=" + num2 + ", already owned=" + num3 + ", unconfirmed=" + num4 + ", skipped special=" + num5 + ", errors=" + num6 + ", attempted=" + num + "."));
}
private static Type[] GetTypesSafely(Assembly assembly)
{
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
return ex.Types.Where((Type t) => t != null).ToArray();
}
}
}
}