using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using ComputerysModdingUtilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: StraftatMod(false)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DualAnything")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DualAnything")]
[assembly: AssemblyTitle("DualAnything")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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;
}
}
}
[BepInPlugin("com.27n.dualanything", "DualAnything", "1.0.0")]
public class DualAnythingPlugin : BaseUnityPlugin
{
public static ConfigEntry<KeyCode> HeavyAttackKey;
private void Awake()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
HeavyAttackKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "HeavyAttackModifier", (KeyCode)308, "Hold to perform heavy attacks when dual wielding (intended for melee weapons, but kinda works for guns as well)");
new Harmony("com.27n.dualanything").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"[27N] DualAnything loaded");
}
}
internal static class DualAnythingUtil
{
public static bool IsCochin(GameObject obj)
{
if ((Object)(object)obj != (Object)null)
{
return (Object)(object)obj.GetComponentInParent<PigItem>() != (Object)null;
}
return false;
}
}
[HarmonyPatch(typeof(PlayerPickup), "SwitchWeapons")]
internal class AllowTwoHandSwapPatch
{
private static bool Prefix(PlayerPickup __instance)
{
object? obj = AccessTools.Field(typeof(PlayerPickup), "objInHand")?.GetValue(__instance);
if (DualAnythingUtil.IsCochin((GameObject)((obj is GameObject) ? obj : null)))
{
return false;
}
return true;
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
FieldInfo field = AccessTools.Field(typeof(Weapon), "requireBothHands");
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode == OpCodes.Ldfld && instruction.operand as FieldInfo == field)
{
yield return new CodeInstruction(OpCodes.Pop, (object)null);
yield return new CodeInstruction(OpCodes.Ldc_I4_0, (object)null);
}
else
{
yield return instruction;
}
}
}
}
[HarmonyPatch(typeof(PlayerPickup), "HandleInteraction")]
internal class HandleDualWieldPickupPatch
{
private static bool Prefix(PlayerPickup __instance)
{
Type typeFromHandle = typeof(PlayerPickup);
object? obj = AccessTools.Field(typeFromHandle, "currentInteractable")?.GetValue(__instance);
Component val = (Component)((obj is Component) ? obj : null);
if ((Object)(object)val == (Object)null)
{
return true;
}
if (DualAnythingUtil.IsCochin(val.gameObject))
{
return true;
}
if ((Object)(object)val.GetComponent<Weapon>() == (Object)null)
{
return true;
}
if (!(bool)AccessTools.Field(typeFromHandle, "hasObjectInHand").GetValue(__instance))
{
return true;
}
MethodInfo methodInfo = AccessTools.Method(typeFromHandle, "LeftHandPickup", (Type[])null, (Type[])null);
if (methodInfo == null)
{
Debug.LogError((object)"[DualAnything] Could not find PlayerPickup.LeftHandPickup(). Falling back to vanilla interaction.");
return true;
}
methodInfo.Invoke(__instance, null);
return false;
}
}
[HarmonyPatch(typeof(Weapon), "Awake")]
internal class FixWeaponIndexes
{
private static void Postfix(Weapon __instance)
{
ItemBehaviour component = ((Component)__instance).GetComponent<ItemBehaviour>();
if (!((Object)(object)component == (Object)null) && component.camChildIndex > 10)
{
component.camChildIndex = 9;
component.camChildIndexLeftHand = 9;
}
}
}
[HarmonyPatch(typeof(MeleeWeapon), "Fire")]
internal class FixLeftHandAnimName
{
private static void Prefix(MeleeWeapon __instance)
{
if (((Weapon)__instance).inLeftHand)
{
FieldInfo fieldInfo = AccessTools.Field(typeof(MeleeWeapon), "baseAttackLeftAnim");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(MeleeWeapon), "baseAttackAnim");
string text = fieldInfo?.GetValue(__instance) as string;
if (string.IsNullOrEmpty(text) || text == "None")
{
fieldInfo?.SetValue(__instance, fieldInfo2?.GetValue(__instance));
}
}
}
}
[HarmonyPatch(typeof(FirstPersonController), "Update")]
internal class OverrideAimingLogic
{
private static void Postfix(FirstPersonController __instance)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
Type typeFromHandle = typeof(FirstPersonController);
object obj = AccessTools.Field(typeFromHandle, "playerPickupScript")?.GetValue(__instance);
if (obj == null)
{
return;
}
FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), "hasObjectInLeftHand");
if (!(fieldInfo == null) && (bool)fieldInfo.GetValue(obj))
{
FieldInfo fieldInfo2 = AccessTools.Field(typeFromHandle, "isAiming");
if (!(fieldInfo2 == null))
{
bool key = Input.GetKey(DualAnythingPlugin.HeavyAttackKey.Value);
fieldInfo2.SetValue(__instance, key);
}
}
}
}