using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using UnityEngine;
[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("SeekersPatcher")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+28250b19ab0a8958d724f2cade6606c818e5d0b1")]
[assembly: AssemblyProduct("SeekersPatcher")]
[assembly: AssemblyTitle("SeekersPatcher")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 _SeekersPatcher
{
public static class _SeekersPatcher
{
internal static class Logger
{
private static readonly ManualLogSource logSource = Logger.CreateLogSource("SeekersPatcher");
public static void Info(object data)
{
logSource.LogInfo(data);
}
public static void Error(object data)
{
logSource.LogError(data);
}
public static void Warn(object data)
{
logSource.LogWarning(data);
}
public static void Fatal(object data)
{
logSource.LogFatal(data);
}
public static void Message(object data)
{
logSource.LogMessage(data);
}
public static void Debug(object data)
{
logSource.LogDebug(data);
}
}
private const string RoR2 = "RoR2";
private const string RoR2UI = "RoR2.UI";
private const string RoR2Projectile = "RoR2.Projectile";
private const string RoR2Skills = "RoR2.Skills";
private static ModuleDefinition ror2;
public static IEnumerable<string> TargetDLLs
{
get
{
yield return "RoR2.dll";
}
}
public static void Patch(AssemblyDefinition assemblyDef)
{
object obj;
if (assemblyDef == null)
{
obj = null;
}
else
{
AssemblyNameDefinition name = assemblyDef.Name;
obj = ((name != null) ? ((AssemblyNameReference)name).Name : null);
}
if (!((string?)obj != "RoR2"))
{
ror2 = assemblyDef.MainModule;
PatchMissingFields();
PatchSuicide();
PatchProjectileFire();
ror2 = null;
}
}
private static void PatchMissingFields()
{
TypeDefinition type = ror2.GetType("RoR2.DLC2Content/Items");
TypeDefinition type2 = ror2.GetType("RoR2", "ItemDef");
AddField(type, (TypeReference)(object)type2, "NegateAttack", (FieldAttributes)22);
AddField(type, (TypeReference)(object)type2, "LowerHealthHigherDamage", (FieldAttributes)22);
AddField(type, (TypeReference)(object)type2, "GoldOnStageStart", (FieldAttributes)22);
AddField(type, (TypeReference)(object)type2, "ResetChests", (FieldAttributes)22);
TypeDefinition type3 = ror2.GetType("RoR2.DLC2Content/Buffs");
TypeDefinition type4 = ror2.GetType("RoR2", "BuffDef");
AddField(type3, (TypeReference)(object)type4, "LowerHealthHigherDamageBuff", (FieldAttributes)22);
TypeDefinition type5 = ror2.GetType("RoR2", "BulletAttack");
TypeDefinition type6 = ror2.GetType("RoR2", "EffectData");
TypeReference fieldTypeRef2 = ror2.ImportReference(typeof(bool));
AddField(type5, (TypeReference)(object)type6, "_EffectData", (FieldAttributes)22);
AddField(type5, fieldTypeRef2, "_UsePools", (FieldAttributes)22);
TypeDefinition type7 = ror2.GetType("RoR2", "PlayerCharacterMasterController");
AddField(type7, fieldTypeRef2, "wasClaimed", (FieldAttributes)6);
TypeDefinition type8 = ror2.GetType("RoR2", "Inventory");
TypeReference fieldTypeRef3 = ror2.ImportReference(typeof(int[]));
AddField(type8, fieldTypeRef3, "itemStacks", (FieldAttributes)6);
TypeDefinition type9 = ror2.GetType("RoR2.PickupPickerController/Option");
TypeDefinition type10 = ror2.GetType("RoR2", "PickupIndex");
AddField(type9, (TypeReference)(object)type10, "pickupIndex", (FieldAttributes)6);
TypeDefinition type11 = ror2.GetType("RoR2", "ShopTerminalBehavior");
AddField(type11, (TypeReference)(object)type10, "pickupIndex", (FieldAttributes)6);
TypeDefinition type12 = ror2.GetType("RoR2", "GenericPickupController");
AddField(type12, (TypeReference)(object)type10, "pickupIndex", (FieldAttributes)6);
TypeDefinition type13 = ror2.GetType("RoR2", "CharacterModel");
TypeReference fieldTypeRef4 = ror2.ImportReference(typeof(int));
AddField(type13, fieldTypeRef4, "invisibilityCount", (FieldAttributes)6);
static void AddField(TypeDefinition typeDef, TypeReference fieldTypeRef, string fieldName, FieldAttributes attr)
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
if (((IEnumerable<FieldDefinition>)typeDef.Fields).Any((FieldDefinition f) => ((MemberReference)f).Name == fieldName && ((MemberReference)((FieldReference)f).FieldType).Name == ((MemberReference)fieldTypeRef).Name))
{
Logger.Warn(fieldName + " already exists in " + ((MemberReference)typeDef).FullName);
}
else
{
typeDef.Fields.Add(new FieldDefinition(fieldName, attr, fieldTypeRef));
Logger.Debug("Added " + ((MemberReference)((IEnumerable<FieldDefinition>)typeDef.Fields).Last()).FullName);
}
}
}
private static void PatchSuicide()
{
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Expected O, but got Unknown
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Expected O, but got Unknown
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Expected O, but got Unknown
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
string name = "Suicide";
TypeDefinition tdDamageType = ror2.GetType("RoR2", "DamageType");
TypeDefinition type = ror2.GetType("RoR2", "DamageTypeCombo");
TypeDefinition type2 = ror2.GetType("RoR2", "HealthComponent");
TypeReference val = ror2.ImportReference(typeof(GameObject));
TypeReference val2 = ror2.ImportReference(typeof(void));
if (((IEnumerable<MethodDefinition>)type2.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == name && ((MethodReference)m).HasParameters && ((MethodReference)m).Parameters.Count == 3 && ((MemberReference)((ParameterReference)((IEnumerable<ParameterDefinition>)((MethodReference)m).Parameters).Last()).ParameterType).Name == ((MemberReference)tdDamageType).Name))
{
Logger.Warn(name + " exists, abort patch");
return;
}
MethodDefinition val3 = ((IEnumerable<MethodDefinition>)type2.Methods).First((MethodDefinition m) => ((MemberReference)m).Name == name);
MethodDefinition val4 = ((IEnumerable<MethodDefinition>)type.Methods).First((MethodDefinition m) => ((MemberReference)m).Name == "op_Implicit" && ((MethodReference)m).HasParameters && ((MethodReference)m).Parameters.Count == 1 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).Name == ((MemberReference)tdDamageType).Name);
MethodDefinition val5 = new MethodDefinition(name, (MethodAttributes)6, val2);
((MethodReference)val5).Parameters.Add(new ParameterDefinition(val));
((MethodReference)val5).Parameters.Add(new ParameterDefinition(val));
((MethodReference)val5).Parameters.Add(new ParameterDefinition((TypeReference)(object)tdDamageType));
ILProcessor iLProcessor = val5.Body.GetILProcessor();
iLProcessor.Emit(OpCodes.Ldarg_0);
iLProcessor.Emit(OpCodes.Ldarg_1);
iLProcessor.Emit(OpCodes.Ldarg_2);
iLProcessor.Emit(OpCodes.Ldarg_3);
iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val4);
iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val3);
iLProcessor.Emit(OpCodes.Ret);
type2.Methods.Add(val5);
Logger.Debug(((MemberReference)val5).FullName);
}
private static void PatchProjectileFire()
{
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Expected O, but got Unknown
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Expected O, but got Unknown
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Expected O, but got Unknown
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Expected O, but got Unknown
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Expected O, but got Unknown
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Expected O, but got Unknown
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Expected O, but got Unknown
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Expected O, but got Unknown
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Expected O, but got Unknown
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Expected O, but got Unknown
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Expected O, but got Unknown
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
string name = "FireProjectile";
TypeDefinition type = ror2.GetType("RoR2.Projectile", "ProjectileManager");
TypeDefinition type2 = ror2.GetType("RoR2", "DamageColorIndex");
TypeReference val = ror2.ImportReference(typeof(Vector3));
TypeReference val2 = ror2.ImportReference(typeof(Quaternion));
TypeReference val3 = ror2.ImportReference(typeof(GameObject));
TypeReference val4 = ror2.ImportReference(typeof(void));
TypeReference val5 = ror2.ImportReference(typeof(float));
TypeReference val6 = ror2.ImportReference(typeof(bool));
if (((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == name && ((MethodReference)m).HasParameters && ((MethodReference)m).Parameters.Count == 10))
{
Logger.Warn(name + " exists, abort patch");
return;
}
MethodDefinition val7 = ((IEnumerable<MethodDefinition>)type.Methods).First((MethodDefinition m) => ((MemberReference)m).Name == "FireProjectileWithoutDamageType");
MethodDefinition val8 = new MethodDefinition(name, (MethodAttributes)6, val4);
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val3));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val2));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val3));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val5));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val5));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val6));
((MethodReference)val8).Parameters.Add(new ParameterDefinition((TypeReference)(object)type2));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val3));
((MethodReference)val8).Parameters.Add(new ParameterDefinition(val5));
ILProcessor iLProcessor = val8.Body.GetILProcessor();
iLProcessor.Emit(OpCodes.Ldarg_0);
iLProcessor.Emit(OpCodes.Ldarg_1);
iLProcessor.Emit(OpCodes.Ldarg_2);
iLProcessor.Emit(OpCodes.Ldarg_3);
iLProcessor.Emit(OpCodes.Ldarg, 4);
iLProcessor.Emit(OpCodes.Ldarg, 5);
iLProcessor.Emit(OpCodes.Ldarg, 6);
iLProcessor.Emit(OpCodes.Ldarg, 7);
iLProcessor.Emit(OpCodes.Ldarg, 8);
iLProcessor.Emit(OpCodes.Ldarg, 9);
iLProcessor.Emit(OpCodes.Ldarg, 10);
iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val7);
iLProcessor.Emit(OpCodes.Ret);
type.Methods.Add(val8);
Logger.Debug(((MemberReference)val8).FullName);
}
}
}