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 Gunfiguration;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[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_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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)
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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: 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_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
if (!AimerModule.gunfig.Enabled("Remote Bullets Fix"))
{
return target;
}
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_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
if (!AimerModule.gunfig.Enabled("Remote Bullets Fix"))
{
return target;
}
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;
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public class AutoAimTargetIsValidPatch
{
[HarmonyPrefix]
public static bool AutoAimTargetIsValidPrefix(AutoAimTarget __instance, ref bool __result)
{
if (!AimerModule.gunfig.Enabled("No Aiming Barrels"))
{
return true;
}
if ((Object)(object)__instance != (Object)null)
{
__result = false;
return false;
}
if ((Object)(object)((BraveBehaviour)__instance).specRigidbody != (Object)null && ((BraveBehaviour)__instance).specRigidbody.CanBeCarried)
{
__result = false;
return false;
}
return true;
}
}
public static void EmitCall<T>(this ILCursor iLCursor, string methodName, Type[] parameters = null, Type[] generics = null)
{
//IL_0014: 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.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("kleirof.etg.controlleraimer", "Controller Aimer", "1.2.1")]
public class AimerModule : BaseUnityPlugin
{
public const string GUID = "kleirof.etg.controlleraimer";
public const string NAME = "Controller Aimer";
public const string VERSION = "1.2.1";
public const string TEXT_COLOR = "#FF7F50";
internal static Gunfig gunfig;
internal const string remoteBulletsFixStr = "Remote Bullets Fix";
internal const string noAimingBarrelsStr = "No Aiming Barrels";
public void Start()
{
ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
}
public void GMStart(GameManager g)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
Log("Controller Aimer v1.2.1 started successfully.", "#FF7F50");
new Harmony("kleirof.etg.controlleraimer").PatchAll();
InitializeGunfig();
}
public static void Log(string text, string color = "FFFFFF")
{
ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
}
internal static void InitializeGunfig()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Invalid comparison between Unknown and I4
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Invalid comparison between Unknown and I4
gunfig = Gunfig.Get(GunfigHelpers.WithColor("Controller Aimer", Color.white));
gunfig.AddToggle("Remote Bullets Fix", true, ((int)GameManager.Options.CurrentLanguage == 11) ? "远程子弹修复" : "Remote Bullets Fix", (Action<string, string>)null, (Update)1);
gunfig.AddToggle("No Aiming Barrels", true, ((int)GameManager.Options.CurrentLanguage == 11) ? "不瞄准桶" : "No Aiming Barrels", (Action<string, string>)null, (Update)1);
}
}