Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of EngiTurretsEquipment v1.0.0
plugins/EngiTurretsEquipment/EngiTurretsEquipment.dll
Decompiled 10 months agousing System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Mono.Cecil.Cil; using MonoMod.Cil; using MonoMod.RuntimeDetour; using RiskOfOptions; using RiskOfOptions.Options; using RoR2; using RoR2.CharacterAI; using UnityEngine; using UnityEngine.AddressableAssets; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] namespace EngiTurretsEquipment; [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("com.KingEnderBrine.EngiTurretsEquipment", "EngiTurretsEquipment", "1.0.0")] public class EngiTurretsEquipmentPlugin : BaseUnityPlugin { public const string GUID = "com.KingEnderBrine.EngiTurretsEquipment"; public const string Name = "EngiTurretsEquipment"; public const string Version = "1.0.0"; private static GameObject engiTurret; private static GameObject engiWalkerTurret; private static CharacterMaster engiTurretMaster; private static CharacterMaster engiWalkerTurretMaster; internal static EngiTurretsEquipmentPlugin Instance { get; private set; } internal static ManualLogSource InstanceLogger { get { EngiTurretsEquipmentPlugin instance = Instance; if (instance == null) { return null; } return ((BaseUnityPlugin)instance).Logger; } } internal static ConfigEntry<bool> RequireGesture { get; private set; } internal static ConfigEntry<float> CooldownMultiplier { get; private set; } private void Start() { //IL_0065: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_015a: Unknown result type (might be due to invalid IL or missing references) Instance = this; RequireGesture = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "RequireGestureOfTheDrowned", false, "If set to true, turrets will only use equipment if they have Gesture of the Drowned. Otherwise they will use equipment when attacking."); CooldownMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Main", "CooldownMultiplier", 1f, "Additional cooldown multiplier for the turrets."); if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions")) { RiskOfOptionsIntegration.Init(); } engiTurret = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Engi/EngiTurretBody.prefab").WaitForCompletion(); engiWalkerTurret = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Engi/EngiWalkerTurretBody.prefab").WaitForCompletion(); if (!Object.op_Implicit((Object)(object)engiTurret.GetComponent<EquipmentSlot>())) { engiTurret.AddComponent<EquipmentSlot>(); } if (!Object.op_Implicit((Object)(object)engiWalkerTurret.GetComponent<EquipmentSlot>())) { engiWalkerTurret.AddComponent<EquipmentSlot>(); } engiTurretMaster = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Engi/EngiTurretMaster.prefab").WaitForCompletion().GetComponent<CharacterMaster>(); engiWalkerTurretMaster = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Engi/EngiWalkerTurretMaster.prefab").WaitForCompletion().GetComponent<CharacterMaster>(); if (!RequireGesture.Value) { UpdateShouldFireEquipment(); } RequireGesture.SettingChanged += delegate { UpdateShouldFireEquipment(); }; new ILHook((MethodBase)typeof(Inventory).GetMethod("CalculateEquipmentCooldownScale", BindingFlags.Instance | BindingFlags.NonPublic), new Manipulator(CalculateEquipmentCooldown)); } private static void UpdateShouldFireEquipment() { AISkillDriver[] components = ((Component)engiTurretMaster).GetComponents<AISkillDriver>(); foreach (AISkillDriver val in components) { if (val.customName == "FireAtEnemy") { val.shouldFireEquipment = !RequireGesture.Value; } } components = ((Component)engiWalkerTurretMaster).GetComponents<AISkillDriver>(); foreach (AISkillDriver val2 in components) { string customName = val2.customName; if (customName == "StrafeAndFireAtEnemy" || customName == "ChaseAndFireAtEnemy") { val2.shouldFireEquipment = !RequireGesture.Value; } } } private void CalculateEquipmentCooldown(ILContext il) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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) ILCursor val = new ILCursor(il); if (val.TryGotoNext(new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchRet(x) })) { val.Emit(OpCodes.Ldarg_0); val.Emit(OpCodes.Call, (MethodBase)typeof(EngiTurretsEquipmentPlugin).GetMethod("GetMultiplier", BindingFlags.Static | BindingFlags.NonPublic)); val.Emit(OpCodes.Mul); } else { ((BaseUnityPlugin)this).Logger.LogError((object)"Couldn't apply cooldown scale hook"); } } private static float GetMultiplier(Inventory inventory) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_002e: Unknown result type (might be due to invalid IL or missing references) CharacterMaster component = ((Component)inventory).GetComponent<CharacterMaster>(); if (Object.op_Implicit((Object)(object)component)) { MasterIndex masterIndex = component.masterIndex; if (masterIndex == engiTurretMaster.masterIndex || masterIndex == engiWalkerTurretMaster.masterIndex) { return CooldownMultiplier.Value; } } return 1f; } } public static class RiskOfOptionsIntegration { public const string RiskOfOptionsGUID = "com.rune580.riskofoptions"; [MethodImpl(MethodImplOptions.NoInlining)] public static void Init() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0050: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown Texture2D val = new Texture2D(128, 128); using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EngiTurretsEquipment.icon.png")) { using BinaryReader binaryReader = new BinaryReader(stream); ImageConversion.LoadImage(val, binaryReader.ReadBytes((int)stream.Length)); ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0f, 0f))); } ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EngiTurretsEquipmentPlugin.RequireGesture), "com.KingEnderBrine.EngiTurretsEquipment", "EngiTurretsEquipment"); ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(EngiTurretsEquipmentPlugin.CooldownMultiplier), "com.KingEnderBrine.EngiTurretsEquipment", "EngiTurretsEquipment"); } }