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 Seatapult v0.1.0
Seatapult.dll
Decompiled 4 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using UnityEngine; [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("Seatapult")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0")] [assembly: AssemblyProduct("Seatapult")] [assembly: AssemblyTitle("Seatapult")] [assembly: AssemblyVersion("0.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Seatapult { public class SeatapultEject : MonoBehaviour { private static FieldInfo f_fallTimer; private static FieldInfo f_maxAirAltitude; private static bool f_lookupTried; private static readonly float MaxFlightSeconds = 40f; private Character m_character; private float m_age; private bool m_wasGrounded; private void Awake() { m_character = ((Component)this).GetComponent<Character>(); m_age = 0f; m_wasGrounded = (Object)(object)m_character != (Object)null && m_character.IsOnGround(); EnsureFieldLookup(); if ((Object)(object)m_character == (Object)null) { Object.Destroy((Object)(object)this); } } private void Update() { if ((Object)(object)m_character == (Object)null || m_character.IsDead()) { Object.Destroy((Object)(object)this); return; } m_age += Time.deltaTime; if (m_age > MaxFlightSeconds) { SeatapultPlugin.Log("eject protection timed out."); Object.Destroy((Object)(object)this); return; } bool flag = m_character.IsOnGround(); if (flag && !m_wasGrounded) { Object.Destroy((Object)(object)this); return; } m_wasGrounded = flag; if (!flag && SeatapultPlugin.EjectNoFallDamage.Value) { PinFallFields(); } } private void PinFallFields() { //IL_0047: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)this).transform; try { if (f_fallTimer != null) { f_fallTimer.SetValue(m_character, 0f); } if (f_maxAirAltitude != null) { f_maxAirAltitude.SetValue(m_character, transform.position.y); } } catch (Exception) { Object.Destroy((Object)(object)this); } } private static void EnsureFieldLookup() { if (!f_lookupTried) { f_lookupTried = true; Type? typeFromHandle = typeof(Character); f_fallTimer = typeFromHandle.GetField("m_fallTimer", BindingFlags.Instance | BindingFlags.NonPublic); f_maxAirAltitude = typeFromHandle.GetField("m_maxAirAltitude", BindingFlags.Instance | BindingFlags.NonPublic); SeatapultPlugin.Log("fall fields: m_fallTimer=" + ((f_fallTimer != null) ? "found" : "MISSING") + " m_maxAirAltitude=" + ((f_maxAirAltitude != null) ? "found" : "MISSING")); } } } public static class SeatapultHud { private static readonly GUIStyle HeaderStyle; private static readonly GUIStyle LineStyle; private static readonly GUIStyle DimStyle; public static void Render() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_0229: 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_025e: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) SeatapultOperator seatedOperator = SeatapultOperator.GetSeatedOperator(Player.m_localPlayer); if (!((Object)(object)seatedOperator == (Object)null)) { SeatapultOperator.HudData hudData = seatedOperator.GetHudData(); float num = 360f; float num2 = 260f; float num3 = 24f; float num4 = (float)Screen.height * 0.28f; Rect val = new Rect(num3, num4, num, num2); GUI.color = new Color(0f, 0f, 0f, 0.6f); GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; float num5 = num4 + 12f; GUI.Label(new Rect(num3 + 14f, num5, num - 28f, 26f), "SEATAPULT", HeaderStyle); num5 += 34f; GUI.Label(new Rect(num3 + 14f, num5, num - 28f, 22f), $"Angle {hudData.Angle,3:0}°", LineStyle); num5 += 26f; GUI.Label(new Rect(num3 + 14f, num5, num - 28f, 22f), $"Aim {hudData.Aim,3:0}°", LineStyle); num5 += 26f; GUI.Label(new Rect(num3 + 14f, num5, num - 28f, 22f), $"Power {hudData.Power * 100f,3:0}%", LineStyle); num5 += 26f; string text = ((hudData.AmmoCount > 0) ? $"Ammo {hudData.AmmoCount} x {LocalizeName(hudData.AmmoName)}" : "Ammo none"); GUI.Label(new Rect(num3 + 14f, num5, num - 28f, 22f), text, (hudData.AmmoCount > 0) ? LineStyle : DimStyle); num5 += 26f; string text2 = (hudData.Deployed ? "Legs DEPLOYED" : "Legs retracted"); Rect val2 = new Rect(num3 + 14f, num5, num - 28f, 22f); object obj; if (!hudData.Deployed) { obj = DimStyle; } else { GUIStyle val3 = new GUIStyle(LineStyle); val3.normal.textColor = new Color(0.5f, 1f, 0.5f); obj = (object)val3; } GUI.Label(val2, text2, (GUIStyle)obj); num5 += 26f; if (hudData.Cooldown > 0f) { GUI.Label(new Rect(num3 + 14f, num5, num - 28f, 22f), $"Reloading {hudData.Cooldown:0.0}s", DimStyle); num5 += 24f; } num5 += 2f; GUI.Label(new Rect(num3 + 14f, num5, num - 28f, 40f), "Shift+F = fire V = deploy T = eject\nShift+Up/Down = power Arrows/WASD = angle & aim E = stand", DimStyle); } } private static string LocalizeName(string sharedName) { if (string.IsNullOrEmpty(sharedName)) { return "?"; } return sharedName.Split('/')[^1]; } static SeatapultHud() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0059: 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_006e: Expected O, but got Unknown //IL_0078: 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_0085: 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_00ae: Expected O, but got Unknown GUIStyle val = new GUIStyle(GUI.skin.label) { fontSize = 18, fontStyle = (FontStyle)1 }; val.normal.textColor = new Color(1f, 0.85f, 0.3f); HeaderStyle = val; GUIStyle val2 = new GUIStyle(GUI.skin.label) { fontSize = 15 }; val2.normal.textColor = Color.white; LineStyle = val2; GUIStyle val3 = new GUIStyle(GUI.skin.label) { fontSize = 12 }; val3.normal.textColor = new Color(1f, 1f, 1f, 0.65f); DimStyle = val3; } } public class SeatapultOperator : MonoBehaviour { public struct HudData { public float Angle; public float Aim; public float Power; public int AmmoCount; public string AmmoName; public float Cooldown; public bool Deployed; } public Catapult Source; public Transform Lift; public Transform PitchPivot; public static readonly HashSet<SeatapultOperator> ActiveOperators = new HashSet<SeatapultOperator>(); private const string KeyAngle = "seatapult_angle"; private const string KeyYaw = "seatapult_yaw"; private const string KeyPower = "seatapult_power"; private const string KeyDeploy = "seatapult_deploy"; private ZNetView m_nview; private Container m_store; private Transform m_arm; private Transform m_shoot; private Quaternion m_armBaseRot = Quaternion.identity; private Quaternion m_pivotBaseRot = Quaternion.identity; private float m_angle; private float m_yaw; private float m_power = 0.5f; private bool m_deployed; private float m_recoil; private float m_fireTimer; private float m_hintTimer; private float m_noOwnershipWarnTimer; private bool m_init; private readonly List<Transform> m_legs = new List<Transform>(); private readonly List<Vector3> m_legBase = new List<Vector3>(); private static readonly string[] HazardHints = new string[10] { "damage", "spike", "hit", "attack", "projectile", "switch", "bucket", "claw", "collision", "letter" }; private void OnEnable() { ActiveOperators.Add(this); m_init = false; } private void OnDisable() { ActiveOperators.Remove(this); } public static SeatapultOperator GetSeatedOperator(Player player) { if ((Object)(object)player == (Object)null || ((Character)player).IsDead() || !((Character)player).IsAttached() || (Object)(object)player.GetAttachPoint() == (Object)null) { return null; } foreach (SeatapultOperator activeOperator in ActiveOperators) { if ((Object)(object)activeOperator != (Object)null && player.GetAttachPoint().IsChildOf(((Component)activeOperator).transform)) { return activeOperator; } } return null; } public HudData GetHudData() { HudData result = default(HudData); result.Angle = SeatapultPlugin.DefaultAngle.Value; result.Aim = 0f; result.Power = SeatapultPlugin.DefaultPower.Value; result.AmmoCount = 0; result.AmmoName = ""; result.Cooldown = Mathf.Max(0f, m_fireTimer); result.Deployed = m_deployed; if ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && m_nview.GetZDO() != null) { ZDO zDO = m_nview.GetZDO(); result.Angle = Mathf.Clamp(zDO.GetFloat("seatapult_angle", SeatapultPlugin.DefaultAngle.Value), SeatapultPlugin.AngleMin.Value, SeatapultPlugin.AngleMax.Value); result.Aim = Mathf.Repeat(zDO.GetFloat("seatapult_yaw", 0f), 360f); result.Power = Mathf.Clamp01(zDO.GetFloat("seatapult_power", SeatapultPlugin.DefaultPower.Value)); result.Deployed = zDO.GetFloat("seatapult_deploy", 0f) > 0.5f; } if ((Object)(object)m_store != (Object)null && m_store.GetInventory() != null) { string value = SeatapultPlugin.AllowedAmmo.Value; bool flag = string.IsNullOrWhiteSpace(value); HashSet<string> hashSet = new HashSet<string>(); if (!flag) { string[] array = value.Split(','); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length > 0) { hashSet.Add(text.ToLowerInvariant()); } } } foreach (ItemData allItem in m_store.GetInventory().GetAllItems()) { if (allItem == null || allItem.m_shared == null || allItem.m_shared.m_name == null) { continue; } string item = allItem.m_shared.m_name.ToLowerInvariant(); if (flag || hashSet.Contains(item)) { result.AmmoCount++; if (result.AmmoName.Length == 0) { result.AmmoName = allItem.m_shared.m_name; } } } } return result; } private void EnsureInit() { //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) if (m_init) { return; } m_init = true; m_nview = ((Component)this).GetComponent<ZNetView>(); m_store = ((Component)this).GetComponent<Container>(); if ((Object)(object)Source != (Object)null) { m_arm = (((Object)(object)Source.m_arm != (Object)null) ? Source.m_arm.transform : null); m_shoot = (((Object)(object)Source.m_shootPoint != (Object)null) ? Source.m_shootPoint : null); ((Behaviour)Source).enabled = false; } Aoe[] componentsInChildren = ((Component)this).GetComponentsInChildren<Aoe>(true); Aoe[] array = componentsInChildren; for (int i = 0; i < array.Length; i++) { Object.Destroy((Object)(object)array[i]); } Switch[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Switch>(true); Switch[] array2 = componentsInChildren2; foreach (Switch obj in array2) { obj.m_hoverText = ""; ((Behaviour)obj).enabled = false; } SeatapultPlugin.Log($"runtime neutralization: {componentsInChildren.Length} Aoe zones destroyed, {componentsInChildren2.Length} switches disabled."); if ((Object)(object)m_arm != (Object)null) { m_armBaseRot = m_arm.localRotation; } if ((Object)(object)PitchPivot != (Object)null) { m_pivotBaseRot = PitchPivot.localRotation; } if (m_legs.Count == 0) { Transform[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren3) { if (((Object)val).name.ToLowerInvariant().StartsWith("leg")) { m_legs.Add(val); m_legBase.Add(val.localPosition); SeatapultPlugin.Log("tracking deploy leg '" + ((Object)val).name + "': local " + ((object)val.localPosition/*cast due to .constrained prefix*/).ToString() + " world " + ((object)val.position/*cast due to .constrained prefix*/).ToString() + "."); } } if (m_legs.Count == 0) { SeatapultPlugin.Log("no 'Leg' objects found - deploy uses machine lift only."); } else { SeatapultPlugin.Log("tracking " + m_legs.Count + " deploy legs for the lift."); } } ReadZdo(); DumpPrefabTree(); SeatapultPlugin.Log(string.Format("operator init: arm={0} shoot={1} store={2} scale={3}", ((Object)(object)m_arm != (Object)null) ? ((Object)m_arm).name : "null", (Object)(object)m_shoot != (Object)null, ((Object)(object)m_store != (Object)null) ? (m_store.m_width + "x" + m_store.m_height) : "null", ((Component)this).transform.localScale)); } private void DumpPrefabTree() { if (!SeatapultPlugin.DebugLogging.Value) { return; } List<string> list = new List<string>(); WalkTransform(((Component)this).transform, "", list); SeatapultPlugin.Log("--- seatapult prefab tree ---"); foreach (string item in list) { SeatapultPlugin.Log(item); } SeatapultPlugin.Log("--- end prefab tree ---"); } private static void WalkTransform(Transform t, string indent, List<string> lines) { Component[] components = ((Component)t).GetComponents<Component>(); List<string> list = new List<string>(); bool flag = false; Component[] array = components; string[] hazardHints; foreach (Component val in array) { string text = (((Object)(object)val != (Object)null) ? ((object)val).GetType().Name : "?"); list.Add(text); string text2 = text.ToLowerInvariant(); hazardHints = HazardHints; foreach (string value in hazardHints) { if (text2.Contains(value)) { flag = true; break; } } } string text3 = ((Object)t).name.ToLowerInvariant(); hazardHints = HazardHints; foreach (string value2 in hazardHints) { if (text3.Contains(value2)) { flag = true; break; } } lines.Add(indent + ((Object)t).name + " [" + string.Join(",", list) + "]" + (flag ? " <<< candidate" : "")); for (int k = 0; k < t.childCount; k++) { WalkTransform(t.GetChild(k), indent + " ", lines); } } private void ReadZdo() { if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid()) { ZDO zDO = m_nview.GetZDO(); m_power = Mathf.Clamp01(zDO.GetFloat("seatapult_power", SeatapultPlugin.DefaultPower.Value)); m_angle = zDO.GetFloat("seatapult_angle", SeatapultPlugin.DefaultAngle.Value); m_yaw = zDO.GetFloat("seatapult_yaw", 0f); m_angle = Mathf.Clamp(m_angle, SeatapultPlugin.AngleMin.Value, SeatapultPlugin.AngleMax.Value); } } private void Update() { //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: 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_01e0: 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_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_0319: 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) EnsureInit(); if (!Enabled_() || (Object)(object)m_nview == (Object)null || !m_nview.IsValid()) { return; } float deltaTime = Time.deltaTime; int num = ((!SeatapultPlugin.InvertPitch.Value) ? 1 : (-1)); ZDO zDO = m_nview.GetZDO(); bool flag = m_nview.IsOwner(); m_deployed = zDO.GetFloat("seatapult_deploy", 0f) > 0.5f; if (flag) { m_angle = Mathf.Clamp(zDO.GetFloat("seatapult_angle", SeatapultPlugin.DefaultAngle.Value), SeatapultPlugin.AngleMin.Value, SeatapultPlugin.AngleMax.Value); m_yaw = zDO.GetFloat("seatapult_yaw", 0f); m_power = Mathf.Clamp01(zDO.GetFloat("seatapult_power", SeatapultPlugin.DefaultPower.Value)); } m_recoil = Mathf.MoveTowards(m_recoil, 0f, deltaTime * 3f); m_fireTimer -= deltaTime; m_hintTimer -= deltaTime; m_noOwnershipWarnTimer -= deltaTime; float num2 = Mathf.Sin(MathF.PI * Mathf.Clamp01(m_recoil)) * 35f * m_recoil; if ((Object)(object)PitchPivot != (Object)null) { PitchPivot.localRotation = m_pivotBaseRot * Quaternion.Euler((float)num * m_angle - num2, 0f, 0f); } if ((Object)(object)Lift != (Object)null) { Lift.localRotation = Quaternion.Euler(0f, m_yaw, 0f); float num3 = (m_deployed ? SeatapultPlugin.DeployHeight.Value : 0f); if (Mathf.Abs(Lift.localPosition.y - num3) > 0.001f) { Lift.localPosition = new Vector3(0f, num3, 0f); SeatapultPlugin.Log("deploy: lift y -> " + Lift.localPosition.y + " (deployed=" + m_deployed + ")."); } } float num4 = (m_deployed ? ((0f - SeatapultPlugin.DeployHeight.Value) * 1.15f) : 0f); for (int i = 0; i < m_legs.Count; i++) { Vector3 val = m_legBase[i] + new Vector3(0f, num4, 0f); if (Vector3.Distance(m_legs[i].localPosition, val) > 0.001f) { m_legs[i].localPosition = val; SeatapultPlugin.Log("deploy: leg " + i + " y -> " + m_legs[i].localPosition.y + "."); } } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || !((Character)localPlayer).IsAttached() || (Object)(object)localPlayer.GetAttachPoint() == (Object)null || !localPlayer.GetAttachPoint().IsChildOf(((Component)this).transform)) { return; } if (!flag) { if (m_noOwnershipWarnTimer <= 0f) { m_noOwnershipWarnTimer = 5f; ((Character)localPlayer).Message((MessageType)1, "Only the Seatapult owner can fire this machine.", 0, (Sprite)null, false); } } else { HandleOperatorInput(localPlayer, zDO, num); } } private bool Enabled_() { return SeatapultPlugin.Enabled.Value; } private void HandleOperatorInput(Player player, ZDO zdo, int flipDeg) { if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)) { if (Input.GetKeyDown((KeyCode)273)) { SetPower(zdo, m_power + SeatapultPlugin.PowerStep.Value); ShowHint(player, PowerText(m_power)); } if (Input.GetKeyDown((KeyCode)274)) { SetPower(zdo, m_power - SeatapultPlugin.PowerStep.Value); ShowHint(player, PowerText(m_power)); } if (Input.GetKeyDown((KeyCode)102)) { TryFire(player); } return; } bool flag = Input.GetKey((KeyCode)273) || Input.GetKey((KeyCode)119); bool flag2 = Input.GetKey((KeyCode)274) || Input.GetKey((KeyCode)115); if (flag && !flag2) { SetAngle(zdo, m_angle + SeatapultPlugin.AngleSpeed.Value * Time.deltaTime); ShowHint(player, "Angle " + Mathf.RoundToInt(m_angle) + "°"); } else if (flag2 && !flag) { SetAngle(zdo, m_angle - SeatapultPlugin.AngleSpeed.Value * Time.deltaTime); ShowHint(player, "Angle " + Mathf.RoundToInt(m_angle) + "°"); } bool flag3 = Input.GetKey((KeyCode)275) || Input.GetKey((KeyCode)100); bool flag4 = Input.GetKey((KeyCode)276) || Input.GetKey((KeyCode)97); if (flag3 && !flag4) { SetYaw(zdo, m_yaw + SeatapultPlugin.YawSpeed.Value * Time.deltaTime); ShowHint(player, "Aim " + Mathf.RoundToInt(m_yaw) + "°"); } else if (flag4 && !flag3) { SetYaw(zdo, m_yaw - SeatapultPlugin.YawSpeed.Value * Time.deltaTime); ShowHint(player, "Aim " + Mathf.RoundToInt(m_yaw) + "°"); } if (Input.GetKeyDown((KeyCode)116)) { Eject(player); } if (Input.GetKeyDown((KeyCode)118)) { m_deployed = !m_deployed; zdo.Set("seatapult_deploy", m_deployed ? 1f : 0f); SeatapultPlugin.Log("deploy V toggled -> " + m_deployed + " (zdo now " + zdo.GetFloat("seatapult_deploy", 0f) + ")."); ShowHint(player, m_deployed ? "Legs deployed - machine raised" : "Legs retracted"); } } private void SetAngle(ZDO zdo, float value) { m_angle = Mathf.Clamp(value, SeatapultPlugin.AngleMin.Value, SeatapultPlugin.AngleMax.Value); zdo.Set("seatapult_angle", m_angle); } private void SetYaw(ZDO zdo, float value) { m_yaw = Mathf.Repeat(value, 360f); zdo.Set("seatapult_yaw", m_yaw); } private void SetPower(ZDO zdo, float value) { m_power = Mathf.Clamp01(value); zdo.Set("seatapult_power", m_power); } private static string PowerText(float power) { return "Power " + Mathf.RoundToInt(power * 100f) + "%"; } private void ShowHint(Player player, string text) { if (!(m_hintTimer > 0f)) { m_hintTimer = 0.25f; ((Character)player).Message((MessageType)2, text, 0, (Sprite)null, false); } } private void TryFire(Player player) { //IL_00a6: 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) if (!(m_fireTimer > 0f)) { ItemData val = PickAmmo(); if (val == null) { ((Character)player).Message((MessageType)1, "No ammo in the Seatapult's store.", 0, (Sprite)null, false); return; } m_store.GetInventory().RemoveItem(val, 1); m_fireTimer = Mathf.Max(0.2f, SeatapultPlugin.FireCooldown.Value); m_recoil = 1f; SpawnProjectile(player, val); PlayEffect(((Object)(object)Source != (Object)null) ? Source.m_shootStartEffect : null, ((Object)(object)m_shoot != (Object)null) ? m_shoot.position : ((Component)this).transform.position); ((Character)player).Message((MessageType)2, "Thunk!", 0, (Sprite)null, false); SeatapultPlugin.Log("fired " + val.m_shared.m_name + " at power " + Mathf.RoundToInt(m_power * 100f) + "%"); } } private ItemData PickAmmo() { if ((Object)(object)m_store == (Object)null || m_store.GetInventory() == null) { return null; } List<ItemData> allItems = m_store.GetInventory().GetAllItems(); if (allItems == null || allItems.Count == 0) { return null; } string value = SeatapultPlugin.AllowedAmmo.Value; bool flag = string.IsNullOrWhiteSpace(value); HashSet<string> hashSet = new HashSet<string>(); if (!flag) { string[] array = value.Split(','); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length > 0) { hashSet.Add(text.ToLowerInvariant()); } } } foreach (ItemData item2 in allItems) { if (item2 != null && item2.m_shared != null && item2.m_shared.m_name != null) { string item = item2.m_shared.m_name.ToLowerInvariant(); if (flag || hashSet.Contains(item)) { return item2; } } } return null; } private void SpawnProjectile(Player player, ItemData ammo) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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_00a1: 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_00a7: 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_00cf: 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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)SeatapultPlugin.ProjectilePrefab == (Object)null) { SeatapultPlugin.ProjectilePrefab = SeatapultPlugin.FindPrefab("Catapult_projectile", "Turret_projectile"); } float num = (((Object)(object)Source != (Object)null) ? Source.m_launchForce : 40f) * (0.35f + 0.9f * m_power); Vector3 val = AimDir(); Vector3 val2 = (((Object)(object)m_shoot != (Object)null) ? m_shoot.position : ((Component)this).transform.position); val2 += val * 0.5f; Quaternion val3 = Quaternion.LookRotation(val, Vector3.up); GameObject projectilePrefab = SeatapultPlugin.ProjectilePrefab; GameObject val4 = (((Object)(object)projectilePrefab != (Object)null) ? Object.Instantiate<GameObject>(projectilePrefab, val2, val3) : Object.Instantiate<GameObject>(GameObject.CreatePrimitive((PrimitiveType)0), val2, val3)); if ((Object)(object)projectilePrefab == (Object)null) { Collider component = val4.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } } Projectile component2 = val4.GetComponent<Projectile>(); if ((Object)(object)component2 != (Object)null) { component2.Setup((Character)(object)player, val * num, ((Object)(object)Source != (Object)null) ? Source.m_hitNoise : 0f, (HitData)null, ammo, ammo); return; } ItemDrop component3 = val4.GetComponent<ItemDrop>(); if ((Object)(object)component3 != (Object)null && component3.m_itemData != null) { component3.m_itemData.m_stack = 1; } } private Vector3 AimDir() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //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) //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) int num = (SeatapultPlugin.InvertPitch.Value ? 1 : (-1)); return ((Component)this).transform.rotation * Quaternion.Euler((float)num * m_angle, m_yaw, 0f) * Vector3.forward; } private void Eject(Player player) { //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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) float num = 0.35f + 0.9f * m_power; float num2 = (((Object)(object)Source != (Object)null) ? Source.m_launchForce : 40f) * num * SeatapultPlugin.EjectMultiplier.Value; Vector3 val = AimDir(); SeatapultPlugin.Log("ejecting player at power " + Mathf.RoundToInt(m_power * 100f) + "%"); ((Character)player).Message((MessageType)2, "YEET!", 0, (Sprite)null, false); PlayEffect(((Object)(object)Source != (Object)null) ? Source.m_shootReleaseEffect : null, ((Object)(object)m_shoot != (Object)null) ? m_shoot.position : ((Component)this).transform.position); PlayScream(player, num); ((Character)player).AttachStop(); if (SeatapultPlugin.EjectNoFallDamage.Value && (Object)(object)((Component)player).GetComponent<SeatapultEject>() == (Object)null) { ((Component)player).gameObject.AddComponent<SeatapultEject>(); } Character.SetTakeInputDelay(0.6f); ((Character)player).ForceJump(val * num2, true); } private void PlayEffect(EffectList effects, Vector3 pos) { //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_0015: 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) if (effects == null) { return; } try { effects.Create(pos, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID)); } catch (Exception ex) { Logger.LogWarning((object)("[Seatapult] effect failed: " + ex.Message)); } } private void PlayScream(Player player, float forcePct) { //IL_003d: 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_0054: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown if (!SeatapultPlugin.EjectScream.Value || (Object)(object)player == (Object)null) { return; } try { AudioClip val = SynthesizeScream(0.7f + 0.9f * forcePct); if (!((Object)(object)val == (Object)null)) { GameObject val2 = new GameObject("SeatapultScream"); val2.transform.SetParent(((Component)player).transform, false); val2.transform.localPosition = new Vector3(0f, 0.5f, 0f); AudioSource obj = val2.AddComponent<AudioSource>(); obj.playOnAwake = false; obj.spatialBlend = 1f; obj.rolloffMode = (AudioRolloffMode)0; obj.minDistance = 5f; obj.maxDistance = 60f; obj.volume = SeatapultPlugin.EjectScreamVolume.Value; obj.pitch = 1f; obj.clip = val; obj.Play(); Object.Destroy((Object)val2, val.length + 0.5f); } } catch (Exception ex) { Logger.LogWarning((object)("[Seatapult] scream failed: " + ex.Message)); } } private static AudioClip SynthesizeScream(float seconds) { float num = Mathf.Clamp(seconds, 0.5f, 2.5f); int num2 = Mathf.CeilToInt(num * 22050f); float[] array = new float[num2]; float num3 = 0f; for (int i = 0; i < num2; i++) { float num4 = (float)i / 22050f; float num5 = Mathf.Clamp01(num4 / num); float num7; float num8; if (num5 < 0.2f) { float num6 = num5 / 0.2f; num7 = Mathf.Lerp(420f, 950f, num6); num8 = 0.25f + 0.7f * num6; } else if (num5 < 0.5f) { num7 = 950f + Mathf.Sin(num4 * MathF.PI * 2f * 9f) * 45f; num8 = 0.95f; } else { float num9 = (num5 - 0.5f) / 0.5f; num7 = Mathf.Lerp(950f, 180f, Mathf.Pow(num9, 0.7f)) + Mathf.Sin(num4 * MathF.PI * 2f * 8f) * 30f; num8 = 0.95f * Mathf.Clamp01(2f * (1f - num9)); } num3 += MathF.PI * 2f * num7 / 22050f; float num10 = 2f * (num3 / (MathF.PI * 2f) - Mathf.Floor(num3 / (MathF.PI * 2f) + 0.5f)) * 0.62f + Mathf.Sin(num3) * 0.38f; float num11 = Mathf.Clamp01(num4 / 0.05f); array[i] = num10 * num8 * num11 * 0.9f; } AudioClip obj = AudioClip.Create("SeatapultScream", num2, 1, 22050, false); obj.SetData(array, 0); return obj; } } [BepInPlugin("com.seatapult.seatapult", "Seatapult", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class SeatapultPlugin : BaseUnityPlugin { public const string PluginGUID = "com.seatapult.seatapult"; public const string PluginName = "Seatapult"; public const string PluginVersion = "0.1.0"; private const string VanillaPrefabName = "Catapult"; private const string NewPrefabName = "Seatapult"; private const string PieceName = "Seatapult"; private const string PieceDescription = "A half-size catapult with an operator's seat, an ammo store, and an ejector seat. Fires anything stored inside."; internal static bool PrefabRegistered; internal static GameObject ProjectilePrefab; internal static GameObject ChairPrefab; internal static GameObject ChestPrefab; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> AddBuildPieces; internal static ConfigEntry<float> Scale; internal static ConfigEntry<bool> DebugLogging; internal static ConfigEntry<float> DefaultAngle; internal static ConfigEntry<float> AngleMin; internal static ConfigEntry<float> AngleMax; internal static ConfigEntry<float> AngleSpeed; internal static ConfigEntry<float> YawSpeed; internal static ConfigEntry<float> PowerStep; internal static ConfigEntry<float> DefaultPower; internal static ConfigEntry<bool> InvertPitch; internal static ConfigEntry<float> FireCooldown; internal static ConfigEntry<float> EjectMultiplier; internal static ConfigEntry<bool> EjectNoFallDamage; internal static ConfigEntry<bool> EjectScream; internal static ConfigEntry<float> EjectScreamVolume; internal static ConfigEntry<string> AllowedAmmo; internal static ConfigEntry<float> DeployHeight; private void Awake() { //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Expected O, but got Unknown //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Expected O, but got Unknown Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master toggle. When false the Seatapult does nothing."); AddBuildPieces = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AddBuildPieces", true, "Add the Seatapult piece to the Hammer build menu. Requires a game restart."); Scale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Scale", 0.55f, "Uniform scale applied to the cloned catapult model (0.5 = half size, 0.55 = slightly larger than half). Requires a game restart."); Scale.Value = Mathf.Clamp(Scale.Value, 0.25f, 1f); DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLogging", true, "Log Seatapult events to the BepInEx log."); DefaultAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "DefaultAngle", 25f, "Starting arm elevation in degrees."); AngleMin = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "AngleMin", -10f, "Lowest arm elevation in degrees."); AngleMax = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "AngleMax", 75f, "Highest arm elevation in degrees."); AngleSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "AngleSpeed", 30f, "How fast W/S raise and lower the arm, degrees per second."); YawSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "YawSpeed", 45f, "How fast A/D swing the aim left and right, degrees per second."); PowerStep = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "PowerStep", 0.08f, "How much one mouse-wheel tick changes the power."); DefaultPower = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "DefaultPower", 0.5f, "Starting power as a fraction of the catapult's launch force."); DefaultPower.Value = Mathf.Clamp01(DefaultPower.Value); InvertPitch = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "InvertPitch", false, "Flip the direction of the arm/aim when using the seat. Try this if the arm swings the wrong way."); FireCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "FireCooldown", 2.5f, "Minimum seconds between shots."); EjectMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "EjectMultiplier", 1f, "Power multiplier applied when using the ejector seat (1 = same power as the catapult's launch force)."); EjectNoFallDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("Combat", "EjectNoFallDamage", true, "When true you take no fall damage from ejecting yourself."); EjectScream = ((BaseUnityPlugin)this).Config.Bind<bool>("Combat", "EjectScream", true, "Plays a synthesized cartoon scream when the ejector seat launches you."); EjectScreamVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "EjectScreamVolume", 1f, new ConfigDescription("Volume of the eject scream.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); AllowedAmmo = ((BaseUnityPlugin)this).Config.Bind<string>("Ammo", "AllowedItems", "", "Comma-separated item names the Seatapult will load. Empty = any item in its store."); DeployHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DeployHeight", 0.9f, new ConfigDescription("How high the machine lifts (and how far the legs extend) when deployed with V while seated. At 0.55 piece scale 0.9 lifts the body about half a meter.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 3f), Array.Empty<object>())); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Seatapult 0.1.0 loading..."); SeatInputPatches.Apply(); PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable; PieceManager.OnPiecesRegistered += OnPiecesRegistered; if (IsVanillaPrefabReady()) { OnVanillaPrefabsAvailable(); } } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable; PieceManager.OnPiecesRegistered -= OnPiecesRegistered; } private void OnGUI() { if (Enabled.Value) { SeatapultHud.Render(); } } private void OnVanillaPrefabsAvailable() { if (!Enabled.Value || !AddBuildPieces.Value) { return; } GameObject val = FindBaseCatapultPrefab(); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Seatapult: could not find the vanilla Catapult prefab to clone. No build piece was registered."); return; } try { RegisterPrefab(val); } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)string.Format("{0}: failed to register the '{1}' prefab: {2}", "Seatapult", "Seatapult", arg)); } } private void RegisterPrefab(GameObject baseCatapult) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) GameObject val = PrefabManager.Instance.CreateClonedPrefab("Seatapult", baseCatapult); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Seatapult: failed to clone the Catapult prefab."); return; } Catapult component = val.GetComponent<Catapult>(); if ((Object)(object)component == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Seatapult: cloned prefab has no Catapult component - aborting."); return; } float num = Mathf.Clamp(Scale.Value, 0.25f, 1f); val.transform.localScale = new Vector3(num, num, num); ((Behaviour)component).enabled = false; if ((Object)(object)component.m_loadPoint != (Object)null) { component.m_loadPoint.m_hoverText = ""; ((Behaviour)component.m_loadPoint).enabled = false; } NeutralizeSpikes(val); AddAmmoStore(val); Transform val2 = SetupLift(val); Transform val3 = SetupAimPivot(val2, component); SetupSeat(val2, val, val3); SetupStoreChest(val2); SeatapultOperator seatapultOperator = val.AddComponent<SeatapultOperator>(); seatapultOperator.Source = component; seatapultOperator.Lift = val2; seatapultOperator.PitchPivot = val3; PrefabManager.Instance.AddPrefab(val); PrefabRegistered = true; Log(string.Format("{0} registered, cloned from '{1}' (scale {2:F2}).", "Seatapult", ((Object)baseCatapult).name, num)); } private static void NeutralizeSpikes(GameObject prefab) { Aoe[] componentsInChildren = prefab.GetComponentsInChildren<Aoe>(true); Aoe[] array = componentsInChildren; for (int i = 0; i < array.Length; i++) { Object.DestroyImmediate((Object)(object)array[i]); } Switch[] componentsInChildren2 = prefab.GetComponentsInChildren<Switch>(true); Switch[] array2 = componentsInChildren2; foreach (Switch obj in array2) { obj.m_hoverText = ""; ((Behaviour)obj).enabled = false; } Log(string.Format("Neutralized {0} Aoe damage zones and {1} vanilla switches ({2} leg/arm spikes no longer hurt or trigger).", componentsInChildren.Length, componentsInChildren2.Length, "Seatapult")); } private static void AddAmmoStore(GameObject prefab) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ChestPrefab == (Object)null) { ChestPrefab = FindPrefab("piece_chest_wood", "woodchest", "piece_chest"); } Container val = (((Object)(object)ChestPrefab != (Object)null) ? ChestPrefab.GetComponent<Container>() : null); Container val2 = prefab.AddComponent<Container>(); val2.m_name = "Seatapult ammo store"; if ((Object)(object)val != (Object)null) { val2.m_bkg = val.m_bkg; val2.m_width = val.m_width; val2.m_height = val.m_height; val2.m_privacy = val.m_privacy; val2.m_checkGuardStone = false; val2.m_autoDestroyEmpty = false; val2.m_destroyedLootPrefab = val.m_destroyedLootPrefab; } else { val2.m_width = 6; val2.m_height = 6; } val2.m_openEffects = (((Object)(object)val != (Object)null) ? val.m_openEffects : null); val2.m_closeEffects = (((Object)(object)val != (Object)null) ? val.m_closeEffects : null); } private static Transform SetupLift(GameObject prefab) { //IL_0005: 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) Transform transform = new GameObject("SeatapultLift").transform; transform.SetParent(prefab.transform, false); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; for (int num = prefab.transform.childCount - 1; num >= 0; num--) { Transform child = prefab.transform.GetChild(num); if (!((Object)(object)child == (Object)(object)transform)) { child.SetParent(transform, true); } } Log("SeatapultLift created - all machine parts, seat and store move together for aim and deploy."); return transform; } private static Transform SetupAimPivot(Transform parent, Catapult source) { //IL_0005: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) Transform transform = new GameObject("SeatapultAim").transform; transform.SetParent(parent, false); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; if ((Object)(object)source.m_arm != (Object)null) { Transform transform2 = source.m_arm.transform; transform.position = transform2.position; transform2.SetParent(transform, true); transform2.localPosition = Vector3.zero; } return transform; } private unsafe static void SetupSeat(Transform parent, GameObject prefab, Transform pitch) { //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_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: 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_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_021c: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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_036d: 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_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0270: 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_0233: 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_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_0402: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0429: Unknown result type (might be due to invalid IL or missing references) //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04c4: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_044f: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0444: Unknown result type (might be due to invalid IL or missing references) //IL_0525: Unknown result type (might be due to invalid IL or missing references) //IL_0534: Unknown result type (might be due to invalid IL or missing references) //IL_0547: Unknown result type (might be due to invalid IL or missing references) //IL_055c: Unknown result type (might be due to invalid IL or missing references) GameObject val = null; string text = "sitting"; Vector3 val2 = Vector3.zero; Vector3? val3 = null; Quaternion? val4 = null; if ((Object)(object)ChairPrefab == (Object)null) { ChairPrefab = FindPrefab("piece_chair", "piece_bench02", "piece_stool", "piece_chair02"); } if ((Object)(object)ChairPrefab != (Object)null) { val = Object.Instantiate<GameObject>(ChairPrefab, parent); Chair component = val.GetComponent<Chair>(); if ((Object)(object)component != (Object)null) { if (!string.IsNullOrEmpty(component.m_attachAnimation)) { text = component.m_attachAnimation; } val2 = component.m_detachOffset; if ((Object)(object)component.m_attachPoint != (Object)null) { val3 = component.m_attachPoint.localPosition; val4 = component.m_attachPoint.localRotation; } Log($"chair serialized: anim='{text}' detachOffset={val2} attachPoint={val3 ?? new Vector3?(Vector3.zero)}."); } ((Object)val).name = "SeatapultSeat"; StripComponents(val); FixSeatRenderers(val); val.transform.localPosition = new Vector3(2.35f, 1.25f, 0.45f); val.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); val.transform.localScale = Vector3.one; } else { val = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)val).name = "SeatapultSeat"; val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(2.35f, 1.25f, 0.45f); val.transform.localScale = new Vector3(0.5f, 0.2f, 0.6f); } Transform val5 = FindChairAttachPoint(val); Vector3 val6; if ((Object)(object)val5 == (Object)null) { val5 = new GameObject("SeatapultAttach").transform; val5.SetParent(val.transform, false); if (val3.HasValue) { val5.localPosition = val3.Value; if (val4.HasValue) { val5.localRotation = val4.Value; } string[] obj = new string[5] { "using vanilla chair attach coords local ", null, null, null, null }; val6 = val5.localPosition; obj[1] = ((object)(*(Vector3*)(&val6))/*cast due to .constrained prefix*/).ToString(); obj[2] = " (world "; val6 = val5.position; obj[3] = ((object)(*(Vector3*)(&val6))/*cast due to .constrained prefix*/).ToString(); obj[4] = ")."; Log(string.Concat(obj)); } else { val5.localPosition = new Vector3(0f, 0.6f, 0.1f); } } else { ((Object)val5).name = "SeatapultAttach"; string[] obj2 = new string[5] { "using vanilla chair attach point at local ", null, null, null, null }; val6 = val5.localPosition; obj2[1] = ((object)(*(Vector3*)(&val6))/*cast due to .constrained prefix*/).ToString(); obj2[2] = " (world "; val6 = val5.position; obj2[3] = ((object)(*(Vector3*)(&val6))/*cast due to .constrained prefix*/).ToString(); obj2[4] = ")."; Log(string.Concat(obj2)); } BoxCollider val7 = val.GetComponent<BoxCollider>(); if ((Object)(object)val7 == (Object)null) { val7 = val.AddComponent<BoxCollider>(); } ((Collider)val7).isTrigger = false; val7.center = new Vector3(0f, 0.2f, 0f); val7.size = new Vector3(0.5f, 0.35f, 0.5f); SeatapultSeat seatapultSeat = val.GetComponent<SeatapultSeat>(); if ((Object)(object)seatapultSeat == (Object)null) { seatapultSeat = val.AddComponent<SeatapultSeat>(); } seatapultSeat.RootObject = prefab; seatapultSeat.AttachPoint = val5; seatapultSeat.AttachAnimation = text; seatapultSeat.DetachOffset = val2; Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true); int num = 0; Renderer[] array = componentsInChildren; foreach (Renderer val8 in array) { if (val8.enabled && ((Component)val8).gameObject.activeInHierarchy) { num++; } } Renderer[] componentsInChildren2 = prefab.GetComponentsInChildren<Renderer>(true); Bounds val9 = default(Bounds); bool flag = false; array = componentsInChildren2; foreach (Renderer val10 in array) { Bounds bounds = val10.bounds; val6 = ((Bounds)(ref bounds)).size; if (!(((Vector3)(ref val6)).sqrMagnitude <= 0f)) { if (!flag) { val9 = val10.bounds; flag = true; } else { ((Bounds)(ref val9)).Encapsulate(val10.bounds); } } } string text2 = string.Join(",", Array.ConvertAll(val.GetComponentsInChildren<Collider>(true), (Collider x) => ((object)x).GetType().Name + "@" + ((Object)((Component)x).transform).name)); Log($"Seat local={val.transform.localPosition} world={val.transform.position}; attach local={val5.localPosition} world={val5.position}; renderers={componentsInChildren.Length} visible={num}; colliders=[{text2}]."); if (flag) { Log($"Seatapult visual bounds center={((Bounds)(ref val9)).center} size={((Bounds)(ref val9)).size} (seat world {val.transform.position} inside={((Bounds)(ref val9)).Contains(val.transform.position)})."); } } private static void SetupStoreChest(Transform parent) { //IL_0085: 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_00b4: 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_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ChestPrefab == (Object)null) { ChestPrefab = FindPrefab("piece_chest_wood", "woodchest", "piece_chest"); } if ((Object)(object)ChestPrefab == (Object)null) { Log("No chest prefab available - store has no visible chest."); return; } GameObject val = Object.Instantiate<GameObject>(ChestPrefab, parent); ((Object)val).name = "SeatapultStore"; StripComponents(val); FixSeatRenderers(val); val.transform.localPosition = new Vector3(-2.35f, 1f, -0.45f); val.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); val.transform.localScale = Vector3.one; BoxCollider val2 = val.GetComponent<BoxCollider>(); if ((Object)(object)val2 == (Object)null) { val2 = val.AddComponent<BoxCollider>(); } ((Collider)val2).isTrigger = false; val2.center = new Vector3(0f, 0.28f, 0f); val2.size = new Vector3(0.85f, 0.6f, 0.85f); val.AddComponent<SeatapultStore>(); Log($"Store chest placed at local={val.transform.localPosition} world={val.transform.position}."); } private static Transform FindChairAttachPoint(GameObject seat) { Transform[] componentsInChildren = seat.GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if ((Object)(object)val == (Object)(object)seat.transform) { continue; } string text = ((Object)val).name.ToLowerInvariant(); switch (text) { default: if (!text.Contains("attach") || text.Length > 14) { continue; } break; case "attach_point": case "attachpoint": case "attach": case "sit_anchor": break; } return val; } return null; } private static void FixSeatRenderers(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { string text = ((Object)val).name.ToLowerInvariant(); if (text.StartsWith("worn") || text.StartsWith("broken") || text.StartsWith("destruction")) { ((Component)val).gameObject.SetActive(false); } } MeshRenderer[] componentsInChildren2 = root.GetComponentsInChildren<MeshRenderer>(true); int num = 0; MeshRenderer[] array = componentsInChildren2; foreach (MeshRenderer val2 in array) { if (!((Renderer)val2).enabled) { ((Renderer)val2).enabled = true; num++; } } SkinnedMeshRenderer[] componentsInChildren3 = root.GetComponentsInChildren<SkinnedMeshRenderer>(true); SkinnedMeshRenderer[] array2 = componentsInChildren3; foreach (SkinnedMeshRenderer val3 in array2) { if (!((Renderer)val3).enabled) { ((Renderer)val3).enabled = true; num++; } } Log($"Seat renderers forced on ({num} previously disabled, {componentsInChildren2.Length} mesh + {componentsInChildren3.Length} skinned present)."); } private static void StripComponents(GameObject root) { if ((Object)(object)root == (Object)null) { return; } List<Component> list = new List<Component>(); Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !(val is Transform) && !(val is MeshFilter) && !(val is MeshRenderer) && !(val is SkinnedMeshRenderer)) { list.Add(val); } } foreach (Component item in list) { Object.DestroyImmediate((Object)(object)item); } int num = root.GetComponentsInChildren<Component>(true).Length; Log($"Seat stripped: kept {num} components (transforms/renderers only)."); } private void OnPiecesRegistered() { if (!Enabled.Value || !AddBuildPieces.Value || !PrefabRegistered) { return; } GameObject prefab = PrefabManager.Instance.GetPrefab("Seatapult"); if ((Object)(object)prefab == (Object)null) { return; } try { AddPiece(prefab); } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)string.Format("{0}: failed to add '{1}' to the Hammer menu: {2}", "Seatapult", "Seatapult", arg)); } } private void AddPiece(GameObject prefab) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: 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_006f: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown Piece val = prefab.GetComponent<Piece>(); if ((Object)(object)val == (Object)null) { val = prefab.GetComponentInChildren<Piece>(); } if ((Object)(object)val != (Object)null) { bool canBeRemoved = val.m_canBeRemoved; val.m_canBeRemoved = true; Log(string.Format("'{0}' piece removal enabled (m_canBeRemoved {1} -> true).", "Seatapult", canBeRemoved)); } else { Log("'Seatapult' prefab has NO Piece component - hammer removal unavailable."); } PieceConfig val2 = new PieceConfig { Name = "Seatapult", Description = "A half-size catapult with an operator's seat, an ammo store, and an ejector seat. Fires anything stored inside.", PieceTable = "Hammer", Category = "Misc", Enabled = true }; val2.AddRequirement("Wood", 20, true); val2.AddRequirement("Stone", 15, true); val2.AddRequirement("Iron", 5, true); PieceManager.Instance.AddPiece(new CustomPiece(prefab, false, val2)); Log("'Seatapult' added to the Hammer > Misc build menu."); } private static bool IsVanillaPrefabReady() { if ((Object)(object)ZNetScene.instance != (Object)null && ZNetScene.instance.m_prefabs != null && ZNetScene.instance.m_prefabs.Count > 0) { return true; } return (Object)(object)FindBaseCatapultPrefab() != (Object)null; } internal static GameObject FindBaseCatapultPrefab() { if ((Object)(object)ZNetScene.instance != (Object)null && ZNetScene.instance.m_prefabs != null) { foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if (!((Object)(object)prefab == (Object)null) && !((Object)(object)prefab.GetComponent<Catapult>() == (Object)null) && string.Equals(((Object)prefab).name, "Catapult", StringComparison.OrdinalIgnoreCase)) { return prefab; } } foreach (GameObject prefab2 in ZNetScene.instance.m_prefabs) { if ((Object)(object)prefab2 != (Object)null && (Object)(object)prefab2.GetComponent<Catapult>() != (Object)null && ((Object)prefab2).name.ToLowerInvariant().Contains("catapult")) { return prefab2; } } } PrefabManager instance = PrefabManager.Instance; if (instance == null) { return null; } return instance.GetPrefab("Catapult"); } internal static GameObject FindPrefab(params string[] names) { foreach (string text in names) { if (string.IsNullOrEmpty(text)) { continue; } PrefabManager instance = PrefabManager.Instance; GameObject val = ((instance != null) ? instance.GetPrefab(text) : null); if ((Object)(object)val != (Object)null) { return val; } if ((Object)(object)ZNetScene.instance != (Object)null) { val = ZNetScene.instance.GetPrefab(text); if ((Object)(object)val != (Object)null) { return val; } } } return null; } internal static void Log(string message) { if (DebugLogging.Value) { Logger.LogInfo((object)("[Seatapult] " + message)); } } } public class SeatapultSeat : MonoBehaviour, Interactable, Hoverable { public GameObject RootObject; public Transform AttachPoint; public string AttachAnimation = "sitting"; public Vector3 DetachOffset = Vector3.zero; public bool Interact(Humanoid user, bool hold, bool alt) { //IL_0051: 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) if (hold) { return false; } Player val = (Player)(object)((user is Player) ? user : null); if (val == null) { return true; } if (((Character)val).IsAttached()) { SeatapultPlugin.Log("sit Interact on already-attached player " + val.GetPlayerName() + " (ignored)."); return true; } SeatapultPlugin.Log($"sit Interact by {val.GetPlayerName()} at {((Component)this).transform.position} (attach={((Component)AttachPoint).transform.position} hold={hold} alt={alt})."); bool flag = AttachStart(val); SeatapultPlugin.Log($"sit attach result={flag} (IsAttached={((Character)val).IsAttached()}, attachPointMatch={(Object)(object)val.GetAttachPoint() == (Object)(object)AttachPoint})."); if (flag) { ((Character)val).Message((MessageType)2, "Seatapult: Shift+F = fire, Shift+Up/Down = power, Arrows/WASD = angle & aim, V = deploy, T = eject, E = stand up", 0, (Sprite)null, false); } return true; } private bool AttachStart(Player player) { //IL_0035: 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_005c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)AttachPoint == (Object)null || (Object)(object)RootObject == (Object)null) { return false; } ((Character)player).AttachStart(AttachPoint, RootObject, true, false, false, AttachAnimation, DetachOffset, (Transform)null); SeatapultPlugin.Log($"attach anim='{AttachAnimation}' detachOffset={DetachOffset} attachLocal={AttachPoint.localPosition}."); if (((Character)player).IsAttached()) { return (Object)(object)player.GetAttachPoint() == (Object)(object)AttachPoint; } return false; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { return "Sit in the Seatapult [<color=yellow>E</color>]"; } public string GetHoverName() { return "Seatapult"; } public float GetHoverOffset() { return 1f; } } public class SeatapultStore : MonoBehaviour, Interactable, Hoverable { public bool Interact(Humanoid character, bool hold, bool alt) { Container store = GetStore(); if ((Object)(object)store == (Object)null) { return false; } return store.Interact(character, hold, alt); } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { return "Seatapult ammo store [E]"; } public string GetHoverName() { return "Seatapult ammo store"; } public float GetHoverOffset() { return 0f; } private Container GetStore() { Transform root = ((Component)this).transform.root; if (!((Object)(object)root != (Object)null)) { return null; } return ((Component)root).GetComponent<Container>(); } } public static class SeatInputPatches { [HarmonyPatch(typeof(ZInput), "GetButton")] [HarmonyPatch(typeof(ZInput), "GetButtonDown")] [HarmonyPatch(typeof(ZInput), "GetButtonUp")] private static class ZInputSpoof { private static bool Prefix(string name, ref bool __result) { if (SeatInUse() && BlockedNames.Contains(name)) { __result = false; return false; } return true; } } [HarmonyPatch(typeof(Character), "CustomFixedUpdate")] private static class LockMovePatch { private static void Prefix(Character __instance) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) if (SeatInUse() && (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { __instance.SetMoveDir(Vector3.zero); __instance.StopMovement(); } } } private static readonly HashSet<string> BlockedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Forward", "Back", "Backward", "Left", "Right", "Jump", "Sneak", "Run", "Sprint", "Attack", "AttackHold", "SecondaryAttack", "SecondaryAttackHold", "Block", "BlockHold", "Dodge" }; public static bool SeatInUse() { return (Object)(object)SeatapultOperator.GetSeatedOperator(Player.m_localPlayer) != (Object)null; } public static void Apply() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) new Harmony("com.seatapult.seatapult.seatinput").PatchAll(typeof(SeatInputPatches).Assembly); } } }