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 Unity.Netcode; 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 DMLRFirstShotExplosive { [BepInPlugin("com.coloron.DMLRFirstShotExplosive", "DMLR First Shot Explosive", "1.0.0")] [MycoMod(/*Could not decode attribute arguments.*/)] public class DMLRFirstShotExplosivePlugin : BaseUnityPlugin { public const string PluginGUID = "com.coloron.DMLRFirstShotExplosive"; public const string PluginName = "DMLR First Shot Explosive"; public const string PluginVersion = "1.0.0"; public const int ModUpgradeID = 88802; public static DMLRFirstShotExplosivePlugin Instance; public static Upgrade CustomUpgradeInstance; internal static ManualLogSource Logger; public const EffectType ExplosionEffect = (EffectType)4; 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 First Shot Explosive..."); new Harmony("com.coloron.DMLRFirstShotExplosive").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_0053: 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) //IL_0063: Unknown result type (might be due to invalid IL or missing references) IUpgradable val = PlayerData.FindGear("dmlr"); if (val == null) { Logger.LogError((object)"[DMLRFirstShotExplosive] PlayerData.FindGear(\"dmlr\") returned null - aborting registration."); return; } CustomUpgradeParams val2 = CustomUpgradeParams.Create(val, 88802, "Explosive Cycle", "The first DMR round fired after switching out of laser mode is overcharged: it detonates on impact.", (Rarity)2, (Sprite)null); try { UpgradeProperty_DMLR_FirstShotExplosive upgradeProperty_DMLR_FirstShotExplosive = new UpgradeProperty_DMLR_FirstShotExplosive { explosionRadius = new Range(4f, 6f) }; CustomUpgradeInstance = PlayerData.CreateUpgrade("com.coloron.DMLRFirstShotExplosive", val2, (UpgradeProperty[])(object)new UpgradeProperty[1] { upgradeProperty_DMLR_FirstShotExplosive }); } catch (Exception arg) { Logger.LogError((object)$"[DMLRFirstShotExplosive] CreateUpgrade threw: {arg}"); return; } if ((Object)(object)CustomUpgradeInstance == (Object)null) { Logger.LogError((object)"[DMLRFirstShotExplosive] CustomUpgradeInstance is null after CreateUpgrade - aborting."); return; } try { ApplyCustomPattern(CustomUpgradeInstance); Logger.LogInfo((object)"[DMLRFirstShotExplosive] Explosive Cycle upgrade registered successfully."); } catch (Exception arg2) { Logger.LogError((object)$"[DMLRFirstShotExplosive] 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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, 1].enabled = true; val[0, 1].connections = (Direction)10; val[0, 2].enabled = true; val[0, 2].connections = (Direction)4; val[1, 0].enabled = true; val[1, 2].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 GunHasFirstShotExplosive(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; } } [Serializable] public class UpgradeProperty_DMLR_FirstShotExplosive : UpgradeProperty { public Range explosionRadius; 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("Explosion radius", explosionRadius, upgrade, ref rand, (OverrideType)1, (LabelType)1, default(BoostParams)); } public override void Apply(IGear gear, UpgradeInstance upgrade, ref Random rand) { //IL_001f: 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) ScoutLaserRifle val = (ScoutLaserRifle)(object)((gear is ScoutLaserRifle) ? gear : null); if (!((Object)(object)val == (Object)null)) { float value = explosionRadius.GetValue(ref rand, upgrade, default(BoostParams)); DMLRFirstShotState.SetExplosionRadius(val, value); } } } public static class DMLRFirstShotState { private static readonly Dictionary armedForNextShot = new Dictionary(); private static readonly Dictionary explosiveShotInFlight = new Dictionary(); private static readonly Dictionary explosionRadius = new Dictionary(); private const float DefaultExplosionRadius = 4f; public static void SetExplosionRadius(ScoutLaserRifle gun, float radius) { explosionRadius[gun] = radius; } public static float GetExplosionRadius(ScoutLaserRifle gun) { float value; return explosionRadius.TryGetValue(gun, out value) ? value : 4f; } public static void ArmNextShot(ScoutLaserRifle gun) { armedForNextShot[gun] = true; } public static bool ConsumeArmedForFiring(ScoutLaserRifle gun, float shotDamage) { if (armedForNextShot.TryGetValue(gun, out var value) && value) { armedForNextShot[gun] = false; explosiveShotInFlight[gun] = shotDamage; return true; } return false; } public static bool ConsumeExplosiveHit(ScoutLaserRifle gun, out float shotDamage) { if (explosiveShotInFlight.TryGetValue(gun, out shotDamage)) { explosiveShotInFlight.Remove(gun); return true; } shotDamage = 0f; return false; } public static void Clear(ScoutLaserRifle gun) { armedForNextShot.Remove(gun); explosiveShotInFlight.Remove(gun); explosionRadius.Remove(gun); } } [HarmonyPatch(typeof(ScoutLaserRifle), "OnUpgradesEnabled")] public static class DMLRFirstShotEnablePatch { [CompilerGenerated] private static class <>O { public static DamageCallback <0>__OnDamageTarget; } private static void Postfix(ScoutLaserRifle __instance) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0042: 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_004d: Expected O, but got Unknown __instance.OnModeChanged += delegate(bool value) { DMLRFirstShotModeHandler.OnModeChanged(__instance, value); }; ScoutLaserRifle obj = __instance; DamageCallback onDamageTarget = ((Gun)obj).OnDamageTarget; object obj2 = <>O.<0>__OnDamageTarget; if (obj2 == null) { DamageCallback val = DMLRFirstShotExplosionPatch.OnDamageTarget; <>O.<0>__OnDamageTarget = val; obj2 = (object)val; } ((Gun)obj).OnDamageTarget = (DamageCallback)Delegate.Combine((Delegate?)(object)onDamageTarget, (Delegate?)obj2); } } [HarmonyPatch(typeof(ScoutLaserRifle), "OnUpgradesDisabled")] public static class DMLRFirstShotDisablePatch { [CompilerGenerated] private static class <>O { public static DamageCallback <0>__OnDamageTarget; } private static void Postfix(ScoutLaserRifle __instance) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown DamageCallback onDamageTarget = ((Gun)__instance).OnDamageTarget; object obj = <>O.<0>__OnDamageTarget; if (obj == null) { DamageCallback val = DMLRFirstShotExplosionPatch.OnDamageTarget; <>O.<0>__OnDamageTarget = val; obj = (object)val; } ((Gun)__instance).OnDamageTarget = (DamageCallback)Delegate.Remove((Delegate?)(object)onDamageTarget, (Delegate?)obj); DMLRFirstShotState.Clear(__instance); } } public static class DMLRFirstShotModeHandler { public static void OnModeChanged(ScoutLaserRifle gun, bool isLaserModeActive) { if (!isLaserModeActive && DMLRFirstShotExplosivePlugin.GunHasFirstShotExplosive(gun)) { DMLRFirstShotState.ArmNextShot(gun); } } } [HarmonyPatch(typeof(ScoutLaserRifle), "ModifyBulletData")] public static class DMLRFirstShotModifyPatch { private static void Postfix(ScoutLaserRifle __instance, ref BulletData data, BulletFlags flags) { if (!__instance.IsLaserModeActive && DMLRFirstShotExplosivePlugin.GunHasFirstShotExplosive(__instance)) { DMLRFirstShotState.ConsumeArmedForFiring(__instance, data.damage); } } } public static class DMLRFirstShotExplosionPatch { public static void OnDamageTarget(in DamageCallbackData data) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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) IDamageSource source = data.source; IDamageSource obj = ((source != null) ? source.ParentSource : null); ScoutLaserRifle val = (ScoutLaserRifle)(object)((obj is ScoutLaserRifle) ? obj : null); if (!((Object)(object)val == (Object)null) && !val.IsLaserModeActive && DMLRFirstShotExplosivePlugin.GunHasFirstShotExplosive(val) && DMLRFirstShotState.ConsumeExplosiveHit(val, out var shotDamage)) { Vector3 position = data.position; float explosionRadius = DMLRFirstShotState.GetExplosionRadius(val); GameManager.Instance.SpawnExplosionVisual_ServerRpc(position, explosionRadius, (EffectType)4); if (NetworkManager.Singleton.IsServer) { DamageData val2 = default(DamageData); ((DamageData)(ref val2))..ctor(shotDamage, (EffectType)4, 0f); IDamageSource.DamageTargetsInSphere((IDamageSource)(object)val, ref position, explosionRadius, (TargetType)5, ref val2, 0f, 1f); } } } } }