Decompiled source of FixDriver v0.0.1

FixDriver.dll

Decompiled 15 hours ago
using System;
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;
using HG;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Cil;
using RoR2;
using RoR2.Orbs;
using RoR2.Projectile;
using RobDriver;
using RobDriver.Modules;
using RobDriver.Modules.Components;
using RobDriver.Modules.Survivors;
using RobDriver.SkillStates.Driver;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FixDriver")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FixDriver")]
[assembly: AssemblyTitle("FixDriver")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 FixDriver
{
	[BepInPlugin("_score.FixDriver", "FixDriver", "0.0.1")]
	public class FixDriverPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "_score.FixDriver";

		public const string PluginAuthor = "score";

		public const string PluginName = "FixDriver";

		public const string PluginVersion = "0.0.1";

		public void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (AccessTools.Field(typeof(DriverPlugin), "MODVERSION").GetValue(null) as string == "1.8.0")
			{
				new Harmony("_score.FixDriver").CreateClassProcessor(typeof(Fix)).Patch();
				return;
			}
			Debug.LogError((object)"Driver is fixed, uninstall this mod :)");
			Object.Destroy((Object)(object)this);
		}
	}
	[HarmonyPatch]
	public class Fix
	{
		[HarmonyPatch(typeof(Driver), "CreateHitboxes")]
		[HarmonyILManipulator]
		public static void BuffKnife(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "KnifeHitbox")
			}) && val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 1.3f)
			}))
			{
				val.Next.Operand = 1.75f;
			}
			else
			{
				Debug.LogError((object)"CreateHitboxes");
			}
		}

		[HarmonyPatch(typeof(Assets), "PopulateAssets")]
		[HarmonyPostfix]
		public static void FixTracer()
		{
			GameObject coinOrbEffect = Assets.coinOrbEffect;
			((OrbEffect)coinOrbEffect.GetComponent<CoinOrbEffect>()).duration = 1f;
			coinOrbEffect.GetComponent<VFXAttributes>().DoNotPool = true;
			Assets.coinImpact.GetComponent<VFXAttributes>().DoNotPool = true;
			GameObject coinTracer = Assets.coinTracer;
			Object.DestroyImmediate((Object)(object)coinTracer.GetComponent<CoinTracer>());
			Tracer obj = coinTracer.AddComponent<Tracer>();
			obj.startTransform = coinTracer.transform.GetChild(2).GetChild(0);
			obj.beamObject = ((Component)coinTracer.transform.GetChild(2).GetChild(0)).gameObject;
			obj.beamDensity = 0.2f;
			obj.speed = 1000f;
			obj.headTransform = coinTracer.transform.GetChild(1);
			obj.tailTransform = coinTracer.transform.GetChild(2).GetChild(0);
			obj.length = 20f;
		}

		[HarmonyPatch(typeof(CoinController), "Start")]
		[HarmonyPrefix]
		public static void FixCoinStart(CoinController __instance)
		{
			((Component)__instance).gameObject.layer = LayerIndex.fakeActor.intVal;
			((MonoBehaviour)__instance).StartCoroutine("SwapBack");
		}

		[HarmonyPatch(typeof(CoinController), "OnIncomingDamageServer")]
		[HarmonyPrefix]
		public static bool FixCoinReciever(CoinController __instance, DamageInfo damageInfo)
		{
			if (Object.op_Implicit((Object)(object)__instance.iDrive) && (Object)(object)damageInfo.attacker == (Object)(object)((Component)__instance.iDrive).gameObject)
			{
				__instance.RicochetBullet(damageInfo);
			}
			else
			{
				damageInfo.rejected = true;
			}
			return false;
		}

		[HarmonyPatch(typeof(CoinRicochetOrb), "PickNextTarget")]
		[HarmonyPrefix]
		public static bool FixCoinOrb2(CoinRicochetOrb __instance, Vector3 position, ref HurtBox __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			__instance.search = new BullseyeSearch
			{
				queryTriggerInteraction = (QueryTriggerInteraction)1,
				filterByDistinctEntity = false,
				filterByLoS = false,
				sortMode = (SortMode)1,
				teamMaskFilter = TeamMask.all,
				maxDistanceFilter = __instance.searchRadius,
				searchOrigin = position
			};
			__instance.search.RefreshCandidates();
			CoinController val = default(CoinController);
			foreach (HurtBox result in __instance.search.GetResults())
			{
				if (((Component)result.healthComponent).TryGetComponent<CoinController>(ref val))
				{
					if (val.canRicochet)
					{
						__result = result;
						break;
					}
				}
				else if (!Object.op_Implicit((Object)(object)__result) && Object.op_Implicit((Object)(object)result.healthComponent.body) && ((GenericDamageOrb)__instance).teamIndex != result.healthComponent.body.teamComponent.teamIndex)
				{
					__result = result;
				}
			}
			return false;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyILManipulator]
		public static void FixCoinSwap(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.25f)
			}))
			{
				val.Next.Operand = 0.1f;
			}
			else
			{
				Debug.LogError((object)"coinswap1");
			}
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsflda(x, typeof(LayerIndex), "entityPrecise")
			}))
			{
				val.GotoPrev((MoveType)1, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0)
				});
				val.Emit(OpCodes.Ldarg_0);
				val.Emit(val.Next.Next.OpCode, val.Next.Next.Operand);
				val.EmitDelegate<Action<CoinController>>((Action<CoinController>)delegate(CoinController coin)
				{
					ProjectileController val2 = default(ProjectileController);
					if (((Component)coin).TryGetComponent<ProjectileController>(ref val2))
					{
						coin.iDrive = val2.owner.GetComponent<DriverController>();
					}
					HealthComponent val3 = default(HealthComponent);
					if (((Component)coin).TryGetComponent<HealthComponent>(ref val3))
					{
						IOnIncomingDamageServerReceiver value = (IOnIncomingDamageServerReceiver)(object)coin;
						if (!val3.onIncomingDamageReceivers.Contains(value))
						{
							ArrayUtils.ArrayAppend<IOnIncomingDamageServerReceiver>(ref val3.onIncomingDamageReceivers, ref value);
						}
					}
					HurtBox componentInChildren = ((Component)coin).GetComponentInChildren<HurtBox>();
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						((Component)componentInChildren).gameObject.layer = LayerIndex.entityPrecise.intVal;
					}
				});
				val.GotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdsflda(x, typeof(LayerIndex), "entityPrecise")
				});
				val.Remove();
				val.Emit<LayerIndex>(OpCodes.Ldsflda, "defaultLayer");
			}
			else
			{
				Debug.LogError((object)"coinswap2");
			}
		}

		[HarmonyPatch(typeof(Driver), "CreateSkills")]
		[HarmonyILManipulator]
		public static void AddCoin(ILContext il)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			ILCursor[] array = null;
			ILCursor[] array2 = null;
			if (new ILCursor(il).TryFindNext(ref array, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(Skills), "AddSpecialSkills"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(Skills), "AddSpecialSkills")
			}))
			{
				ILCursor val = array[0];
				TypeReference val3 = default(TypeReference);
				val.FindPrev(ref array2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchNewarr(x, ref val3)
				});
				array2[0].Prev.OpCode = OpCodes.Ldc_I4_7;
				val.Emit(OpCodes.Dup);
				val.Emit(OpCodes.Ldc_I4, 6);
				val.Emit(OpCodes.Ldloc, 14);
				val.Emit(OpCodes.Stelem_Ref);
				val = array[1];
				TypeReference val2 = default(TypeReference);
				val.FindPrev(ref array2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchNewarr(x, ref val2)
				});
				array2[0].Prev.OpCode = OpCodes.Ldc_I4_5;
				val.Emit(OpCodes.Dup);
				val.Emit(OpCodes.Ldc_I4, 4);
				val.Emit(OpCodes.Ldloc, 14);
				val.Emit(OpCodes.Stelem_Ref);
			}
			else
			{
				Debug.LogError((object)"skills");
			}
		}

		[HarmonyPatch(typeof(SyncOverlay), "OnReceived")]
		[HarmonyPatch(typeof(UseSyringe), "ApplyBuff")]
		[HarmonyPatch(typeof(UseSyringeLegacy), "ApplyBuff")]
		[HarmonyPatch(typeof(UseSyringeScepter), "ApplyBuff")]
		[HarmonyILManipulator]
		public static void SyringeScepter(ILContext il)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			TypeReference variableType = il.Import(typeof(TemporaryOverlayInstance));
			Enumerator<VariableDefinition> enumerator = il.Body.Variables.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					VariableDefinition current = enumerator.Current;
					if (((object)((VariableReference)current).VariableType).ToString() == "RoR2.TemporaryOverlay")
					{
						((VariableReference)current).VariableType = variableType;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			ILCursor val = new ILCursor(il);
			while (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.Method(typeof(GameObject), "AddComponent", Array.Empty<Type>(), new Type[1] { typeof(TemporaryOverlay) }))
			}))
			{
				val.Remove();
				val.Emit(OpCodes.Call, (MethodBase)AccessTools.Method(typeof(TemporaryOverlayManager), "AddOverlay", (Type[])null, (Type[])null));
				if (val.TryGotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<TemporaryOverlay>(x, "AddToCharacerModel")
				}))
				{
					val.Remove();
					val.Emit(OpCodes.Call, (MethodBase)AccessTools.Method(typeof(TemporaryOverlayInstance), "AddToCharacterModel", (Type[])null, (Type[])null));
				}
			}
		}
	}
}