Decompiled source of Binary Trigger v1.2.0

BinaryTrigger.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BinaryTrigger.Patches;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BinaryTrigger")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BinaryTrigger")]
[assembly: AssemblyTitle("BinaryTrigger")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace BinaryTrigger
{
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Logger = new ManualLogSource("cactus.BinaryTrigger");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}
	}
	[BepInPlugin("cactus.BinaryTrigger", "BinaryTrigger", "1.1.0")]
	public class Plugin : BasePlugin
	{
		public Harmony m_Harmony;

		public static ConfigFile configFile;

		public static ConfigEntry<string> weapons;

		public override void Load()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(17, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin is loaded!");
			}
			log.LogInfo(val);
			GetSettings();
			m_Harmony = new Harmony("cactus.BinaryTrigger");
			m_Harmony.PatchAll();
		}

		public static void GetSettings()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "cactus.BinaryTrigger.cfg"), true);
			weapons = configFile.Bind<string>("General", "ArchetypeDB persistentIDs", "26,42", "List desired persistentIDs from ArchetypeDB: xx,xx,xx,etc");
			string[] array = weapons.Value.Split(',');
			uint[] array2 = new uint[array.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array2[i] = Convert.ToUInt32(array[i]);
			}
			BinaryTrigger_Patches.configWeaponArray = array2;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BinaryTrigger";

		public const string PLUGIN_NAME = "BinaryTrigger";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace BinaryTrigger.Patches
{
	[HarmonyPatch]
	internal class BinaryTrigger_Patches
	{
		public static uint[] configWeaponArray = new uint[2] { 26u, 42u };

		private static bool checkSecondShot;

		[HarmonyPatch(typeof(BulletWeaponArchetype), "Update")]
		[HarmonyPostfix]
		internal static void Update__Postfix(BulletWeaponArchetype __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			bool flag = InputMapper.GetButtonUp.Invoke((InputAction)8, __instance.m_owner.InputFilter);
			checkSecondShot = __instance.m_fireHeld;
			__instance.m_clip = ((ItemEquippable)__instance.m_weapon).GetCurrentClip();
			uint persistentID = ((GameDataBlockBase<ArchetypeDataBlock>)(object)__instance.m_archetypeData).persistentID;
			if (configWeaponArray.Contains(persistentID) && __instance.m_clip > 0f)
			{
				if (__instance.m_fireHeld)
				{
					__instance.m_firePressed = false;
				}
				if (!__instance.m_fireHeld && flag && !((PlayerInventoryBase)((Weapon)__instance.m_weapon).m_inventory).m_wieldedItem.IsReloading)
				{
					__instance.OnFireShot();
					__instance.m_nextBurstTimer = Clock.Time + __instance.ShotDelay();
				}
			}
		}

		[HarmonyPatch(typeof(BWA_Burst), "BurstIsDone")]
		[HarmonyPostfix]
		internal static void NoWeaponSwap__Postfix(ref bool __result, BulletWeaponArchetype __instance)
		{
			if (configWeaponArray.Contains(((GameDataBlockBase<ArchetypeDataBlock>)(object)__instance.m_archetypeData).persistentID) && checkSecondShot)
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(GameDataInit), "Initialize")]
		[HarmonyPostfix]
		internal static void FireMode__Postfix()
		{
			Enumerator<ArchetypeDataBlock> enumerator = GameDataBlockBase<ArchetypeDataBlock>.Wrapper.Blocks.GetEnumerator();
			while (enumerator.MoveNext())
			{
				ArchetypeDataBlock current = enumerator.Current;
				if (configWeaponArray.Contains(((GameDataBlockBase<ArchetypeDataBlock>)(object)current).persistentID))
				{
					current.FireMode = (eWeaponFireMode)1;
					current.BurstShotCount = 1;
					Logger.Info("FireMode adjusted");
				}
			}
		}
	}
}