Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ShotgunPlus v1.0.2
ShotgunPlus.dll
Decompiled 2 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using CSync.Extensions; using CSync.Lib; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using LethalLib.Modules; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.Rendering; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ShotgunPlus")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.2.0")] [assembly: AssemblyInformationalVersion("1.0.2")] [assembly: AssemblyProduct("ShotgunPlus")] [assembly: AssemblyTitle("ShotgunPlus")] [assembly: AssemblyVersion("1.0.2.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 ShotgunPlus { internal static class Barrels { private class State { public byte[] b = new byte[2]; } private static readonly ConditionalWeakTable<ShotgunItem, State> table = new ConditionalWeakTable<ShotgunItem, State>(); internal static readonly FieldRef<NutcrackerEnemyAI, ShotgunItem> nutGun = AccessTools.FieldRefAccess<NutcrackerEnemyAI, ShotgunItem>("gun"); private static byte[] Of(ShotgunItem g) { return table.GetOrCreateValue(g).b; } internal static byte Get(ShotgunItem g, int barrel) { if (!((Object)(object)g != (Object)null) || barrel < 0 || barrel >= 2 || barrel >= g.shellsLoaded) { return 0; } return Of(g)[barrel]; } internal static void Set(ShotgunItem g, int barrel, byte t) { if (!((Object)(object)g == (Object)null) && barrel >= 0 && barrel <= 1) { Of(g)[barrel] = t; Visuals(g); } } internal static void Fired(ShotgunItem g, int shells) { byte[] array = Of(g); if (shells >= 2) { array[0] = 0; array[1] = 0; } else { array[0] = array[1]; array[1] = 0; } Visuals(g); } internal static void Visuals(ShotgunItem g) { if (!((Object)(object)g == (Object)null)) { byte[] array = Of(g); Material val = ShellRegistry.Mat(array[0]); Material val2 = ShellRegistry.Mat(array[1]); if ((Object)(object)g.shotgunShellLeft != (Object)null && (Object)(object)val != (Object)null) { ((Renderer)g.shotgunShellLeft).sharedMaterial = val; } if ((Object)(object)g.shotgunShellRight != (Object)null && (Object)(object)val2 != (Object)null) { ((Renderer)g.shotgunShellRight).sharedMaterial = val2; } } } internal static void InHand(ShotgunItem g, byte t) { Material val = ShellRegistry.Mat(t); if ((Object)(object)g != (Object)null && (Object)(object)g.shotgunShellInHand != (Object)null && (Object)(object)val != (Object)null) { ((Renderer)g.shotgunShellInHand).sharedMaterial = val; } } internal static void Share(ShotgunItem g) { if (!((Object)(object)g == (Object)null) && !((Object)(object)((NetworkBehaviour)g).NetworkObject == (Object)null)) { byte[] array = Of(g); Net.Send(Net.Kind.Barrels, ((NetworkBehaviour)g).NetworkObjectId, array[0], array[1]); } } internal static void Received(ulong id, byte b0, byte b1) { if (!((Object)(object)NetworkManager.Singleton == (Object)null) && NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(id, out var value)) { ShotgunItem component = ((Component)value).GetComponent<ShotgunItem>(); if (!((Object)(object)component == (Object)null) && !((NetworkBehaviour)component).IsOwner) { byte[] array = Of(component); array[0] = Clamp(b0); array[1] = Clamp(b1); Visuals(component); ReloadPatches.Refresh(component); } } } private static byte Clamp(int id) { if (id < 0 || id >= ShellRegistry.All.Count) { return 0; } return (byte)id; } [HarmonyPatch(typeof(NutcrackerEnemyAI), "ReloadGunClientRpc")] [HarmonyPostfix] private static void NutcrackerReload(NutcrackerEnemyAI __instance) { ShotgunItem val = nutGun.Invoke(__instance); if (!((Object)(object)val == (Object)null)) { byte[] array = Of(val); array[0] = 0; array[1] = 0; Visuals(val); } } [HarmonyPatch(typeof(NutcrackerEnemyAI), "FireGun")] [HarmonyPrefix] private static void NutcrackerFire(NutcrackerEnemyAI __instance, ref Vector3 gunForward) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) ShotgunItem val = nutGun.Invoke(__instance); if (!((Object)(object)val == (Object)null)) { byte b = Get(val, 0); if (b != 0) { gunForward = ((Vector3)(ref gunForward)).normalized * (float)(1 + 4 * b); } } } [HarmonyPatch(typeof(ShotgunItem), "GetItemDataToSave")] [HarmonyPostfix] private static void Save(ShotgunItem __instance, ref int __result) { int num = Mathf.Clamp(__instance.shellsLoaded, 0, 2); byte b = Get(__instance, 0); byte b2 = Get(__instance, 1); if (b != 0 || b2 != 0) { __result = num + 10 * b + 100 * b2; } } [HarmonyPatch(typeof(ShotgunItem), "LoadItemSaveData")] [HarmonyPostfix] private static void Load(ShotgunItem __instance, int saveData) { if (saveData >= 10) { __instance.shellsLoaded = Mathf.Clamp(saveData % 10, 0, 2); byte[] array = Of(__instance); array[0] = Clamp(saveData / 10 % 10); array[1] = Clamp(saveData / 100); Visuals(__instance); } } } internal static class Net { internal enum Kind : byte { Barrels, Explosion } [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnMessage; } private const string Name = "Miles.ShotgunPlus"; [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPostfix] private static void Hook() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown CustomMessagingManager val = (((Object)(object)NetworkManager.Singleton != (Object)null) ? NetworkManager.Singleton.CustomMessagingManager : null); if (val == null) { Plugin.Log.LogWarning((object)"No network messages yet: shell types won't be shared this lobby."); return; } try { val.UnregisterNamedMessageHandler("Miles.ShotgunPlus"); } catch { } object obj2 = <>O.<0>__OnMessage; if (obj2 == null) { HandleNamedMessageDelegate val2 = OnMessage; <>O.<0>__OnMessage = val2; obj2 = (object)val2; } val.RegisterNamedMessageHandler("Miles.ShotgunPlus", (HandleNamedMessageDelegate)obj2); } internal static void Send(Kind kind, ulong id, byte a = 0, byte b = 0) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null) { return; } if (singleton.IsServer) { if (kind != Kind.Barrels) { Do(kind, id, a, b); } Forward(kind, id, a, b); return; } FastBufferWriter w = default(FastBufferWriter); ((FastBufferWriter)(ref w))..ctor(16, (Allocator)2, -1); try { Write(ref w, kind, id, a, b); singleton.CustomMessagingManager.SendNamedMessage("Miles.ShotgunPlus", 0uL, w, (NetworkDelivery)3); } finally { ((FastBufferWriter)(ref w)).Dispose(); } } private static void Forward(Kind kind, ulong id, byte a, byte b) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) FastBufferWriter w = default(FastBufferWriter); ((FastBufferWriter)(ref w))..ctor(16, (Allocator)2, -1); try { Write(ref w, kind, id, a, b); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("Miles.ShotgunPlus", w, (NetworkDelivery)3); } finally { ((FastBufferWriter)(ref w)).Dispose(); } } private static void Write(ref FastBufferWriter w, Kind kind, ulong id, byte a, byte b) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) byte b2 = (byte)kind; ((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref b2, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref a, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref b, default(ForPrimitives)); } private static void OnMessage(ulong sender, FastBufferReader r) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) try { byte kind = default(byte); ((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref kind, default(ForPrimitives)); ulong id = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); byte a = default(byte); ((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref a, default(ForPrimitives)); byte b = default(byte); ((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives)); NetworkManager singleton = NetworkManager.Singleton; if (!singleton.IsServer || sender != 0L) { Do((Kind)kind, id, a, b); if (singleton.IsServer) { Forward((Kind)kind, id, a, b); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Shell message: " + ex.Message)); } } private static void Explosion(ulong id) { if (!((Object)(object)NetworkManager.Singleton == (Object)null) && NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(id, out var value)) { EnemyAI component = ((Component)value).GetComponent<EnemyAI>(); if ((Object)(object)component != (Object)null && !component.isEnemyDead) { component.HitFromExplosion(0f); } } } private static void Do(Kind kind, ulong id, byte a, byte b) { switch (kind) { case Kind.Barrels: Barrels.Received(id, a, b); break; case Kind.Explosion: Explosion(id); break; } } } internal static class Compat { private static bool done; internal static void TakeOverShotgun() { //IL_00f7: Unknown result type (might be due to invalid IL or missing references) if (done) { return; } done = true; try { HashSet<string> hashSet = new HashSet<string>(); int num = 0; foreach (MethodBase item in Harmony.GetAllPatchedMethods().ToList()) { Type declaringType = item.DeclaringType; if (declaringType != typeof(ShotgunItem) && declaringType != typeof(NutcrackerEnemyAI) && declaringType != typeof(GunAmmo)) { continue; } Patches patchInfo = Harmony.GetPatchInfo(item); if (patchInfo == null) { continue; } foreach (Patch item2 in patchInfo.Prefixes.Concat(patchInfo.Postfixes).Concat(patchInfo.Transpilers).Concat(patchInfo.Finalizers) .ToList()) { if (!(item2.owner == "Miles.ShotgunPlus") && item2.owner.IndexOf("BetterShotgun", StringComparison.OrdinalIgnoreCase) >= 0) { new Harmony(item2.owner).Unpatch(item, item2.PatchMethod); hashSet.Add(item2.owner); num++; } } } if (num > 0) { Plugin.Log.LogWarning((object)(string.Format("{0} is installed too. ShotgunPlus does what it does, so its {1} shotgun ", string.Join(", ", hashSet), num) + "patches were turned off (two mods changing the same shot would fire it twice). You can remove it.")); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("BetterShotgun check: " + ex.Message)); } } } internal static class EnemyFixes { internal const int HitId = 7348; [HarmonyPatch(typeof(CaveDwellerAI), "HitEnemy")] [HarmonyPrefix] private static void ManeaterBefore(CaveDwellerAI __instance, out int __state) { __state = ((EnemyAI)__instance).enemyHP; } [HarmonyPatch(typeof(CaveDwellerAI), "HitEnemy")] [HarmonyPostfix] private static void ManeaterAfter(CaveDwellerAI __instance, int force, int hitID, int __state) { if (Plugin.Cfg.FixManeater.Value && ((EnemyAI)__instance).currentBehaviourStateIndex != 0) { Rest((EnemyAI)(object)__instance, force, hitID, __state); } } [HarmonyPatch(typeof(CadaverBloomAI), "HitEnemy")] [HarmonyPrefix] private static void BloomBefore(CadaverBloomAI __instance, out int __state) { __state = ((EnemyAI)__instance).enemyHP; } [HarmonyPatch(typeof(CadaverBloomAI), "HitEnemy")] [HarmonyPostfix] private static void BloomAfter(CadaverBloomAI __instance, int force, int hitID, int __state) { if (Plugin.Cfg.FixCadaverBloom.Value) { Rest((EnemyAI)(object)__instance, force, hitID, __state); } } private static void Rest(EnemyAI e, int force, int hitID, int before) { if (hitID != 7348 || force <= 1 || before <= 0 || e.isEnemyDead) { return; } int num = before - e.enemyHP; if (num <= 0) { return; } int num2 = force - num; if (num2 > 0) { bool num3 = e.enemyHP > 0; e.enemyHP -= num2; if (num3 && e.enemyHP <= 0 && ((NetworkBehaviour)e).IsOwner) { e.KillEnemyOnOwnerClient(false); } } } } internal static class ItemSync { private const int ShotgunFallbackPrice = 800; private const int ShellFallbackPrice = 50; internal const int ShellMinValue = 15; internal const int ShellMaxValue = 25; private static Item shotgun; private static Item shell; internal static bool IsHost { get { if ((Object)(object)NetworkManager.Singleton != (Object)null) { return NetworkManager.Singleton.IsServer; } return false; } } private static bool InShop(Item i) { return Items.shopItems.Any((ShopItem s) => s != null && ((Object)(object)s.origItem == (Object)(object)i || (Object)(object)s.item == (Object)(object)i)); } private static bool InScrap(Item i) { return Items.scrapItems.Any((ScrapItem s) => s != null && ((Object)(object)s.origItem == (Object)(object)i || (Object)(object)s.item == (Object)(object)i)); } private static void Step(string what, Action a) { try { a(); } catch (Exception ex) { Plugin.Log.LogError((object)(what + " failed: " + ex.Message)); } } internal static void Register(Item gun, Item ammo) { ShotgunConfig cfg = Plugin.Cfg; shotgun = gun; shell = ammo; if ((Object)(object)gun == (Object)null) { Plugin.Log.LogError((object)"Vanilla Shotgun item not found: store and scrap changes are off."); } else { gun.itemName = "Shotgun"; if (InShop(gun)) { Plugin.Log.LogInfo((object)"The shotgun is already in the store (another mod): its price is set here once in a lobby."); } else { Step("Shotgun store entry", delegate { Items.RegisterShopItem(gun, (cfg.ShotgunPrice.Value >= 0) ? cfg.ShotgunPrice.Value : 800); }); } if (cfg.ShotgunRarity.Value > 0 && !InScrap(gun)) { Step("Shotgun scrap entry", delegate { Items.RegisterScrap(gun, cfg.ShotgunRarity.Value, (LevelTypes)(-1)); }); } } if ((Object)(object)ammo == (Object)null) { Plugin.Log.LogError((object)"Vanilla shell item (GunAmmo) not found: shell changes are off."); } else { ammo.itemName = "Buck Shell"; if (InShop(ammo)) { Plugin.Log.LogInfo((object)"The shell is already in the store (another mod): its price is set here once in a lobby."); } else { Step("Shell store entry", delegate { Items.RegisterShopItem(ammo, (cfg.ShellPrice.Value >= 0) ? cfg.ShellPrice.Value : 50); }); } if (InScrap(ammo)) { Plugin.Log.LogWarning((object)"The shell is already scrap (another mod, like BetterShotgun): that mod's scrap rarity is used, not ShellRarity."); } else { Step("Shell scrap entry", delegate { Items.RegisterScrap(ammo, Mathf.Max(cfg.ShellRarity.Value, 0), (LevelTypes)(-1)); }); } foreach (Item item in ((IEnumerable<Item>)(object)new Item[2] { ammo, ScrapCopy(ammo) }).Distinct()) { if (!((Object)(object)item == (Object)null)) { item.minValue = 37; item.maxValue = 62; } } Step("Shell types", delegate { ShellRegistry.Setup(ammo); }); } Plugin.Log.LogInfo((object)$"Shotgun and shells registered (shell scrap rarity {Mathf.Max(cfg.ShellRarity.Value, 0)}, shotgun scrap rarity {Mathf.Max(cfg.ShotgunRarity.Value, 0)})."); } internal static void Apply(string reason) { ShotgunConfig cfg = Plugin.Cfg; if (cfg == null) { return; } try { if ((Object)(object)shotgun != (Object)null) { ApplyPrice(shotgun, cfg.ShotgunPrice.Value); } if ((Object)(object)shell != (Object)null) { ApplyPrice(shell, cfg.ShellPrice.Value); } Plugin.Log.LogInfo((object)$"Store prices ({reason}): shotgun {cfg.ShotgunPrice.Value}, Buck Shell {cfg.ShellPrice.Value}"); } catch (Exception arg) { Plugin.Log.LogError((object)$"Store prices ({reason}) failed: {arg}"); } } internal static void EnsureNetworkPrefabs() { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.IsListening || singleton.NetworkConfig == null || singleton.NetworkConfig.Prefabs == null) { return; } List<Item> list = new List<Item> { shotgun, shell }; foreach (ShellDef item in ShellRegistry.All) { list.Add(item.Item); } int num = 0; foreach (Item item2 in list.Where((Item i) => (Object)(object)i != (Object)null).Distinct()) { List<GameObject> list2 = new List<GameObject> { item2.spawnPrefab }; foreach (ScrapItem scrapItem in Items.scrapItems) { if (scrapItem != null && ((Object)(object)scrapItem.origItem == (Object)(object)item2 || (Object)(object)scrapItem.item == (Object)(object)item2) && (Object)(object)scrapItem.item != (Object)null) { list2.Add(scrapItem.item.spawnPrefab); } } foreach (GameObject item3 in list2) { if (!((Object)(object)item3 == (Object)null) && !((Object)(object)item3.GetComponent<NetworkObject>() == (Object)null) && !singleton.NetworkConfig.Prefabs.Contains(item3)) { try { singleton.AddNetworkPrefab(item3); num++; } catch (Exception ex) { Plugin.Log.LogWarning((object)("Network prefab " + ((Object)item3).name + ": " + ex.Message)); } } } } if (num > 0) { Plugin.Log.LogInfo((object)$"{num} shotgun/shell prefabs added to the network list."); } } internal static Item ScrapCopy(Item item) { return ((IEnumerable<ScrapItem>)Items.scrapItems).FirstOrDefault((Func<ScrapItem, bool>)((ScrapItem s) => (Object)(object)s.origItem == (Object)(object)item || (Object)(object)s.item == (Object)(object)item))?.item; } internal static void ApplyPrice(Item item, int price) { Terminal val = Object.FindObjectOfType<Terminal>(); if ((Object)(object)val == (Object)null || (Object)(object)val.terminalNodes == (Object)null || val.buyableItemsList == null) { return; } int index = Array.IndexOf(val.buyableItemsList, item); if (index < 0) { return; } TerminalKeyword[] allKeywords = val.terminalNodes.allKeywords; TerminalKeyword val2 = ((IEnumerable<TerminalKeyword>)allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => (Object)(object)k != (Object)null && k.word == "buy")); TerminalKeyword val3 = ((IEnumerable<TerminalKeyword>)allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => (Object)(object)k != (Object)null && k.word == "info")); if ((Object)(object)val2 == (Object)null || val2.compatibleNouns == null) { return; } ShopItem val4 = ((IEnumerable<ShopItem>)Items.shopItems).FirstOrDefault((Func<ShopItem, bool>)((ShopItem s) => (Object)(object)s.origItem == (Object)(object)item || (Object)(object)s.item == (Object)(object)item)); if (price >= 0) { item.creditsWorth = price; CompatibleNoun[] compatibleNouns = val2.compatibleNouns; for (int num = 0; num < compatibleNouns.Length; num++) { TerminalNode val5 = compatibleNouns[num]?.result; if ((Object)(object)val5 == (Object)null || val5.buyItemIndex != index) { continue; } val5.itemCost = price; if (val5.terminalOptions == null) { continue; } CompatibleNoun[] terminalOptions = val5.terminalOptions; foreach (CompatibleNoun val6 in terminalOptions) { if ((Object)(object)val6?.result != (Object)null && val6.result.buyItemIndex == index) { val6.result.itemCost = price; } } } return; } List<TerminalKeyword> itemWords = (from n in val2.compatibleNouns where (Object)(object)n?.result != (Object)null && n.result.buyItemIndex == index select n.noun).ToList(); if (itemWords.Count > 0) { val2.compatibleNouns = val2.compatibleNouns.Where((CompatibleNoun n) => n == null || !itemWords.Contains(n.noun)).ToArray(); if (val3?.compatibleNouns != null) { val3.compatibleNouns = val3.compatibleNouns.Where((CompatibleNoun n) => n == null || !itemWords.Contains(n.noun)).ToArray(); } val.terminalNodes.allKeywords = allKeywords.Where((TerminalKeyword k) => !itemWords.Contains(k)).ToArray(); } if (val4 != null) { val4.wasRemoved = true; } } } internal static class ItemSyncPatch { [HarmonyPatch(typeof(StartOfRound), "Start")] [HarmonyPostfix] [HarmonyPriority(200)] private static void LobbyStart() { if (ItemSync.IsHost) { ItemSync.Apply("host lobby start"); } } } public class Keybinds : LcInputActions { [InputAction("<Keyboard>/r", Name = "Reload shotgun")] public InputAction ReloadKey { get; set; } [InputAction("<Keyboard>/t", Name = "Shotgun fire mode")] public InputAction ModeKey { get; set; } } internal static class PelletFx { private static Material tracerMat; private static bool triedMat; private static Shader unlit; private static readonly Dictionary<Color, Material> tinted = new Dictionary<Color, Material>(); internal static void BeforeVanillaShot(ShotgunItem gun) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)gun.gunShootParticle == (Object)null)) { EmissionModule emission = gun.gunShootParticle.emission; ((EmissionModule)(ref emission)).enabled = Plugin.Cfg.Look.Value == PelletLook.Off; } } internal static void Pellet(ShotgunItem gun, Vector3 from, Vector3 to, bool hit, ShellDef shell = null) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) PelletLook value = Plugin.Cfg.Look.Value; if (value == PelletLook.Off) { return; } try { if (value == PelletLook.TracersAndSparks) { Vector3 val = to - from; if (((Vector3)(ref val)).sqrMagnitude > 1f) { Material val2 = TracerMaterial(shell?.TracerColor); if ((Object)(object)val2 != (Object)null) { Tracer.Spawn(from, to, val2); } } } if (hit) { Puff(gun, to, from); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Pellet effect: " + ex.Message)); } } private static Material TracerMaterial(Color? colour) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) if (!triedMat) { triedMat = true; unlit = Shader.Find("HDRP/Unlit"); if ((Object)(object)unlit == (Object)null) { Plugin.Log.LogWarning((object)"HDRP/Unlit shader not found: streaks are off, puffs still work."); return null; } tracerMat = Make(unlit, "ShotgunPlus Streak", new Color(1f, 0.72f, 0.32f, 1f)); } if ((Object)(object)unlit == (Object)null || !colour.HasValue) { return tracerMat; } if (!tinted.TryGetValue(colour.Value, out var value)) { value = (tinted[colour.Value] = Make(unlit, "ShotgunPlus Streak " + tinted.Count, colour.Value)); } return value; } private static Material Make(Shader s, string name, Color c) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown Material val = new Material(s) { name = name }; val.SetColor("_UnlitColor", c); val.SetColor("_Color", c); return val; } private static void Puff(ShotgunItem gun, Vector3 at, Vector3 from) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)gun.gunShootParticle == (Object)null) { return; } ParticleSystem val = null; ParticleSystem[] componentsInChildren = ((Component)gun.gunShootParticle).GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem val2 in componentsInChildren) { if ((Object)(object)val2 != (Object)(object)gun.gunShootParticle) { val = val2; break; } } if (!((Object)(object)val == (Object)null)) { Vector3 val3 = from - at; Vector3 normalized = ((Vector3)(ref val3)).normalized; GameObject val4 = Object.Instantiate<GameObject>(((Component)val).gameObject, at + normalized * 0.05f, Quaternion.LookRotation(normalized)); ((Object)val4).name = "ShotgunPlus Puff"; Light[] componentsInChildren2 = val4.GetComponentsInChildren<Light>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { ((Behaviour)componentsInChildren2[i]).enabled = false; } MonoBehaviour[] componentsInChildren3 = val4.GetComponentsInChildren<MonoBehaviour>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { ((Behaviour)componentsInChildren3[i]).enabled = false; } val4.transform.localScale = ((Component)val).transform.lossyScale * 0.45f; componentsInChildren = val4.GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem obj in componentsInChildren) { MainModule main = obj.main; ((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)0; ((MainModule)(ref main)).startSpeedMultiplier = ((MainModule)(ref main)).startSpeedMultiplier * 0.3f; CollisionModule collision = obj.collision; ((CollisionModule)(ref collision)).enabled = false; SubEmittersModule subEmitters = obj.subEmitters; ((SubEmittersModule)(ref subEmitters)).enabled = false; } val4.GetComponent<ParticleSystem>().Play(true); Object.Destroy((Object)(object)val4, 2f); } } } internal class Tracer : MonoBehaviour { private const float Speed = 300f; private const float Length = 4f; private const float Width = 0.02f; private LineRenderer line; private Vector3 from; private Vector3 dir; private float dist; private float travelled; internal static void Spawn(Vector3 from, Vector3 to, Material mat) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("ShotgunPlus Streak"); Tracer tracer = val.AddComponent<Tracer>(); tracer.from = from; tracer.dist = Vector3.Distance(from, to); tracer.dir = (to - from) / tracer.dist; tracer.line = val.AddComponent<LineRenderer>(); tracer.line.useWorldSpace = true; tracer.line.positionCount = 2; ((Renderer)tracer.line).sharedMaterial = mat; ((Renderer)tracer.line).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)tracer.line).receiveShadows = false; tracer.line.startWidth = 0.008f; tracer.line.endWidth = 0.02f; tracer.line.SetPosition(0, from); tracer.line.SetPosition(1, from); Object.Destroy((Object)(object)val, 1f); } private void Update() { //IL_0064: 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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) travelled += 300f * Time.deltaTime; float num = Mathf.Min(travelled, dist); float num2 = Mathf.Clamp(travelled - 4f, 0f, dist); if (num2 >= dist) { Object.Destroy((Object)(object)((Component)this).gameObject); return; } line.SetPosition(0, from + dir * num2); line.SetPosition(1, from + dir * num); } } internal static class PelletPatches { private class Hits { public readonly Dictionary<PlayerControllerB, int> players = new Dictionary<PlayerControllerB, int>(); public readonly Dictionary<EnemyAI, int[]> enemies = new Dictionary<EnemyAI, int[]>(); public readonly Dictionary<EnemyAI, IHittable> enemyHit = new Dictionary<EnemyAI, IHittable>(); public readonly Dictionary<IHittable, int[]> others = new Dictionary<IHittable, int[]>(); } private const float Range = 30f; private const int EnemyLayerMask = 524288; private const int DoorLayerMask = 512; private static readonly FieldRef<ShotgunItem, EnemyAI> heldByEnemy = AccessTools.FieldRefAccess<ShotgunItem, EnemyAI>("heldByEnemy"); private static readonly FieldRef<ShotgunItem, bool> sendingRpc = AccessTools.FieldRefAccess<ShotgunItem, bool>("localClientSendingShootGunRPC"); private static readonly MethodInfo shootGun = AccessTools.Method(typeof(ShotgunItem), "ShootGun", (Type[])null, (Type[])null); private static readonly MethodInfo shootServerRpc = AccessTools.Method(typeof(ShotgunItem), "ShootGunServerRpc", (Type[])null, (Type[])null); [HarmonyPatch(typeof(ShotgunItem), "ShootGunAndSync")] [HarmonyPrefix] private static bool ShootAndSync(ShotgunItem __instance, bool heldByPlayer) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) if (!heldByPlayer || (Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) { return true; } Transform transform = ((Component)((GrabbableObject)__instance).playerHeldBy.gameplayCamera).transform; Vector3 val = transform.position - transform.up * 0.45f; ShotMode num = ShotModes.ModeFor(__instance); int num2 = Barrels.Get(__instance, 0); int num3 = ((num == ShotMode.Double) ? Barrels.Get(__instance, 1) : 0); int num4 = (int)(num + 4 * num2 + 32 * num3); object[] parameters = new object[2] { val, transform.forward * (float)num4 }; shootGun.Invoke(__instance, parameters); sendingRpc.Invoke(__instance) = true; shootServerRpc.Invoke(__instance, parameters); return false; } [HarmonyPatch(typeof(ShotgunItem), "ShootGun")] [HarmonyPrefix] private static bool ShootGun(ShotgunItem __instance, Vector3 shotgunPosition, Vector3 shotgunForward) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) try { Shoot(__instance, shotgunPosition, shotgunForward); } catch (Exception ex) { Plugin.Log.LogError((object)("Shotgun shot failed: " + ex)); } return false; } private static void Shoot(ShotgunItem gun, Vector3 pos, Vector3 fwd) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0351: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_05df: Unknown result type (might be due to invalid IL or missing references) //IL_05e0: Unknown result type (might be due to invalid IL or missing references) //IL_05e6: Unknown result type (might be due to invalid IL or missing references) //IL_0626: Unknown result type (might be due to invalid IL or missing references) //IL_04d1: Unknown result type (might be due to invalid IL or missing references) //IL_05ac: Unknown result type (might be due to invalid IL or missing references) float magnitude = ((Vector3)(ref fwd)).magnitude; int num = Mathf.Max(1, Mathf.RoundToInt(magnitude)); ShotMode shotMode = (ShotMode)Mathf.Clamp(num % 4, 1, 3); ShellDef shellDef = ShellRegistry.Get(num / 4 % 8); ShellDef shell = ShellRegistry.Get(num / 32); fwd = ((magnitude > 0.0001f) ? (fwd / magnitude) : Vector3.forward); int num2 = ((shotMode != ShotMode.Double) ? 1 : 2); gun.isReloading = false; bool flag = ((GrabbableObject)gun).isHeld && (Object)(object)((GrabbableObject)gun).playerHeldBy != (Object)null; PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); bool flag2 = flag && (Object)(object)((GrabbableObject)gun).playerHeldBy == (Object)(object)val; if (flag2) { ((GrabbableObject)gun).playerHeldBy.playerBodyAnimator.SetTrigger("ShootShotgun"); } RoundManager.PlayRandomClip(gun.gunShootAudio, gun.gunShootSFX, true, 1f, 1840, 1000); WalkieTalkie.TransmitOneShotAudio(gun.gunShootAudio, gun.gunShootSFX[0], 1f); PelletFx.BeforeVanillaShot(gun); gun.gunShootParticle.Play(true); gun.shellsLoaded = Mathf.Clamp(gun.shellsLoaded - num2, 0, 2); Barrels.Fired(gun, num2); ReloadPatches.Refresh(gun); if ((Object)(object)val == (Object)null) { return; } float num3 = Vector3.Distance(((Component)val).transform.position, gun.shotgunRayPoint.position); float num4 = 0f; if (num3 < 5f) { num4 = 0.8f; HUDManager.Instance.ShakeCamera((ScreenShakeType)1); } else if (num3 < 15f) { num4 = 0.5f; HUDManager.Instance.ShakeCamera((ScreenShakeType)1); } else if (num3 < 23f) { HUDManager.Instance.ShakeCamera((ScreenShakeType)0); } if (num4 > 0f && !flag2 && SoundManager.Instance.timeSinceEarsStartedRinging > 16f) { ((MonoBehaviour)gun).StartCoroutine(Ears(num4)); } if (flag) { Vector3 val2 = Vector3.Cross(Vector3.up, fwd); Vector3 val3 = ((((Vector3)(ref val2)).sqrMagnitude > 0.0001f) ? Vector3.Cross(fwd, ((Vector3)(ref val2)).normalized) : Vector3.up); pos += val3 * 0.25f; } Random rnd = new Random(Seed(pos, fwd * (float)num)); Hits hits = new Hits(); Vector3 position = gun.shotgunRayPoint.position; if (shotMode == ShotMode.Choke && shellDef.Choke) { float range = Mathf.Clamp(Plugin.Cfg.ChokeDistance.Value, 0.5f, 25f); Vector3 end; bool flag3 = Cast(gun, flag, pos, fwd, range, shellDef, hits, out end); PelletFx.Pellet(gun, position, end, flag3, shellDef); if (!flag3) { Burst(gun, flag, end, fwd, end, shellDef, rnd, hits); } } else { Burst(gun, flag, pos, fwd, position, shellDef, rnd, hits); if (shotMode == ShotMode.Double) { Burst(gun, flag, pos, fwd, position, shell, rnd, hits); } } if (hits.players.TryGetValue(val, out var value) && !val.isPlayerDead && value > 0) { val.DamagePlayer(value, true, true, (CauseOfDeath)7, 0, false, fwd * 30f); } foreach (KeyValuePair<EnemyAI, int[]> e in hits.enemies) { int t; for (t = 0; t < e.Value.Length; t++) { if (e.Value[t] > 0) { Try(delegate { ShellRegistry.Get(t).OnEnemyHitSeen?.Invoke(gun, e.Key); }); } } } if (((NetworkBehaviour)gun).IsOwner) { foreach (KeyValuePair<EnemyAI, int[]> e2 in hits.enemies) { IHittable h = hits.enemyHit[e2.Key]; h.Hit(Damage(e2.Value), fwd, ((GrabbableObject)gun).playerHeldBy, true, 7348); int t2; for (t2 = 0; t2 < e2.Value.Length; t2++) { if (e2.Value[t2] > 0) { Try(delegate { ShellRegistry.Get(t2).OnEnemyHit?.Invoke(gun, e2.Key, h); }); } } } foreach (KeyValuePair<IHittable, int[]> other in hits.others) { other.Key.Hit(Damage(other.Value), fwd, ((GrabbableObject)gun).playerHeldBy, true, 7348); } } Ray val4 = default(Ray); ((Ray)(ref val4))..ctor(pos, fwd); RaycastHit val5 = default(RaycastHit); if (Physics.Raycast(val4, ref val5, 30f, StartOfRound.Instance.collidersAndRoomMaskAndDefault | 0x200, (QueryTriggerInteraction)1)) { ((Component)gun.gunBulletsRicochetAudio).transform.position = ((Ray)(ref val4)).GetPoint(((RaycastHit)(ref val5)).distance - 0.5f); gun.gunBulletsRicochetAudio.Play(); } } private static int Damage(int[] perShell) { int num = 0; for (int i = 0; i < perShell.Length; i++) { if (perShell[i] > 0) { int n = perShell[i]; ShellDef def = ShellRegistry.Get(i); num += Math.Max(1, Get(() => def.EnemyDamage(n), n / 2 + 1)); } } return Math.Max(1, num); } private static T Get<T>(Func<T> f, T fallback) { try { return f(); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Shell setting: " + ex.Message)); return fallback; } } private static void Try(Action a) { try { a(); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Shell effect: " + ex.Message)); } } private static void Burst(ShotgunItem gun, bool playerFired, Vector3 from, Vector3 fwd, Vector3 drawFrom, ShellDef shell, Random rnd, Hits hits) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Clamp(Get(shell.Pellets, 10), 1, 40); int num2 = Mathf.RoundToInt((float)num * 0.3f); float num3 = Mathf.Clamp(shell.Spread, 0f, 45f); float num4 = num3 / 4f; for (int i = 0; i < num; i++) { Vector3 dir = Spread(rnd, fwd, (i < num2) ? num4 : num3); Vector3 end; bool hit = Cast(gun, playerFired, from, dir, 30f, shell, hits, out end); PelletFx.Pellet(gun, drawFrom, end, hit, shell); } } private static bool Cast(ShotgunItem gun, bool playerFired, Vector3 from, Vector3 dir, float range, ShellDef shell, Hits hits, out Vector3 end) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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) //IL_006b: 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) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) int num = StartOfRound.Instance.collidersRoomMaskDefaultAndPlayers | 0x80000 | 0x200; end = from + dir * range; RaycastHit[] array = Physics.RaycastAll(new Ray(from, dir), range, num, (QueryTriggerInteraction)2); Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance)); RaycastHit[] array2 = array; IHittable val2 = default(IHittable); for (int num2 = 0; num2 < array2.Length; num2++) { RaycastHit val = array2[num2]; if (((Component)((RaycastHit)(ref val)).transform).TryGetComponent<IHittable>(ref val2)) { PlayerControllerB val3 = (PlayerControllerB)(object)((val2 is PlayerControllerB) ? val2 : null); if (val3 != null) { if ((Object)(object)val3 == (Object)(object)((GrabbableObject)gun).playerHeldBy || val3.isPlayerDead) { continue; } hits.players[val3] = (hits.players.TryGetValue(val3, out var value) ? value : 0) + Math.Max(0, Get(shell.PlayerDamagePerPellet, 20)); } else { EnemyAICollisionDetect val4 = (EnemyAICollisionDetect)(object)((val2 is EnemyAICollisionDetect) ? val2 : null); if (val4 != null) { EnemyAI mainScript = val4.mainScript; if ((Object)(object)mainScript == (Object)null || (Object)(object)mainScript == (Object)(object)heldByEnemy.Invoke(gun) || mainScript.isEnemyDead || mainScript.enemyHP <= 0 || !mainScript.enemyType.canDie) { continue; } Count(hits.enemies, mainScript, shell); hits.enemyHit[mainScript] = (IHittable)(object)val4; } else { if (!playerFired) { continue; } Count(hits.others, val2, shell); } } } else if (((RaycastHit)(ref val)).collider.isTrigger) { continue; } end = ((RaycastHit)(ref val)).point; return true; } return false; } private static void Count<T>(Dictionary<T, int[]> d, T key, ShellDef shell) { if (!d.TryGetValue(key, out var value)) { value = (d[key] = new int[8]); } value[shell.Id]++; } private static IEnumerator Ears(float severity) { yield return (object)new WaitForSeconds(0.6f); SoundManager.Instance.earsRingingTimer = severity; } private static int Seed(Vector3 p, Vector3 f) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) int num = 17; float[] array = new float[6] { p.x, p.y, p.z, f.x, f.y, f.z }; foreach (float value in array) { num = num * 31 + BitConverter.ToInt32(BitConverter.GetBytes(value), 0); } return num; } private static Vector3 Spread(Random r, Vector3 fwd, float angle) { //IL_006f: 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) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) float num = (float)(r.NextDouble() * 2.0 - 1.0); float num2 = (float)(r.NextDouble() * Math.PI * 2.0); float num3 = Mathf.Sqrt(1f - num * num); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(num3 * Mathf.Cos(num2), num3 * Mathf.Sin(num2), num); float num4 = angle * Mathf.Sqrt((float)r.NextDouble()); if (Vector3.Angle(fwd, val) < num4) { val = -val; } return Vector3.RotateTowards(fwd, val, num4 * (MathF.PI / 180f), 0f); } } [BepInPlugin("Miles.ShotgunPlus", "ShotgunPlus", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency("com.sigurd.csync", "5.0.0")] public class Plugin : BaseUnityPlugin { public const string Guid = "Miles.ShotgunPlus"; public const string Name = "ShotgunPlus"; public const string Version = "1.0.2"; internal static ManualLogSource Log; internal static ShotgunConfig Cfg; internal static Keybinds Keys; private static bool registered; private void Awake() { //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Cfg = new ShotgunConfig(((BaseUnityPlugin)this).Config); ((SyncedConfig2<ShotgunConfig>)Cfg).InitialSyncCompleted += delegate { ItemSync.Apply("config synced from host"); }; Keys = new Keybinds(); Keys.ReloadKey.performed += OnReloadKey; Keys.ModeKey.performed += OnModeKey; SceneManager.sceneLoaded += OnSceneLoaded; Harmony val = new Harmony("Miles.ShotgunPlus"); val.PatchAll(typeof(PelletPatches)); val.PatchAll(typeof(ReloadPatches)); val.PatchAll(typeof(ToolPatches)); val.PatchAll(typeof(ItemSyncPatch)); val.PatchAll(typeof(Barrels)); val.PatchAll(typeof(Net)); val.PatchAll(typeof(EnemyFixes)); ToolPatches.PatchAdvancedCompany(val); Log.LogInfo((object)"ShotgunPlus 1.0.2 loaded."); } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (((Scene)(ref scene)).name != "MainMenu") { return; } if (!registered) { registered = true; Item[] source = Resources.FindObjectsOfTypeAll<Item>(); Compat.TakeOverShotgun(); ItemSync.Register(((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => ((Object)i).name == "Shotgun")), ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => ((Object)i).name == "GunAmmo"))); } ItemSync.EnsureNetworkPrefabs(); } private static void OnModeKey(CallbackContext ctx) { if (!((CallbackContext)(ref ctx)).performed || (Object)(object)GameNetworkManager.Instance == (Object)null) { return; } PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; if (!((Object)(object)localPlayerController == (Object)null) && ((NetworkBehaviour)localPlayerController).IsOwner && !localPlayerController.isPlayerDead && !localPlayerController.inTerminalMenu && !localPlayerController.isTypingChat && !localPlayerController.quickMenuManager.isMenuOpen) { GrabbableObject currentlyHeldObjectServer = localPlayerController.currentlyHeldObjectServer; ShotgunItem val = (ShotgunItem)(object)((currentlyHeldObjectServer is ShotgunItem) ? currentlyHeldObjectServer : null); if (val != null) { ShotModes.Next(val); } } } private static void OnReloadKey(CallbackContext ctx) { if (!((CallbackContext)(ref ctx)).performed || (Object)(object)GameNetworkManager.Instance == (Object)null) { return; } PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; if (!((Object)(object)localPlayerController == (Object)null) && ((NetworkBehaviour)localPlayerController).IsOwner && !localPlayerController.isPlayerDead && !localPlayerController.inTerminalMenu && !localPlayerController.isTypingChat && !localPlayerController.quickMenuManager.isMenuOpen) { GrabbableObject currentlyHeldObjectServer = localPlayerController.currentlyHeldObjectServer; ShotgunItem val = (ShotgunItem)(object)((currentlyHeldObjectServer is ShotgunItem) ? currentlyHeldObjectServer : null); if (val != null && !val.isReloading) { ReloadPatches.Reload(val); } } } } internal static class ReloadPatches { private static bool fromKey; private static readonly FieldRef<ShotgunItem, int> ammoSlotToUse = AccessTools.FieldRefAccess<ShotgunItem, int>("ammoSlotToUse"); private const float SkipOpen = 0.55f; private const float Blend = 0.2f; private const float ShellPartStart = 1.45f; private const float ClosePartStart = 2f; internal static void Reload(ShotgunItem gun) { fromKey = true; try { ((GrabbableObject)gun).ItemInteractLeftRight(true); } finally { fromKey = false; } } [HarmonyPatch(typeof(ShotgunItem), "ItemInteractLeftRight")] [HarmonyPrefix] private static bool BlockE(bool right) { if (right) { return fromKey; } return true; } [HarmonyPatch(typeof(ShotgunItem), "reloadGunAnimation")] [HarmonyPrefix] private static bool ReloadAnimation(ShotgunItem __instance, ref IEnumerator __result) { __result = LoadShells(__instance); return false; } private static void PlayPart(ShotgunItem g, float from, float to) { AudioClip gunReloadSFX = g.gunReloadSFX; if (!((Object)(object)gunReloadSFX == (Object)null)) { g.gunAudio.clip = gunReloadSFX; g.gunAudio.time = Mathf.Clamp(from, 0f, gunReloadSFX.length - 0.05f); g.gunAudio.Play(); if (to > from) { g.gunAudio.SetScheduledEndTime(AudioSettings.dspTime + (double)(to - from)); } } } private static bool Fits(ShotgunItem g, GrabbableObject item, byte want) { GunAmmo val = (GunAmmo)(object)((item is GunAmmo) ? item : null); if (val != null && val.ammoType == g.gunCompatibleAmmoID) { return ShellRegistry.Of((GrabbableObject)(object)val).Id == want; } return false; } private static int ShellsInPockets(ShotgunItem g, byte want) { int num = 0; GrabbableObject[] itemSlots = ((GrabbableObject)g).playerHeldBy.ItemSlots; foreach (GrabbableObject item in itemSlots) { if (Fits(g, item, want)) { num++; } } return num; } private static bool FindShell(ShotgunItem g, byte want) { GrabbableObject[] itemSlots = ((GrabbableObject)g).playerHeldBy.ItemSlots; for (int i = 0; i < itemSlots.Length; i++) { if (Fits(g, itemSlots[i], want)) { ammoSlotToUse.Invoke(g) = i; return true; } } return false; } private static byte ShellInSlot(ShotgunItem g) { int num = ammoSlotToUse.Invoke(g); GrabbableObject[] itemSlots = ((GrabbableObject)g).playerHeldBy.ItemSlots; if (num < 0 || num >= itemSlots.Length || !((Object)(object)itemSlots[num] != (Object)null)) { return 0; } return ShellRegistry.Of(itemSlots[num]).Id; } private static IEnumerator LoadShells(ShotgunItem g) { Animator body = ((GrabbableObject)g).playerHeldBy.playerBodyAnimator; bool startedEmpty = g.shellsLoaded <= 0; g.isReloading = true; if (g.shellsLoaded <= 0) { body.SetBool("ReloadShotgun", true); ((Renderer)g.shotgunShellLeft).enabled = false; ((Renderer)g.shotgunShellRight).enabled = false; } else { body.SetBool("ReloadShotgun2", true); ((Renderer)g.shotgunShellRight).enabled = false; } byte shell = ShellInSlot(g); Barrels.InHand(g, shell); bool twoShells = startedEmpty && ShellsInPockets(g, shell) >= 2; yield return (object)new WaitForSeconds(0.3f); if (twoShells) { PlayPart(g, 0f, 2f); } else { g.gunAudio.PlayOneShot(g.gunReloadSFX); } g.gunAnimator.SetBool("Reloading", true); g.ReloadGunEffectsServerRpc(true); int loaded = 0; float num = 0.95f; bool second = false; while (true) { yield return (object)new WaitForSeconds(num); ((Renderer)g.shotgunShellInHand).enabled = true; g.shotgunShellInHandTransform.SetParent(((GrabbableObject)g).playerHeldBy.leftHandItemTarget); g.shotgunShellInHandTransform.localPosition = new Vector3(-0.0555f, 0.1469f, -0.0655f); g.shotgunShellInHandTransform.localEulerAngles = new Vector3(-1.956f, 143.856f, -16.427f); if (second) { float lead = 0.39999998f; yield return (object)new WaitForSeconds(0.95f - lead); PlayPart(g, 1.45f, 0f); yield return (object)new WaitForSeconds(lead); } else { yield return (object)new WaitForSeconds(0.95f); } ((GrabbableObject)g).playerHeldBy.DestroyItemInSlotAndSync(ammoSlotToUse.Invoke(g)); ammoSlotToUse.Invoke(g) = -1; g.shellsLoaded = Mathf.Clamp(g.shellsLoaded + 1, 0, 2); Barrels.Set(g, g.shellsLoaded - 1, shell); Barrels.Share(g); loaded++; ((Renderer)g.shotgunShellLeft).enabled = true; if (g.shellsLoaded >= 2) { ((Renderer)g.shotgunShellRight).enabled = true; } ((Renderer)g.shotgunShellInHand).enabled = false; g.shotgunShellInHandTransform.SetParent(((Component)g).transform); Refresh(g); if (g.shellsLoaded >= 2 || !FindShell(g, shell)) { break; } int layerIndex = body.GetLayerIndex("HoldingItemsBothHands"); if (layerIndex >= 0) { body.CrossFadeInFixedTime(startedEmpty ? "ShotgunReloadOneShell" : "ShotgunReloadSecondShell", 0.2f, layerIndex, 0.55f); } else { Plugin.Log.LogWarning((object)"Reload: arms layer not found, the second shell plays without its animation."); } num = 0.7f; second = true; } yield return (object)new WaitForSeconds(0.45f); g.gunAudio.PlayOneShot(g.gunReloadFinishSFX); g.gunAnimator.SetBool("Reloading", false); body.SetBool("ReloadShotgun", false); body.SetBool("ReloadShotgun2", false); g.isReloading = false; for (int i = 0; i < loaded; i++) { g.ReloadGunEffectsServerRpc(false); } } internal static string ReloadTip(ShotgunItem gun) { string text = KeyName(); if (!Plugin.Cfg.ShowAmmo.Value) { return "Reload: [" + text + "]"; } if (!ShellRegistry.AnyExtraEnabled) { return $"Reload ({gun.shellsLoaded}/2): [{text}]"; } string text2; if (gun.shellsLoaded <= 0) { text2 = "Empty"; } else { byte b = Barrels.Get(gun, 0); byte b2 = Barrels.Get(gun, 1); text2 = ((gun.shellsLoaded == 1) ? Tag(b) : ((b != b2) ? (Tag(b) + ", " + Tag(b2)) : ("2 " + Tag(b)))); } return "Reload (" + text2 + "): [" + text + "]"; } private static string Tag(byte id) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) ShellDef shellDef = ShellRegistry.Get(id); if (shellDef != null) { return "<color=#" + ColorUtility.ToHtmlStringRGB(Color32.op_Implicit(shellDef.HudColor)) + ">" + shellDef.ShortName + "</color>"; } return "Buck"; } private static string KeyName() { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) try { InputAction reloadKey = Plugin.Keys.ReloadKey; for (int i = 0; i < reloadKey.bindings.Count; i++) { InputBinding val = reloadKey.bindings[i]; if (((InputBinding)(ref val)).isComposite) { continue; } val = reloadKey.bindings[i]; if (!string.IsNullOrEmpty(((InputBinding)(ref val)).effectivePath)) { string bindingDisplayString = InputActionRebindingExtensions.GetBindingDisplayString(reloadKey, i, (DisplayStringOptions)0); if (!string.IsNullOrWhiteSpace(bindingDisplayString)) { return bindingDisplayString.Trim(); } } } } catch { } return "R"; } [HarmonyPatch(typeof(ShotgunItem), "SetControlTipsForItem")] [HarmonyPrefix] private static void Tips(ShotgunItem __instance) { string[] array = (((Object)(object)((GrabbableObject)__instance).itemProperties != (Object)null) ? ((GrabbableObject)__instance).itemProperties.toolTips : null); if (array != null && array.Length > 1) { array[1] = ReloadTip(__instance); } if (array != null && array.Length != 0) { array[0] = ShotModes.FireTip(); } } [HarmonyPatch(typeof(ShotgunItem), "SetSafetyControlTip")] [HarmonyPostfix] private static void SafetyTip(ShotgunItem __instance) { Refresh(__instance); } [HarmonyPatch(typeof(ShotgunItem), "ReloadGunEffectsClientRpc")] [HarmonyPostfix] private static void Reloaded(ShotgunItem __instance) { Refresh(__instance); } internal static void Refresh(ShotgunItem gun) { if (!((Object)(object)gun == (Object)null) && ((NetworkBehaviour)gun).IsOwner && !((Object)(object)((GrabbableObject)gun).playerHeldBy == (Object)null) && !((Object)(object)HUDManager.Instance == (Object)null) && !((Object)(object)((GrabbableObject)gun).playerHeldBy.currentlyHeldObjectServer != (Object)(object)gun)) { HUDManager.Instance.ChangeControlTip(1, ShotModes.FireTip(), false); HUDManager.Instance.ChangeControlTip(2, ReloadTip(gun), false); } } } public class ShellDef { public string ShortName = "Buck"; public Color32 HudColor = new Color32((byte)230, (byte)70, (byte)60, byte.MaxValue); public Item Item; public Material Material; public Func<bool> Enabled = () => true; public Func<int> Pellets = () => 10; public float Spread = 10f; public bool Choke = true; public Func<int, int> EnemyDamage = (int hits) => hits / 2 + 1; public Func<int> PlayerDamagePerPellet = () => 20; public Color? TracerColor; public Action<ShotgunItem, EnemyAI, IHittable> OnEnemyHit; public Action<ShotgunItem, EnemyAI> OnEnemyHitSeen; public byte Id { get; internal set; } } public static class ShellRegistry { public const int Max = 8; private static readonly List<ShellDef> defs = new List<ShellDef>(); private static readonly Dictionary<Item, ShellDef> byItem = new Dictionary<Item, ShellDef>(); private static readonly Dictionary<string, ShellDef> byName = new Dictionary<string, ShellDef>(); public static Item BuckShell { get; private set; } public static Material VanillaShellMaterial { get; private set; } public static IReadOnlyList<ShellDef> All => defs; public static ShellDef Buck { get { if (defs.Count <= 0) { return null; } return defs[0]; } } public static bool EffectsOn { get { if (Plugin.Cfg != null) { return Plugin.Cfg.Look.Value != PelletLook.Off; } return true; } } internal static bool AnyExtraEnabled { get { for (int i = 1; i < defs.Count; i++) { if (Safe(defs[i].Enabled)) { return true; } } return false; } } public static event Action<Item> Registering; public static ShellDef Register(ShellDef def) { if (def == null) { throw new ArgumentNullException("def"); } if (defs.Count >= 8) { Plugin.Log.LogError((object)$"Shell '{def.ShortName}' not added: {8} shells max."); return null; } def.Id = (byte)defs.Count; defs.Add(def); if ((Object)(object)def.Item != (Object)null) { Map(def.Item, def); } return def; } public static void Map(Item item, ShellDef def) { if (!((Object)(object)item == (Object)null) && def != null) { byItem[item] = def; if (!string.IsNullOrEmpty(item.itemName)) { byName[item.itemName] = def; } } } public static ShellDef Get(int id) { if (id < 0 || id >= defs.Count) { return Buck; } return defs[id]; } public static ShellDef Of(GrabbableObject shell) { if ((Object)(object)shell == (Object)null || (Object)(object)shell.itemProperties == (Object)null) { return Buck; } if (byItem.TryGetValue(shell.itemProperties, out var value)) { return value; } if (!byName.TryGetValue(shell.itemProperties.itemName ?? "", out value)) { return Buck; } return value; } internal static bool Safe(Func<bool> f) { try { return f?.Invoke() ?? true; } catch { return false; } } public static void LoadGun(ShotgunItem gun, ShellDef first, ShellDef second) { if (!((Object)(object)gun == (Object)null)) { Barrels.Set(gun, 0, first?.Id ?? 0); Barrels.Set(gun, 1, second?.Id ?? 0); Barrels.Share(gun); } } public static void HitFromExplosionEverywhere(EnemyAI enemy) { if ((Object)(object)enemy != (Object)null && (Object)(object)((NetworkBehaviour)enemy).NetworkObject != (Object)null) { Net.Send(Net.Kind.Explosion, ((NetworkBehaviour)enemy).NetworkObjectId, 0, 0); } } public static void SetStorePrice(Item item, int price) { ItemSync.ApplyPrice(item, price); } internal static void Setup(Item buckShell) { BuckShell = buckShell; MeshRenderer val = (((Object)(object)buckShell != (Object)null && (Object)(object)buckShell.spawnPrefab != (Object)null) ? buckShell.spawnPrefab.GetComponentInChildren<MeshRenderer>() : null); VanillaShellMaterial = (((Object)(object)val != (Object)null) ? ((Renderer)val).sharedMaterial : null); if (defs.Count == 0) { Register(new ShellDef { Item = buckShell, Material = VanillaShellMaterial }); } else { Map(buckShell, defs[0]); } try { ShellRegistry.Registering?.Invoke(buckShell); } catch (Exception ex) { Plugin.Log.LogError((object)("A shell mod failed to register: " + ex)); } if (defs.Count > 1) { Plugin.Log.LogInfo((object)($"{defs.Count} shell types: " + string.Join(", ", defs.ConvertAll((ShellDef d) => d.ShortName)))); } } internal static Material Mat(byte id) { ShellDef shellDef = Get(id); if (shellDef == null || !((Object)(object)shellDef.Material != (Object)null)) { return VanillaShellMaterial; } return shellDef.Material; } } public enum PelletLook { TracersAndSparks, SparksOnly, Off } public class ShotgunConfig : SyncedConfig2<ShotgunConfig> { [field: SyncedEntryField] public SyncedEntry<int> ShotgunPrice { get; private set; } [field: SyncedEntryField] public SyncedEntry<int> ShotgunRarity { get; private set; } [field: SyncedEntryField] public SyncedEntry<int> ShellPrice { get; private set; } [field: SyncedEntryField] public SyncedEntry<int> ShellRarity { get; private set; } [field: SyncedEntryField] public SyncedEntry<bool> AllowChoke { get; private set; } [field: SyncedEntryField] public SyncedEntry<float> ChokeDistance { get; private set; } [field: SyncedEntryField] public SyncedEntry<bool> AllowDouble { get; private set; } [field: SyncedEntryField] public SyncedEntry<bool> FixManeater { get; private set; } [field: SyncedEntryField] public SyncedEntry<bool> FixCadaverBloom { get; private set; } public ConfigEntry<PelletLook> Look { get; private set; } public ConfigEntry<bool> ShowAmmo { get; private set; } public ShotgunConfig(ConfigFile cfg) : base("Miles.ShotgunPlus") { ShotgunPrice = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Store", "ShotgunPrice", 800, "Price of a shotgun in the store (-1 = not sold). A bought shotgun is a tool: it's kept like a flashlight if everyone dies."); ShellPrice = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Store", "ShellPrice", 50, "Price of one Buck Shell (the vanilla shell) in the store (-1 = not sold). Bought shells are tools too."); ShellRarity = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Scrap", "ShellRarity", 10, "How often Buck Shells show up as scrap on every moon (higher = more common, 0 = never). The most common shell."); ShotgunRarity = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Scrap", "ShotgunRarity", 0, "How often shotguns show up as scrap on every moon (higher = more common, 0 = never). Off by default."); AllowChoke = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Fire Modes", "Choke", true, "Choke mode: one pellet that flies straight, then bursts into the shell's normal spread at the distance below. For far targets."); ChokeDistance = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "Fire Modes", "ChokeDistance", 8f, "How far the Choke shot flies before it bursts, in meters (0.5 to 25)."); AllowDouble = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Fire Modes", "Double", false, "Double mode: fires both barrels at once (each barrel fires its own shell). Needs 2 shells loaded."); FixManeater = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Enemy Damage", "Maneater", true, "The grown Maneater only ever loses 1 HP per hit in vanilla. On: a shotgun hit does its full damage to it (the baby still can't be hurt)."); FixCadaverBloom = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Enemy Damage", "CadaverBloom", true, "The Cadaver Bloom only ever loses 1 HP per hit in vanilla. On: a shotgun hit does its full damage to it."); Look = cfg.Bind<PelletLook>("Visuals", "PelletLook", PelletLook.TracersAndSparks, "What each pellet looks like. TracersAndSparks = quick streaks plus a puff where it lands, SparksOnly = just the puffs, Off = vanilla (nothing)."); ShowAmmo = cfg.Bind<bool>("Visuals", "ShowAmmo", true, "Show the shells loaded next to the reload hint in the top right (the count, or the shell names when a shell mod adds more shells)."); ConfigManager.Register<ShotgunConfig>((SyncedConfig2<ShotgunConfig>)this); } } public enum ShotMode { Spread = 1, Choke, Double } internal static class ShotModes { internal static ShotMode Chosen = ShotMode.Spread; internal static bool Allowed(ShotMode m) { if (m != ShotMode.Spread && (m != ShotMode.Choke || !Plugin.Cfg.AllowChoke.Value)) { if (m == ShotMode.Double) { return Plugin.Cfg.AllowDouble.Value; } return false; } return true; } internal static ShotMode ModeFor(ShotgunItem gun) { ShotMode shotMode = ((!Allowed(Chosen)) ? ShotMode.Spread : Chosen); if (shotMode == ShotMode.Double && gun.shellsLoaded < 2) { shotMode = ShotMode.Spread; } return shotMode; } internal static void Next(ShotgunItem gun) { ShotMode shotMode = Chosen; for (int i = 0; i < 3; i++) { shotMode = ((shotMode == ShotMode.Double) ? ShotMode.Spread : (shotMode + 1)); if (Allowed(shotMode)) { break; } } if (shotMode != Chosen) { Chosen = shotMode; if ((Object)(object)gun.gunAudio != (Object)null && (Object)(object)gun.switchSafetyOffSFX != (Object)null) { gun.gunAudio.PlayOneShot(gun.switchSafetyOffSFX); } ReloadPatches.Refresh(gun); } } internal static string Name(ShotMode m) { return m.ToString(); } internal static string Key() { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) try { InputAction modeKey = Plugin.Keys.ModeKey; for (int i = 0; i < modeKey.bindings.Count; i++) { InputBinding val = modeKey.bindings[i]; if (((InputBinding)(ref val)).isComposite) { continue; } val = modeKey.bindings[i]; if (!string.IsNullOrEmpty(((InputBinding)(ref val)).effectivePath)) { string bindingDisplayString = InputActionRebindingExtensions.GetBindingDisplayString(modeKey, i, (DisplayStringOptions)0); if (!string.IsNullOrWhiteSpace(bindingDisplayString)) { return bindingDisplayString.Trim(); } } } } catch { } return "T"; } internal static string FireTip() { bool num = Allowed(ShotMode.Choke) || Allowed(ShotMode.Double); ShotMode m = ((!Allowed(Chosen)) ? ShotMode.Spread : Chosen); if (!num) { return "Fire : [LMB]"; } return "Fire (" + Name(m) + ") [" + Key() + "] : [LMB]"; } } internal static class ToolPatches { private static readonly Dictionary<ScanNodeProperties, int> scrapNodeType = new Dictionary<ScanNodeProperties, int>(); private static readonly FieldInfo itemProperties = AccessTools.Field(typeof(GrabbableObject), "itemProperties"); private static readonly FieldInfo isScrap = AccessTools.Field(typeof(Item), "isScrap"); private static readonly MethodInfo ours = AccessTools.Method(typeof(ToolPatches), "LostWithShip", (Type[])null, (Type[])null); private static Func<GrabbableObject, bool> chained; internal static bool IsTool(GrabbableObject g) { if (g is ShotgunItem || g is GunAmmo) { return g.scrapValue <= 0; } return false; } [HarmonyPatch(typeof(GrabbableObject), "Start")] [HarmonyPostfix] private static void Spawned(GrabbableObject __instance) { ScanLook(__instance); } [HarmonyPatch(typeof(GrabbableObject), "SetScrapValue")] [HarmonyPostfix] private static void ValueSet(GrabbableObject __instance) { ScanLook(__instance); } private static void ScanLook(GrabbableObject g) { if (!(g is ShotgunItem) && !(g is GunAmmo)) { return; } ScanNodeProperties componentInChildren = ((Component)g).GetComponentInChildren<ScanNodeProperties>(); if (!((Object)(object)componentInChildren == (Object)null)) { if (!scrapNodeType.ContainsKey(componentInChildren)) { scrapNodeType[componentInChildren] = componentInChildren.nodeType; } if (IsTool(g)) { componentInChildren.nodeType = 0; componentInChildren.subText = ""; } else { componentInChildren.nodeType = scrapNodeType[componentInChildren]; } } } internal static void PatchAdvancedCompany(Harmony harmony) { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown try { if (Chainloader.PluginInfos.TryGetValue("com.potatoepet.AdvancedCompany", out var value) && value.Instance != null) { Type type = ((object)value.Instance).GetType().Assembly.GetType("AdvancedCompany.Patches.RoundManager"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "ProtectLoot", (Type[])null, (Type[])null) : null); if (!(methodInfo == null)) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ToolPatches), "Transpiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); Plugin.Log.LogInfo((object)"AdvancedCompany found: bought shotguns are kept when everyone dies (with its Save Loot perk too)."); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("AdvancedCompany loot check: " + ex.Message)); } } [HarmonyPatch(typeof(RoundManager), "CollectNewScrapForThisRound")] [HarmonyPrefix] private static bool Collect(GrabbableObject scrapObject) { if (!((Object)(object)scrapObject == (Object)null)) { return !IsTool(scrapObject); } return true; } [HarmonyTranspiler] [HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")] internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); int num = 0; for (int i = 0; i < list.Count; i++) { if (i < list.Count - 1 && CodeInstructionExtensions.LoadsField(list[i], itemProperties, false) && CodeInstructionExtensions.LoadsField(list[i + 1], isScrap, false)) { list[i].opcode = OpCodes.Call; list[i].operand = ours; list.RemoveAt(i + 1); num++; } else if ((list[i].opcode == OpCodes.Call || list[i].opcode == OpCodes.Callvirt) && list[i].operand is MethodInfo methodInfo && methodInfo != ours && methodInfo.Name == "LostWithShip" && methodInfo.IsStatic && methodInfo.ReturnType == typeof(bool) && methodInfo.GetParameters().Length == 1 && methodInfo.GetParameters()[0].ParameterType == typeof(GrabbableObject)) { try { chained = (Func<GrabbableObject, bool>)Delegate.CreateDelegate(typeof(Func<GrabbableObject, bool>), methodInfo); } catch { continue; } list[i].opcode = OpCodes.Call; list[i].operand = ours; num++; } } if (num == 0) { Plugin.Log.LogWarning((object)"Could not find the scrap check in DespawnPropsAtEndOfRound: bought shotguns will be lost if everyone dies."); } return list; } public static bool LostWithShip(GrabbableObject g) { if ((Object)(object)g == (Object)null || (Object)(object)g.itemProperties == (Object)null || !g.itemProperties.isScrap) { return false; } if (IsTool(g)) { return false; } if (chained != null) { try { return chained(g); } catch { } } return true; } } }