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 Stormrune Armory v1.0.1
BepInEx/plugins/StormruneArmory/StormruneArmory.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Surik.Assets; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("StormruneArmory")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+eab6c7e89f658012dfcf541fd5b3c00fa1ebd550")] [assembly: AssemblyProduct("StormruneArmory")] [assembly: AssemblyTitle("StormruneArmory")] [assembly: AssemblyVersion("1.0.1.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 Surik.Assets { internal static class ModAssets { internal static AssetBundle OpenBundle(Assembly assembly, string prefix) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_0009: Invalid comparison between Unknown and I4 //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Invalid comparison between Unknown and I4 //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_0030: 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) RuntimePlatform platform = Application.platform; if ((int)platform <= 13) { if ((int)platform == 2) { goto IL_0020; } if ((int)platform == 13) { goto IL_0028; } } else { if ((int)platform == 43) { goto IL_0028; } if ((int)platform == 44) { goto IL_0020; } } throw new PlatformNotSupportedException(((object)Application.platform/*cast due to .constrained prefix*/).ToString()); IL_0028: string text = "linux"; goto IL_004a; IL_0020: text = "windows"; goto IL_004a; IL_004a: using Stream stream = Resource(assembly, "Bundles." + prefix + "-" + text); using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return AssetBundle.LoadFromMemory(memoryStream.ToArray()) ?? throw new InvalidDataException(prefix + " bundle"); } internal static Sprite Icon(Assembly assembly, string id) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0061: 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) using Stream stream = Resource(assembly, "Icons." + id + ".png"); using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2); if (!AssetUtils.LoadImage(val, memoryStream.ToArray())) { throw new InvalidDataException(id); } ((Texture)val).wrapMode = (TextureWrapMode)1; return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } private static Stream Resource(Assembly assembly, string suffix) { string text = assembly.GetName().Name + "." + suffix; return assembly.GetManifestResourceStream(text) ?? throw new FileNotFoundException(text); } } } namespace StormruneArmory { [BepInPlugin("surik.stormrunearmory", "Stormrune Armory", "1.0.1")] [BepInDependency("com.jotunn.jotunn", "2.30.2")] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class ArmoryPlugin : BaseUnityPlugin { internal static readonly Dictionary<string, Weapon> Weapons = new Dictionary<string, Weapon>(StringComparer.Ordinal); internal static GameObject ProjectilePrefab; private Harmony harmony; private void Awake() { //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Expected O, but got Unknown Add(new Weapon("BirchfirePistol", "Birchfire Pistol", "BirchfireRounds", "Birchfire Rounds", "piece_workbench", 2, 42f, 1, 1f, 0.75f, 6, 2f, 20, Cost("Flint", 2), Cost("Resin", 1)), Cost("Bronze", 4, 2), Cost("FineWood", 6, 2), Cost("DeerHide", 2)); Add(new Weapon("FenbreakerShotgun", "Fenbreaker Shotgun", "FenbreakerShells", "Fenbreaker Shells", "forge", 2, 22f, 6, 5f, 1f, 2, 2.8f, 10, Cost("Iron", 1), Cost("Ooze", 2)), Cost("Iron", 8, 4), Cost("ElderBark", 8, 3), Cost("Ooze", 2)); Add(new Weapon("HailweaverRifle", "Hailweaver Automatic Rifle", "HailweaverRounds", "Hailweaver Rounds", "forge", 3, 23f, 1, 1.6f, 0.25f, 12, 2f, 60, Cost("Iron", 1), Cost("Resin", 3)), Cost("Iron", 12, 6), Cost("Chain", 2, 1), Cost("FineWood", 8, 2)); Add(new Weapon("NorthwatchRifle", "Northwatch Sniper Rifle", "NorthwatchRounds", "Northwatch Rounds", "blackforge", 4, 284f, 1, 0.15f, 1f, 3, 2f, 5, Cost("Gold", 1), Cost("FreezeGland", 1)), Cost("Gold", 20, 10), Cost("Frostwood", 8, 3), Cost("OrbFrostFire", 1, 1)); PrefabManager.OnVanillaPrefabsAvailable += Register; harmony = new Harmony("surik.stormrunearmory"); harmony.PatchAll(typeof(ArmoryPlugin)); } private void Add(Weapon weapon, params RequirementConfig[] materials) { weapon.Materials = materials; weapon.Bind(((BaseUnityPlugin)this).Config); Weapons.Add(weapon.Id, weapon); } private static RequirementConfig Cost(string item, int count, int upgrade = 0) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected O, but got Unknown return new RequirementConfig(item, count, upgrade, true); } private void Register() { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown PrefabManager.OnVanillaPrefabsAvailable -= Register; AssetBundle val = ModAssets.OpenBundle(Assembly.GetExecutingAssembly(), "arms"); try { GameObject attackProjectile = PrefabManager.Instance.GetPrefab("ArrowWood").GetComponent<ItemDrop>().m_itemData.m_shared.m_attack.m_attackProjectile; CustomPrefab val2 = new CustomPrefab(PrefabManager.Instance.CreateClonedPrefab("Surik_StormruneBolt", attackProjectile), false); Projectile component = val2.Prefab.GetComponent<Projectile>(); component.m_gravity = 1.2f; component.m_ttl = 3.5f; component.m_spawnItem = null; PrefabManager.Instance.AddPrefab(val2); ProjectilePrefab = val2.Prefab; foreach (Weapon value in Weapons.Values) { value.Register(val); } } finally { val.Unload(false); } } [HarmonyPatch(typeof(Player), "PlayerAttackInput")] [HarmonyPrefix] private static bool UpdateFiring(Player __instance, bool ___m_attack, bool ___m_attackHold) { ItemData currentWeapon = ((Humanoid)__instance).GetCurrentWeapon(); Magazine magazine = ((Component)__instance).GetComponent<Magazine>(); if ((Object)(object)currentWeapon?.m_dropPrefab == (Object)null || !Weapons.TryGetValue(((Object)currentWeapon.m_dropPrefab).name, out var value)) { if (Object.op_Implicit((Object)(object)magazine)) { magazine.Holster(); } return true; } if (!Object.op_Implicit((Object)(object)magazine)) { magazine = ((Component)__instance).gameObject.AddComponent<Magazine>(); } magazine.UpdateFire(__instance, currentWeapon, value, ___m_attack, ___m_attackHold); return false; } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= Register; Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } Weapons.Clear(); } } public sealed class HeldGun : MonoBehaviour { [SerializeField] private string itemId; [SerializeField] private Transform gripPivot; [SerializeField] private Transform muzzle; [SerializeField] private Transform secondMuzzle; private Player wielder; private ZNetView view; private EquippedGunAnimation animationLease; private Vector3 shotTarget; private Vector3 shotSightDirection; private float holdAimUntil; private static readonly int SightLayers = LayerMask.GetMask(new string[12] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle" }); internal string ItemId => itemId; internal Quaternion BarrelRotation => gripPivot.rotation; internal Transform Muzzle(int pellet) { if (!Object.op_Implicit((Object)(object)secondMuzzle) || (pellet & 1) != 1) { return muzzle; } return secondMuzzle; } internal static void Mount(Transform socket, Transform model, string id) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_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_0075: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: 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) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) Transform[] parts = ((Component)model).GetComponentsInChildren<Transform>(true); Transform val = Marker("Grip"); Transform val2 = Marker("BoreRear"); Transform val3 = Marker("Muzzle"); Vector3 val4 = model.InverseTransformPoint(val3.position) - model.InverseTransformPoint(val2.position); Vector3 val5 = model.InverseTransformPoint(Marker("SightUp").position) - model.InverseTransformPoint(val2.position); Transform transform = new GameObject("Stormrune grip").transform; transform.SetParent(socket, false); model.SetParent(transform, false); model.localRotation = Quaternion.Inverse(Quaternion.LookRotation(val4, val5)); model.localPosition -= transform.InverseTransformPoint(val.position); HeldGun heldGun = ((Component)socket).gameObject.AddComponent<HeldGun>(); heldGun.itemId = id; heldGun.gripPivot = transform; heldGun.muzzle = val3; heldGun.secondMuzzle = ((IEnumerable<Transform>)parts).SingleOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Muzzle2")); Transform Marker(string name) { return ((IEnumerable<Transform>)parts).SingleOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == name)) ?? throw new InvalidDataException(id + " has no " + name + " marker."); } } private void OnEnable() { BindHand(); } private void OnTransformParentChanged() { BindHand(); } private void OnDisable() { ReleaseHand(); } private void BindHand() { VisEquipment componentInParent = ((Component)this).GetComponentInParent<VisEquipment>(); Player val = ((Object.op_Implicit((Object)(object)componentInParent) && ((Object)(object)((Component)this).transform.parent == (Object)(object)componentInParent.m_leftHand || (Object)(object)((Component)this).transform.parent == (Object)(object)componentInParent.m_rightHand)) ? ((Component)componentInParent).GetComponent<Player>() : null); if ((Object)(object)wielder == (Object)(object)val || !((Behaviour)this).isActiveAndEnabled) { return; } ReleaseHand(); if (Object.op_Implicit((Object)(object)val)) { wielder = val; view = ((Component)val).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsDedicated()) { animationLease = ((Component)val).GetComponent<EquippedGunAnimation>() ?? ((Component)val).gameObject.AddComponent<EquippedGunAnimation>(); animationLease.Acquire(); } } } private void ReleaseHand() { if (Object.op_Implicit((Object)(object)animationLease)) { animationLease.Release(); } animationLease = null; wielder = null; view = null; } private void LateUpdate() { //IL_0026: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)wielder) || !Object.op_Implicit((Object)(object)gripPivot)) { return; } Vector3 forward = ((Component)wielder).transform.forward; if ((Object)(object)wielder == (Object)(object)Player.m_localPlayer && Time.time < holdAimUntil) { PointAt(shotTarget, shotSightDirection); return; } Vector3 val = ((Object.op_Implicit((Object)(object)view) && view.IsValid()) ? view.GetZDO().GetVec3(ZDOVars.s_lookTarget, Vector3.zero) : Vector3.zero); Vector3 val2; if (!((Object)(object)wielder == (Object)(object)Player.m_localPlayer)) { if (!(val != Vector3.zero)) { val2 = forward; } else { Vector3 val3 = val - ((Character)wielder).GetEyePoint(); val2 = ((Vector3)(ref val3)).normalized; } } else { val2 = ((Character)wielder).GetLookDir(); } Vector3 val4 = val2; if (Vector3.Dot(val4, forward) <= 0f) { val4 = forward; } gripPivot.rotation = Quaternion.LookRotation(val4, ((Component)wielder).transform.up); } internal void AimForShot(Vector3 target, Vector3 sightDirection) { //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) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: 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_0021: Unknown result type (might be due to invalid IL or missing references) shotTarget = target; shotSightDirection = sightDirection; holdAimUntil = Time.time + 0.35f; PointAt(target, sightDirection); } private void PointAt(Vector3 target, Vector3 sightDirection) { //IL_000b: 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_0017: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) Vector3 up = ((Component)wielder).transform.up; gripPivot.rotation = Quaternion.LookRotation(sightDirection, up); Vector3 val = Vector3.ProjectOnPlane((Object.op_Implicit((Object)(object)secondMuzzle) ? ((muzzle.position + secondMuzzle.position) * 0.5f) : muzzle.position) - gripPivot.position, sightDirection); Vector3 val2 = target - (gripPivot.position + val); if (Vector3.Dot(val2, sightDirection) > 0.02f) { gripPivot.rotation = Quaternion.LookRotation(val2, up); } } internal static Vector3 SightTarget(Player player, Vector3 direction) { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_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_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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_005a: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) Vector3 eyePoint = ((Character)player).GetEyePoint(); Vector3 val = eyePoint; GameCamera instance = GameCamera.instance; if (Object.op_Implicit((Object)(object)instance) && Vector3.Dot(((Component)instance).transform.forward, direction) > 0.995f) { Vector3 position = ((Component)instance).transform.position; direction = ((Component)instance).transform.forward; val = position + direction * Vector3.Dot(eyePoint - position, direction); } float num = 260f; Vector3 result = val + direction * 260f; RaycastHit[] array = Physics.RaycastAll(val, direction, 260f, SightLayers, (QueryTriggerInteraction)1); for (int i = 0; i < array.Length; i++) { RaycastHit val2 = array[i]; if (!(((RaycastHit)(ref val2)).distance >= num) && !((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(((Component)player).transform)) { num = ((RaycastHit)(ref val2)).distance; result = ((RaycastHit)(ref val2)).point; } } return result; } } internal sealed class EquippedGunAnimation : MonoBehaviour { private Animator rig; private AnimatorCullingMode originalMode; private int equipped; internal void Acquire() { //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) if (equipped++ == 0) { rig = ((Component)this).GetComponentInChildren<Animator>(); if (Object.op_Implicit((Object)(object)rig)) { originalMode = rig.cullingMode; rig.cullingMode = (AnimatorCullingMode)0; } } } internal void Release() { //IL_0026: 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) if (--equipped == 0 && Object.op_Implicit((Object)(object)rig) && (int)rig.cullingMode == 0) { rig.cullingMode = originalMode; } } } internal sealed class Magazine : MonoBehaviour { private const string UsedKey = "Surik.Stormrune.ShotsUsed"; private ItemData equipped; private HeldGun equippedModel; private double readyAt; private double reloadAt; private bool reloading; private bool triggerDown; internal void Holster() { equipped = null; equippedModel = null; reloading = false; triggerDown = false; } internal void UpdateFire(Player player, ItemData item, Weapon gun, bool pressed, bool held) { if (equipped != item) { Holster(); equipped = item; } if (!Object.op_Implicit((Object)(object)equippedModel)) { HeldGun[] componentsInChildren = ((Component)((Humanoid)player).GetVisEquipment().m_leftHand).GetComponentsInChildren<HeldGun>(); foreach (HeldGun heldGun in componentsInChildren) { if (heldGun.ItemId == gun.Id) { equippedModel = heldGun; break; } } if (!Object.op_Implicit((Object)(object)equippedModel)) { return; } } bool flag = (gun.Automatic ? (pressed || held) : ((pressed || held) && !triggerDown)); triggerDown = pressed || held; if (((Character)player).InPlaceMode() || ((Character)player).IsAttached() || ((Character)player).IsSwimming() || ((Character)player).InDodge() || ((Character)player).IsStaggering() || ((Character)player).IsKnockedBack() || ((Character)player).IsBlocking() || ((Character)player).InMinorAction() || !((Character)player).CanMove() || item.m_durability <= 0f) { reloading = false; return; } double fixedTimeAsDouble = Time.fixedTimeAsDouble; int result = 0; if (item.m_customData.TryGetValue("Surik.Stormrune.ShotsUsed", out var value)) { int.TryParse(value, out result); } if (result >= gun.Capacity.Value) { if (!reloading) { if (((Humanoid)player).GetInventory().GetItem(gun.AmmoId, -1, true) == null) { return; } reloadAt = Math.Max(readyAt, fixedTimeAsDouble) + (double)gun.Reload.Value; reloading = true; ((Character)player).Message((MessageType)1, "Reloading " + gun.Title, 0, (Sprite)null, false); } if (fixedTimeAsDouble + 0.0001 < reloadAt) { return; } result = 0; item.m_customData.Remove("Surik.Stormrune.ShotsUsed"); reloading = false; } if (!flag || fixedTimeAsDouble + 0.0001 < readyAt) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); ItemData item2 = inventory.GetItem(gun.AmmoId, -1, true); if (item2 == null) { if (pressed) { ((Character)player).Message((MessageType)1, "Needs " + gun.AmmoTitle, 0, (Sprite)null, false); } return; } float num = (gun.Automatic ? 1.2f : 2f); if (((Character)player).HaveStamina(num) && inventory.RemoveItem(item2, 1)) { item.m_customData["Surik.Stormrune.ShotsUsed"] = (result + 1).ToString(CultureInfo.InvariantCulture); readyAt = fixedTimeAsDouble + (double)gun.Interval.Value; item.m_durability = Mathf.Max(0f, item.m_durability - item.m_shared.m_useDurabilityDrain * Game.m_durabilityRate); ((Character)player).UseStamina(num); Shoot(player, item, item2, gun, equippedModel); } } private static void Shoot(Player player, ItemData gunItem, ItemData ammo, Weapon gun, HeldGun held) { //IL_0008: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Expected O, but got Unknown //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) player.FaceLookDirection(); Vector3 val = ((Humanoid)player).GetAimDir(((Character)player).GetEyePoint()); Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 val2 = HeldGun.SightTarget(player, normalized); held.AimForShot(val2, normalized); ((Component)player).GetComponent<ZSyncAnimation>().SetTrigger(gunItem.m_shared.m_attack.m_attackAnimation); Transform val3 = held.Muzzle(0); gunItem.m_shared.m_triggerEffect.Create(val3.position, held.BarrelRotation, (Transform)null, 1f, -1, ((Character)player).GetZDOID()); HitData val4 = new HitData { m_damage = gunItem.GetDamage(), m_dodgeable = true, m_blockable = true, m_ranged = true, m_hitType = (HitType)2, m_skill = (SkillType)8, m_skillLevel = ((Character)player).GetSkillLevel((SkillType)8), m_skillRaiseAmount = Mathf.Min(1f, (gun.Interval.Value + gun.Reload.Value / (float)gun.Capacity.Value) / 1.5f) / (float)gun.Pellets.Value, m_itemLevel = (short)gunItem.m_quality, m_itemWorldLevel = (byte)gunItem.m_worldLevel, m_backstabBonus = 1f, m_pushForce = gunItem.m_shared.m_attackForce / (float)gun.Pellets.Value }; val4.SetAttacker((Character)(object)player); ((DamageTypes)(ref val4.m_damage)).Modify(((Character)player).GetRandomSkillFactor((SkillType)8)); ((Character)player).GetSEMan().ModifyAttack((SkillType)8, ref val4); for (int i = 0; i < gun.Pellets.Value; i++) { Vector3 position = held.Muzzle(i).position; Vector3 val5 = val2 - position; Quaternion val6 = Quaternion.LookRotation((Vector3.Dot(val5, normalized) > 0.02f) ? ((Vector3)(ref val5)).normalized : normalized, ((Component)player).transform.up); Vector2 val7 = Random.insideUnitCircle * Mathf.Tan(gun.Spread.Value * ((float)Math.PI / 180f)); val = new Vector3(val7.x, val7.y, 1f); Vector3 val8 = val6 * ((Vector3)(ref val)).normalized; Object.Instantiate<GameObject>(ArmoryPlugin.ProjectilePrefab, position, Quaternion.LookRotation(val8)).GetComponent<Projectile>().Setup((Character)(object)player, val8 * 75f, 12f, val4, gunItem, ammo); } } } internal sealed class Weapon { internal readonly string Id; internal readonly string Title; internal readonly string AmmoId; internal readonly string AmmoTitle; private readonly string station; private readonly int level; private readonly int defaultPellets; private readonly int defaultCapacity; private readonly int defaultYield; private readonly float defaultDamage; private readonly float defaultSpread; private readonly float defaultRecovery; private readonly float defaultReload; private readonly RequirementConfig[] ammoCosts; internal RequirementConfig[] Materials; internal ConfigEntry<float> Damage; internal ConfigEntry<float> Spread; internal ConfigEntry<float> Interval; internal ConfigEntry<float> Reload; internal ConfigEntry<int> Pellets; internal ConfigEntry<int> Capacity; private ConfigEntry<int> yield; private ConfigEntry<int> firstCost; private ConfigEntry<int> secondCost; private SharedData stats; private Recipe ammoRecipe; internal bool Automatic => Id == "Surik_HailweaverRifle"; internal Weapon(string id, string name, string ammo, string ammoName, string station, int level, float damage, int pellets, float spread, float interval, int capacity, float reload, int amount, params RequirementConfig[] costs) { Id = "Surik_" + id; Title = name; AmmoId = "Surik_" + ammo; AmmoTitle = ammoName; this.station = station; this.level = level; defaultDamage = damage; defaultPellets = pellets; defaultSpread = spread; defaultRecovery = interval; defaultCapacity = capacity; defaultReload = reload; defaultYield = amount; ammoCosts = costs; } internal void Bind(ConfigFile cfg) { Damage = Entry<float>("Damage", defaultDamage, 1f, 2000f, "Quality-one pierce damage per projectile, before skill."); Pellets = Entry<int>("Projectiles", defaultPellets, 1, 16, "Projectiles per ammunition item."); Spread = Entry<float>("SpreadDegrees", defaultSpread, 0f, 30f, "Half-angle of the projectile spread."); Interval = Entry<float>("ShotInterval", defaultRecovery, 0.1f, 8f, "Seconds of recovery per shot."); Capacity = Entry<int>("Magazine", defaultCapacity, 1, 100, "Shots between reloads."); Reload = Entry<float>("Reload", defaultReload, 0.1f, 20f, "Additional seconds to refill after shot recovery."); yield = Entry<int>("AmmoBatch", defaultYield, 1, 100, "Ammunition crafted per batch."); firstCost = Entry<int>("Cost_" + ammoCosts[0].Item, ammoCosts[0].Amount, 1, 100, "First ingredient per ammunition batch."); secondCost = Entry<int>("Cost_" + ammoCosts[1].Item, ammoCosts[1].Amount, 1, 100, "Second ingredient per ammunition batch."); Damage.SettingChanged += delegate { Refresh(); }; yield.SettingChanged += delegate { Refresh(); }; firstCost.SettingChanged += delegate { Refresh(); }; secondCost.SettingChanged += delegate { Refresh(); }; ConfigEntry<T> Entry<T>(string name, T initial, T min, T max, string text) where T : IComparable { //IL_0025: 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_0032: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown return cfg.Bind<T>(Title, name, initial, new ConfigDescription(text, (AcceptableValueBase)(object)new AcceptableValueRange<T>(min, max), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } } internal void Register(AssetBundle bundle) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_0066: 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_0089: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Expected O, but got Unknown //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Expected O, but got Unknown //IL_0223: Unknown result type (might be due to invalid IL or missing references) Assembly executingAssembly = Assembly.GetExecutingAssembly(); CustomItem val = new CustomItem(AmmoId, "ArrowWood", new ItemConfig { Name = AmmoTitle, Description = "Runic ammunition for the " + Title + ".", CraftingStation = station, MinStationLevel = level, Amount = yield.Value, Requirements = ammoCosts, Icon = ModAssets.Icon(executingAssembly, AmmoId) }); SharedData shared = val.ItemDrop.m_itemData.m_shared; shared.m_ammoType = AmmoId; shared.m_damages = default(DamageTypes); shared.m_weight = 0.05f; shared.m_maxStackSize = 100; GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0); try { Object.DestroyImmediate((Object)(object)val2.GetComponent<Collider>()); val2.transform.localScale = new Vector3(0.13f, 0.18f, 0.13f); Material sharedMaterial = ((Renderer)bundle.LoadAsset<GameObject>(Id).GetComponentInChildren<MeshRenderer>(true)).sharedMaterial; ((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = sharedMaterial; ReplaceVisual(val.ItemPrefab, val2); } finally { Object.DestroyImmediate((Object)(object)val2); } if (!ItemManager.Instance.AddItem(val)) { throw new InvalidDataException(AmmoId); } ammoRecipe = val.Recipe.Recipe; string id = Id; ItemConfig val3 = new ItemConfig(); val3.Name = Title; val3.Description = "Uses " + AmmoTitle + ". " + (Automatic ? "Hold Attack to fire." : "Press Attack for each shot.") + " Reloads automatically."; val3.CraftingStation = station; val3.MinStationLevel = level; val3.Requirements = Materials; val3.Icon = ModAssets.Icon(executingAssembly, Id); CustomItem val4 = new CustomItem(id, "CrossbowArbalest", val3); stats = val4.ItemDrop.m_itemData.m_shared; stats.m_skillType = (SkillType)8; stats.m_ammoType = AmmoId; stats.m_attack.m_requiresReload = false; stats.m_attack.m_bowDraw = false; stats.m_maxQuality = 4; stats.m_maxDurability = 160f; stats.m_attackForce = 8f; GameObject val5 = bundle.LoadAsset<GameObject>(Id); if (!Object.op_Implicit((Object)(object)val5)) { throw new InvalidDataException(Id); } ReplaceVisual(val4.ItemPrefab, val5, Id); Refresh(); if (!ItemManager.Instance.AddItem(val4)) { throw new InvalidDataException(Id); } } private static void ReplaceVisual(GameObject prefab, GameObject model, string weaponId = null) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) LODGroup[] componentsInChildren = prefab.GetComponentsInChildren<LODGroup>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } Renderer[] componentsInChildren2 = prefab.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } Transform val = prefab.transform.Find("attach"); if (!Object.op_Implicit((Object)(object)val)) { val = new GameObject("attach").transform; val.SetParent(prefab.transform, false); } foreach (Transform item in ((IEnumerable<Transform>)(object)new Transform[2] { val, prefab.transform.Find("attach_back") }).Where((Transform t) => Object.op_Implicit((Object)(object)t))) { GameObject val2 = Object.Instantiate<GameObject>(model, item, false); ((Object)val2).name = "Surik model"; val2.transform.localPosition = Vector3.zero; val2.transform.localRotation = Quaternion.identity; if (weaponId != null && (Object)(object)item == (Object)(object)val) { HeldGun.Mount(item, val2.transform, weaponId); } } } private void Refresh() { //IL_0010: 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_0036: 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) if (stats != null) { stats.m_damages = new DamageTypes { m_pierce = Damage.Value }; stats.m_damagesPerLevel = new DamageTypes { m_pierce = Damage.Value * 0.05f }; } if (Object.op_Implicit((Object)(object)ammoRecipe)) { ammoRecipe.m_amount = yield.Value; ammoRecipe.m_resources[0].m_amount = firstCost.Value; ammoRecipe.m_resources[1].m_amount = secondCost.Value; } } } }