using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Pigeon.Math; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyVersion("0.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; } } } namespace DMLRAutoSwap { [BepInPlugin("com.coloron.dmlrAutoSwap", "DMLR AutoSwap", "1.0.0")] [MycoMod(/*Could not decode attribute arguments.*/)] public class DMLRAutoSwapPlugin : BaseUnityPlugin { public const string PluginGUID = "com.coloron.dmlrAutoSwap"; public const string PluginName = "DMLR AutoSwap"; public const string PluginVersion = "1.0.0"; public const int ModUpgradeID = 88801; public static DMLRAutoSwapPlugin Instance; public static Upgrade CustomUpgradeInstance; internal static ManualLogSource Logger; private void Awake() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) Instance = this; Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)"Loading DMLR AutoSwap..."); new Harmony("com.coloron.dmlrAutoSwap").PatchAll(); PlayerData.AddRegisterUpgradesCallback((Action)InitializeUpgrades); } private static void InitializeUpgrades() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) IUpgradable val = PlayerData.FindGear("dmlr"); if (val == null) { Logger.LogError((object)"[DMLRAutoSwap] PlayerData.FindGear(\"dmlr\") returned null - aborting registration."); return; } CustomUpgradeParams val2 = CustomUpgradeParams.Create(val, 88801, "AutoSwap", "Increases Laser Burst radius and damage. Automatically switches between Laser and DMR modes when out of ammo or charge.", (Rarity)3, (Sprite)null); ref UpgradeFlags flags = ref val2.flags; flags = (UpgradeFlags)((uint)flags | 0x2000u); try { CustomUpgradeInstance = PlayerData.CreateUpgrade("com.coloron.dmlrAutoSwap", val2, (UpgradeProperty[])(object)new UpgradeProperty[1] { new UpgradeProperty_DMLR_AutoSwap() }); } catch (Exception arg) { Logger.LogError((object)$"[DMLRAutoSwap] CreateUpgrade threw: {arg}"); return; } if ((Object)(object)CustomUpgradeInstance == (Object)null) { Logger.LogError((object)"[DMLRAutoSwap] CustomUpgradeInstance is null after CreateUpgrade - aborting pattern setup."); return; } try { ApplyCustomPattern(CustomUpgradeInstance); Logger.LogInfo((object)"[DMLRAutoSwap] AutoSwap upgrade registered successfully."); } catch (Exception arg2) { Logger.LogError((object)$"[DMLRAutoSwap] ApplyCustomPattern threw: {arg2}"); } } private static void ApplyCustomPattern(Upgrade upgrade) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)upgrade == (Object)null)) { HexMap val = new HexMap(3, 3); val[0, 0].enabled = true; val[0, 1].enabled = true; val[0, 1].connections = (Direction)5; val[1, 0].enabled = true; val[1, 0].connections = (Direction)56; val[1, 1].enabled = true; SetPrivateField(upgrade, "pattern", val); } } public static bool SetPrivateField(object target, string name, object value) { Type type = target.GetType(); FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); while (field == null && type.BaseType != null) { type = type.BaseType; field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } if (field != null) { field.SetValue(target, value); return true; } return false; } public static bool GunHasAutoSwap(ScoutLaserRifle gun) { if ((Object)(object)gun == (Object)null || (Object)(object)CustomUpgradeInstance == (Object)null) { return false; } List list = PlayerData.GetUpgradeInfo((IUpgradable)(object)gun, CustomUpgradeInstance)?.Instances; if (list == null) { return false; } foreach (UpgradeInstance item in list) { if (item.IsEquipped((IUpgradable)(object)gun)) { return true; } } return false; } } [HarmonyPatch(typeof(ScoutLaserRifle))] public static class DMLRAutoSwitchPatch { private static float _lastForcedSwitchTime = -999f; private const float ForcedSwitchCooldown = 0.25f; [HarmonyPatch("OnActiveUpdate")] [HarmonyPostfix] private static void OnActiveUpdate_Postfix(ScoutLaserRifle __instance) { if (DMLRAutoSwapPlugin.GunHasAutoSwap(__instance) && !(Time.time - _lastForcedSwitchTime < 0.25f)) { bool isLaserModeActive = __instance.IsLaserModeActive; float laserCharge = __instance.LaserCharge; float remainingAmmo = ((Gun)__instance).RemainingAmmo; if (!isLaserModeActive && remainingAmmo <= 0f && laserCharge > 0f) { ForceToggleLaserMode(__instance); _lastForcedSwitchTime = Time.time; } else if (isLaserModeActive && laserCharge <= 0f) { ForceToggleLaserMode(__instance); _lastForcedSwitchTime = Time.time; } } } private static bool ForceToggleLaserMode(ScoutLaserRifle instance) { MethodInfo method = typeof(ScoutLaserRifle).GetMethod("ToggleLaserMode", BindingFlags.Instance | BindingFlags.NonPublic); if (method == null) { ManualLogSource logger = DMLRAutoSwapPlugin.Logger; if (logger != null) { logger.LogError((object)"[DMLRAutoSwap] ToggleLaserMode method not found via reflection!"); } return false; } method.Invoke(instance, null); return true; } } [Serializable] public class UpgradeProperty_DMLR_AutoSwap : UpgradeProperty { public const float burstSizeBonus = 2f; private const float TurboBurstSizeBonus = 1f; public Range burstDamageBonus = new Range(12f, 16f); private const float TurboBurstDamageBonus = 10f; public override IEnumerator GetStatData(Random rand, IUpgradable gear, UpgradeInstance upgrade) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) yield return StatData.Create(TextBlocks.GetString("maxsize"), new Range(2f, 2f), upgrade, ref rand, (OverrideType)1, (LabelType)1, default(BoostParams)); yield return StatData.Create(TextBlocks.GetString("Burst damage"), burstDamageBonus, upgrade, ref rand, (OverrideType)1, (LabelType)1, default(BoostParams)); if (upgrade != null && upgrade.IsTurbocharged) { StatData val = UpgradeProperty.AddTurbochargedProperty(upgrade); yield return ((StatData)(ref val)).PlaceAtEnd(true); val = new StatData($"Max Size: +{1f}\nBurst Damage: +{10f}"); yield return ((StatData)(ref val)).PlaceAtEnd(true); } } public override string GetTurbochargedInfo(Random rand, IUpgradable gear, UpgradeInstance upgrade) { return $"Turbocharged\nMax Size: +{1f}\nBurst Damage: +{10f}"; } public override void Apply(IGear gear, UpgradeInstance upgrade, ref Random rand) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) ScoutLaserRifle val = (ScoutLaserRifle)(object)((gear is ScoutLaserRifle) ? gear : null); if (!((Object)(object)val == (Object)null)) { val.LaserData.laserBurstSize += 2f; float value = burstDamageBonus.GetValue(ref rand, upgrade, default(BoostParams)); val.LaserData.laserBurstDamage += value; if (upgrade.IsTurbocharged) { val.LaserData.laserBurstSize += 1f; val.LaserData.laserBurstDamage += 10f; } } } } }