using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.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: AssemblyTitle("ControllerAimer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ControllerAimer")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("17665fc7-b7f3-448d-b85b-22506f488236")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ControllerAimer;
public static class AimerPatches
{
[HarmonyPatch(typeof(GuidedBulletsPassiveItem), "PreMoveProjectileModifier")]
public class PreMoveProjectileModifierPatchClass
{
[HarmonyILManipulator]
public static void PreMoveProjectileModifierPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 2)
}))
{
val.Emit(OpCodes.Ldarg_0);
val.Emit(OpCodes.Ldarg_1);
val.Emit(OpCodes.Ldloc_0);
val.Emit(OpCodes.Ldloc_1);
val.EmitCall<PreMoveProjectileModifierPatchClass>("PreMoveProjectileModifierPatchCall");
}
}
private static float PreMoveProjectileModifierPatchCall(float target, GuidedBulletsPassiveItem self, Projectile p, BraveInput instanceForPlayer, Vector2 vector)
{
//IL_0012: 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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
if (!instanceForPlayer.IsKeyboardAndMouse(false) && instanceForPlayer.ActiveActions != null && vector == Vector2.zero)
{
float num = default(float);
AIActor nearestEnemy = ((PassiveItem)self).Owner.CurrentRoom.GetNearestEnemy(((GameActor)((PassiveItem)self).Owner).CenterPosition, ref num, true, false);
if (Object.op_Implicit((Object)(object)nearestEnemy))
{
vector = ((GameActor)nearestEnemy).CenterPosition - ((BraveBehaviour)p).specRigidbody.UnitCenter;
return Vector2Extensions.ToAngle(vector);
}
return ((PassiveItem)self).Owner.m_currentGunAngle;
}
return target;
}
}
[HarmonyPatch(typeof(InputGuidedProjectile), "Move")]
public class MovePatchClass
{
[HarmonyILManipulator]
public static void MovePatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 3)
}))
{
val.Emit(OpCodes.Ldarg_0);
val.Emit(OpCodes.Ldloc_1);
val.Emit(OpCodes.Ldloc_2);
val.EmitCall<MovePatchClass>("MovePatchCall");
}
}
private static float MovePatchCall(float target, InputGuidedProjectile self, BraveInput instanceForPlayer, Vector2 vector)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
if (!instanceForPlayer.IsKeyboardAndMouse(false) && instanceForPlayer.ActiveActions != null && vector == Vector2.zero)
{
GameActor owner = ((Projectile)self).Owner;
float num = default(float);
AIActor nearestEnemy = ((PlayerController)((owner is PlayerController) ? owner : null)).CurrentRoom.GetNearestEnemy(((Projectile)self).Owner.CenterPosition, ref num, true, false);
if (Object.op_Implicit((Object)(object)nearestEnemy))
{
vector = ((GameActor)nearestEnemy).CenterPosition - ((BraveBehaviour)self).specRigidbody.UnitCenter;
return Vector2Extensions.ToAngle(vector);
}
GameActor owner2 = ((Projectile)self).Owner;
return ((PlayerController)((owner2 is PlayerController) ? owner2 : null)).m_currentGunAngle;
}
return target;
}
}
public static void EmitCall<T>(this ILCursor iLCursor, string methodName, Type[] parameters = null, Type[] generics = null)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
MethodInfo methodInfo = AccessTools.Method(typeof(T), methodName, parameters, generics);
iLCursor.Emit(OpCodes.Call, (MethodBase)methodInfo);
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("kleirof.etg.controlleraimer", "Controller Aimer", "1.1.3")]
public class AimerModule : BaseUnityPlugin
{
public const string GUID = "kleirof.etg.controlleraimer";
public const string NAME = "Controller Aimer";
public const string VERSION = "1.1.3";
public const string TEXT_COLOR = "#FF7F50";
public void Start()
{
ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
}
public void GMStart(GameManager g)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
Log("Controller Aimer v1.1.3 started successfully.", "#FF7F50");
Harmony val = new Harmony("kleirof.etg.controlleraimer");
val.PatchAll();
}
public static void Log(string text, string color = "FFFFFF")
{
ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
}
}