using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx.Preloader.Core.Patching;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("DeleagateRefEditingPrePatcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5b601c508e3fa4a35750e3aa1cf3031155ce2ee8")]
[assembly: AssemblyProduct("DeleagateRefEditingPrePatcher")]
[assembly: AssemblyTitle("DeleagateRefEditingPrePatcher")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace DeleagateRefEditing;
[PatcherPluginInfo("net.eia485.DeleagateRefEditingPrePatcher", "DeleagateRefEditingPrePatcher", "1.0.0")]
public class Patcher : BasePatcher
{
[TargetAssembly("FrooxEngine.dll")]
public void PatchAssembly(AssemblyDefinition assembly)
{
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Expected O, but got Unknown
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
ModuleDefinition mainModule = assembly.MainModule;
ModuleDefinition module = ((MemberReference)mainModule.TypeSystem.Object.Resolve()).Module;
TypeDefinition type = FindType(mainModule, "FrooxEngine.SyncDelegate`1");
TypeDefinition type2 = FindType(mainModule, "FrooxEngine.ISyncRef");
TypeDefinition val = FindType(module, "System.Delegate");
TypeDefinition val2 = FindType(module, "System.Reflection.MethodBase");
TypeDefinition val3 = FindType(module, "System.Reflection.MemberInfo");
TypeDefinition val4 = FindType(module, "System.Type");
MethodDefinition val5 = FindMethod(type, "FrooxEngine.ISyncRef.TrySet");
MethodDefinition val6 = FindMethod(val4, "GetType");
MethodDefinition val7 = FindMethod(val4, "IsAssignableTo");
MethodDefinition getMethod = FindProperty(val, "Method").GetMethod;
MethodDefinition getMethod2 = FindProperty(val2, "IsStatic").GetMethod;
MethodDefinition getMethod3 = FindProperty(val3, "DeclaringType").GetMethod;
MethodDefinition setMethod = FindProperty(type2, "Target").SetMethod;
FieldDefinition val8 = FindField(type, "_target");
mainModule.ImportReference((TypeReference)(object)val);
mainModule.ImportReference((TypeReference)(object)val2);
mainModule.ImportReference((TypeReference)(object)val3);
mainModule.ImportReference((TypeReference)(object)val4);
MethodReference val9 = mainModule.ImportReference((MethodReference)(object)val6);
MethodReference val10 = mainModule.ImportReference((MethodReference)(object)val7);
MethodReference val11 = mainModule.ImportReference((MethodReference)(object)getMethod);
MethodReference val12 = mainModule.ImportReference((MethodReference)(object)getMethod2);
MethodReference val13 = mainModule.ImportReference((MethodReference)(object)getMethod3);
val5.Body = new MethodBody(val5);
MethodBody body = val5.Body;
body.InitLocals = false;
ILProcessor iLProcessor = body.GetILProcessor();
Instruction val14 = Instruction.Create(OpCodes.Ldc_I4_0);
iLProcessor.Emit(OpCodes.Ldarg_0);
iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val8);
iLProcessor.Emit(OpCodes.Brfalse, val14);
iLProcessor.Emit(OpCodes.Ldarg_0);
iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val8);
iLProcessor.Emit(OpCodes.Callvirt, val11);
iLProcessor.Emit(OpCodes.Callvirt, val12);
iLProcessor.Emit(OpCodes.Brtrue, val14);
iLProcessor.Emit(OpCodes.Ldarg_1);
iLProcessor.Emit(OpCodes.Callvirt, val9);
iLProcessor.Emit(OpCodes.Ldarg_0);
iLProcessor.Emit(OpCodes.Ldfld, (FieldReference)(object)val8);
iLProcessor.Emit(OpCodes.Callvirt, val11);
iLProcessor.Emit(OpCodes.Callvirt, val13);
iLProcessor.Emit(OpCodes.Callvirt, val10);
iLProcessor.Emit(OpCodes.Brfalse, val14);
iLProcessor.Emit(OpCodes.Ldarg_0);
iLProcessor.Emit(OpCodes.Ldarg_1);
iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)setMethod);
iLProcessor.Emit(OpCodes.Ldc_I4_1);
iLProcessor.Emit(OpCodes.Ret);
iLProcessor.Append(val14);
iLProcessor.Emit(OpCodes.Ret);
body.MaxStackSize = 3;
MethodBodyRocks.OptimizeMacros(body);
}
private static TypeDefinition FindType(ModuleDefinition module, string fullName)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
TypeDefinition type = module.GetType(fullName);
if (type != null)
{
return type;
}
throw new InvalidOperationException("Type not found: " + fullName);
}
private static MethodDefinition FindMethod(TypeDefinition type, string name)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
string name2 = name;
return Enumerable.FirstOrDefault<MethodDefinition>((global::System.Collections.Generic.IEnumerable<MethodDefinition>)Enumerable.OrderBy<MethodDefinition, int>((global::System.Collections.Generic.IEnumerable<MethodDefinition>)type.Methods, (Func<MethodDefinition, int>)((MethodDefinition m) => ((MethodReference)m).Parameters.Count)), (Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == name2)) ?? throw new InvalidOperationException("Method not found: " + ((MemberReference)type).FullName + "." + name2);
}
private static PropertyDefinition FindProperty(TypeDefinition type, string name)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
string name2 = name;
return Enumerable.FirstOrDefault<PropertyDefinition>((global::System.Collections.Generic.IEnumerable<PropertyDefinition>)type.Properties, (Func<PropertyDefinition, bool>)((PropertyDefinition p) => ((MemberReference)p).Name == name2)) ?? throw new InvalidOperationException("Property not found: " + ((MemberReference)type).FullName + "." + name2);
}
private static FieldDefinition FindField(TypeDefinition type, string name)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
string name2 = name;
return Enumerable.FirstOrDefault<FieldDefinition>((global::System.Collections.Generic.IEnumerable<FieldDefinition>)type.Fields, (Func<FieldDefinition, bool>)((FieldDefinition f) => ((MemberReference)f).Name == name2)) ?? throw new InvalidOperationException("Field not found: " + ((MemberReference)type).FullName + "." + name2);
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "net.eia485.DeleagateRefEditingPrePatcher";
public const string PLUGIN_NAME = "DeleagateRefEditingPrePatcher";
public const string PLUGIN_VERSION = "1.0.0";
public const string PLUGIN_AUTHORS = "DeleagateRefEditingPrePatcher";
public const string PLUGIN_REPOSITORY_URL = "";
}