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 BarrelCopter v1.0.0
BarrelCopter.dll
Decompiled an hour agousing System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace BarrelCopterMod; public class SE_BarrelCopter : SE_Stats { public override void Setup(Character character) { ((SE_Stats)this).Setup(character); if (character is Player) { BarrelCopterPlugin.SeActive = true; } } public override void Stop() { ((StatusEffect)this).Stop(); BarrelCopterPlugin.SeActive = false; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { Rigidbody val = (Rigidbody)((BarrelCopterPlugin.fBody != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val != (Object)null) { val.useGravity = true; } } } } [BepInPlugin("neck.valheim.barrelcopter", "Barrel Copter", "1.0.0")] public class BarrelCopterPlugin : BaseUnityPlugin { internal class MeshBuilder { public List<Vector3> V = new List<Vector3>(); public List<int> T = new List<int>(); private void Tri(Vector3 a, Vector3 b, Vector3 c, Vector3 outward) { //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_0003: 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_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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_002a: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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) if (Vector3.Dot(Vector3.Cross(b - a, c - a), outward) < 0f) { Vector3 val = b; b = c; c = val; } int count = V.Count; V.Add(a); V.Add(b); V.Add(c); T.Add(count); T.Add(count + 1); T.Add(count + 2); } private void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 outward) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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) Tri(a, b, c, outward); Tri(a, c, d, outward); } public void Tube(float y0, float y1, int segs, Func<float, float> profile, bool inside) { //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0110: 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) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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) //IL_0134: Unknown result type (might be due to invalid IL or missing references) int num = 6; Vector3 a = default(Vector3); Vector3 b = default(Vector3); Vector3 d = default(Vector3); Vector3 c = default(Vector3); Vector3 val = default(Vector3); for (int i = 0; i < num; i++) { float num2 = (float)i / (float)num; float num3 = (float)(i + 1) / (float)num; float num4 = Mathf.Lerp(y0, y1, num2); float num5 = Mathf.Lerp(y0, y1, num3); float num6 = profile(num2); float num7 = profile(num3); for (int j = 0; j < segs; j++) { float num8 = (float)Math.PI * 2f * (float)j / (float)segs; float num9 = (float)Math.PI * 2f * (float)(j + 1) / (float)segs; ((Vector3)(ref a))..ctor(Mathf.Cos(num8) * num6, num4, Mathf.Sin(num8) * num6); ((Vector3)(ref b))..ctor(Mathf.Cos(num9) * num6, num4, Mathf.Sin(num9) * num6); ((Vector3)(ref d))..ctor(Mathf.Cos(num8) * num7, num5, Mathf.Sin(num8) * num7); ((Vector3)(ref c))..ctor(Mathf.Cos(num9) * num7, num5, Mathf.Sin(num9) * num7); ((Vector3)(ref val))..ctor(Mathf.Cos((num8 + num9) * 0.5f), 0f, Mathf.Sin((num8 + num9) * 0.5f)); Quad(a, b, c, d, val); if (inside) { Quad(a, b, c, d, -val); } } } } public void Disc(float y, float radius, int segs) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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) Vector3 a = default(Vector3); Vector3 b = default(Vector3); Vector3 c = default(Vector3); for (int i = 0; i < segs; i++) { float num = (float)Math.PI * 2f * (float)i / (float)segs; float num2 = (float)Math.PI * 2f * (float)(i + 1) / (float)segs; ((Vector3)(ref a))..ctor(0f, y, 0f); ((Vector3)(ref b))..ctor(Mathf.Cos(num) * radius, y, Mathf.Sin(num) * radius); ((Vector3)(ref c))..ctor(Mathf.Cos(num2) * radius, y, Mathf.Sin(num2) * radius); Tri(a, b, c, Vector3.up); Tri(a, b, c, Vector3.down); } } public void Box(Vector3 center, Vector3 half, Quaternion rot) { //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_0023: 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_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_0058: 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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00a3: 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_00aa: 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_00b2: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: 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) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: 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) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[3] { Vector3.right, Vector3.up, Vector3.forward }; for (int i = 0; i < 3; i++) { for (int j = -1; j <= 1; j += 2) { Vector3 val = array[i] * (float)j; Vector3 val2 = array[(i + 1) % 3]; Vector3 val3 = array[(i + 2) % 3]; Vector3 val4 = Corner(val, -val2, -val3, half); Vector3 val5 = Corner(val, val2, -val3, half); Vector3 val6 = Corner(val, val2, val3, half); Vector3 val7 = Corner(val, -val2, val3, half); Quad(center + rot * val4, center + rot * val5, center + rot * val6, center + rot * val7, rot * val); } } } private static Vector3 Corner(Vector3 n, Vector3 u, Vector3 w, Vector3 half) { //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_0003: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) Vector3 val = n + u + w; return new Vector3(val.x * half.x, val.y * half.y, val.z * half.z); } public void Beam(Vector3 a, Vector3 b, float thick) { //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_0003: 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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_0031: 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) Vector3 val = b - a; Box((a + b) * 0.5f, new Vector3(thick, thick, ((Vector3)(ref val)).magnitude * 0.5f), Quaternion.LookRotation(((Vector3)(ref val)).normalized)); } public Mesh ToMesh(string name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown Mesh val = new Mesh(); ((Object)val).name = name; val.SetVertices(V); val.SetTriangles(T, 0); val.RecalculateNormals(); val.RecalculateBounds(); return val; } } public const string Guid = "neck.valheim.barrelcopter"; public const string Prefab = "BarrelCopter"; private const string Key = "item_barrelcopter"; internal static bool SeActive; internal static string Dir; internal static HashSet<Character> Riders = new HashSet<Character>(); internal static ConfigEntry<float> cfgFlySpeed; internal static ConfigEntry<float> cfgBoostSpeed; internal static ConfigEntry<float> cfgVertSpeed; internal static ConfigEntry<float> cfgStamina; internal static ConfigEntry<float> cfgMaxHeight; internal static ConfigEntry<float> cfgVolume; internal static ConfigEntry<float> cfgScale; internal static ConfigEntry<float> cfgOffsetY; internal static ConfigEntry<float> cfgRotorHeight; private static ConfigEntry<string> cfgRecipe; private static ConfigEntry<float> cfgFall; internal static readonly FieldInfo fBody = AccessTools.Field(typeof(Character), "m_body"); private static GameObject container; private static GameObject instance; private static SE_BarrelCopter effect; private static Sprite icon; private static List<Mesh> bodyMeshes = new List<Mesh>(); private static List<Material> bodyMats = new List<Material>(); private static Mesh rotorMesh; private static Material rotorMat; private static AudioClip rotorClip; internal static AudioClip RotorClip => BuildRotorClip(); private void Awake() { //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Expected O, but got Unknown Dir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); cfgFlySpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "FlySpeed", 12f, "Cruise speed in m/s (a running player is ~7)"); cfgBoostSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "BoostSpeed", 26f, "Speed in m/s while holding Run (Shift)"); cfgVertSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "VerticalSpeed", 9f, "Climb (Space) / descend (Ctrl) speed in m/s"); cfgStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "StaminaPerSecond", 0f, "Stamina drained per second of flight (0 = free). When empty the copter only descends"); cfgMaxHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "MaxHeightAboveGround", 0f, "Ceiling above the terrain in meters (0 = unlimited)"); cfgFall = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "FallDamageReductionPercent", 100f, "Fall damage reduction while the copter is equipped"); cfgVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "Volume", 0.35f, "Rotor volume 0..1 (0 = silent)"); cfgRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("Recipe", "Resources", "Wood:20,Resin:10,Flax:5", "Crafting cost as Prefab:Amount,Prefab:Amount"); cfgScale = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "Scale", 1f, "Model scale"); cfgOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "OffsetY", 0f, "Move the barrel up/down (meters)"); cfgRotorHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "RotorHeight", 2.35f, "Height of the rotor above the feet"); Harmony val = new Harmony("neck.valheim.barrelcopter"); val.PatchAll(typeof(Patches)); } private static GameObject FindItem(ObjectDB db, string name) { for (int i = 0; i < db.m_items.Count; i++) { if ((Object)(object)db.m_items[i] != (Object)null && ((Object)db.m_items[i]).name == name) { return db.m_items[i]; } } return null; } private static void AddWord(string key, string value) { MethodInfo methodInfo = AccessTools.Method(typeof(Localization), "AddWord", (Type[])null, (Type[])null); if (methodInfo != null) { methodInfo.Invoke(Localization.instance, new object[2] { key, value }); } } private static bool RussianUi() { return Localization.instance != null && Localization.instance.GetSelectedLanguage() == "Russian"; } private static Sprite LoadIcon() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0070: 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) if ((Object)(object)icon != (Object)null) { return icon; } string path = Path.Combine(Dir, "BarrelCopterIcon.png"); if (!File.Exists(path)) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path))) { return null; } icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); return icon; } private static void BuildPrefab(ObjectDB db) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_017b: Unknown result type (might be due to invalid IL or missing references) GameObject val = FindItem(db, "Wishbone"); if ((Object)(object)val == (Object)null) { val = FindItem(db, "BeltStrength"); } if (!((Object)(object)val == (Object)null)) { if ((Object)(object)container == (Object)null) { container = new GameObject("BarrelCopterContainer"); container.SetActive(false); Object.DontDestroyOnLoad((Object)(object)container); } GameObject val2 = Object.Instantiate<GameObject>(val, container.transform); ((Object)val2).name = "BarrelCopter"; for (int num = val2.transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)val2.transform.GetChild(num)).gameObject); } Renderer[] components = val2.GetComponents<Renderer>(); foreach (Renderer val3 in components) { Object.DestroyImmediate((Object)(object)val3); } MeshFilter[] components2 = val2.GetComponents<MeshFilter>(); foreach (MeshFilter val4 in components2) { Object.DestroyImmediate((Object)(object)val4); } CreateVisual(val2.transform, asItem: true); ItemDrop component = val2.GetComponent<ItemDrop>(); component.m_itemData.m_dropPrefab = val2; SharedData shared = component.m_itemData.m_shared; shared.m_name = "$item_barrelcopter"; shared.m_description = "$item_barrelcopter_description"; shared.m_itemType = (ItemType)18; shared.m_maxStackSize = 1; shared.m_weight = 4f; shared.m_setStatusEffect = null; Sprite val5 = LoadIcon(); if ((Object)(object)val5 != (Object)null) { shared.m_icons = (Sprite[])(object)new Sprite[1] { val5 }; } SE_BarrelCopter sE_BarrelCopter = ScriptableObject.CreateInstance<SE_BarrelCopter>(); ((Object)sE_BarrelCopter).name = "SE_BarrelCopter"; ((StatusEffect)sE_BarrelCopter).m_name = "$item_barrelcopter"; ((StatusEffect)sE_BarrelCopter).m_tooltip = "$item_barrelcopter_description"; ((StatusEffect)sE_BarrelCopter).m_icon = ((shared.m_icons != null && shared.m_icons.Length > 0) ? shared.m_icons[0] : null); ((SE_Stats)sE_BarrelCopter).m_fallDamageModifier = 0f - Mathf.Clamp01(cfgFall.Value / 100f); ((SE_Stats)sE_BarrelCopter).m_jumpStaminaUseModifier = -1f; ((SE_Stats)sE_BarrelCopter).m_runStaminaDrainModifier = -1f; effect = sE_BarrelCopter; shared.m_equipStatusEffect = (StatusEffect)(object)sE_BarrelCopter; instance = val2; } } internal static void EnsureItems(ObjectDB db) { if ((Object)(object)db == (Object)null || db.m_items.Count == 0) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(ObjectDB), "m_itemByHash"); Dictionary<int, GameObject> dictionary = ((fieldInfo != null) ? ((Dictionary<int, GameObject>)fieldInfo.GetValue(db)) : null); if ((Object)(object)instance == (Object)null) { BuildPrefab(db); } if ((Object)(object)instance == (Object)null) { return; } bool flag = RussianUi(); AddWord("item_barrelcopter", flag ? "Бочка-вертолёт" : "Barrel Copter"); AddWord("item_barrelcopter_description", flag ? "Наденьте, чтобы взлететь. Пробел - вверх, Ctrl - вниз, Shift - ускорение. Без урона от падения." : "Equip to take off. Space = up, Ctrl = down, Shift = boost. No fall damage."); if ((Object)(object)FindItem(db, "BarrelCopter") == (Object)null) { db.m_items.Add(instance); if (dictionary != null) { dictionary[StringExtensionMethods.GetStableHashCode("BarrelCopter")] = instance; } } if ((Object)(object)effect != (Object)null && !db.m_StatusEffects.Contains((StatusEffect)(object)effect)) { db.m_StatusEffects.Add((StatusEffect)(object)effect); } AddRecipe(db); } private static void AddRecipe(ObjectDB db) { //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Expected O, but got Unknown for (int i = 0; i < db.m_recipes.Count; i++) { if ((Object)(object)db.m_recipes[i] != (Object)null && ((Object)db.m_recipes[i]).name == "Recipe_BarrelCopter") { return; } } List<Requirement> list = new List<Requirement>(); string[] array = cfgRecipe.Value.Split(','); foreach (string text in array) { string[] array2 = text.Trim().Split(':'); if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result) && result > 0) { GameObject val = FindItem(db, array2[0].Trim()); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)("BarrelCopter: unknown recipe item " + array2[0])); continue; } Requirement val2 = new Requirement(); val2.m_resItem = val.GetComponent<ItemDrop>(); val2.m_amount = result; val2.m_amountPerLevel = 0; val2.m_recover = true; list.Add(val2); } } if (list.Count != 0) { Recipe val3 = ScriptableObject.CreateInstance<Recipe>(); ((Object)val3).name = "Recipe_BarrelCopter"; val3.m_item = instance.GetComponent<ItemDrop>(); val3.m_amount = 1; val3.m_enabled = true; val3.m_craftingStation = null; val3.m_minStationLevel = 1; val3.m_resources = list.ToArray(); db.m_recipes.Add(val3); } } internal static void RegisterInScene(ZNetScene scene) { if ((Object)(object)scene == (Object)null || (Object)(object)instance == (Object)null) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs"); Dictionary<int, GameObject> dictionary = ((fieldInfo != null) ? ((Dictionary<int, GameObject>)fieldInfo.GetValue(scene)) : null); if (dictionary != null) { int stableHashCode = StringExtensionMethods.GetStableHashCode("BarrelCopter"); if (!dictionary.ContainsKey(stableHashCode)) { scene.m_prefabs.Add(instance); dictionary[stableHashCode] = instance; } } } private static Material NewMaterial(Color color) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_00b1: 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_00b0: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown Shader val = Shader.Find("Standard"); Material val2 = null; if ((Object)(object)val != (Object)null) { val2 = new Material(val); } else if ((Object)(object)ObjectDB.instance != (Object)null) { GameObject val3 = FindItem(ObjectDB.instance, "Wood"); MeshRenderer val4 = (((Object)(object)val3 != (Object)null) ? val3.GetComponentInChildren<MeshRenderer>(true) : null); if ((Object)(object)val4 != (Object)null && (Object)(object)((Renderer)val4).sharedMaterial != (Object)null) { val2 = new Material(((Renderer)val4).sharedMaterial); } } if ((Object)(object)val2 == (Object)null) { val2 = new Material(Shader.Find("Sprites/Default")); } val2.color = color; return val2; } private static void BuildMeshes() { //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0151: 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_019b: 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_01be: 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_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: 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_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0360: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) float num = 0.8f; MeshBuilder meshBuilder = new MeshBuilder(); meshBuilder.Tube(0f, num, 20, (float t) => 0.4f + 0.07f * Mathf.Sin((float)Math.PI * t), inside: true); meshBuilder.Disc(0.02f, 0.37f, 20); MeshBuilder meshBuilder2 = new MeshBuilder(); float[] array = new float[4] { 0.08f, 0.3f, 0.52f, 0.74f }; foreach (float num3 in array) { float num4 = (num3 + 0.025f) / num; float r = 0.4f + 0.07f * Mathf.Sin((float)Math.PI * num4) + 0.012f; meshBuilder2.Tube(num3, num3 + 0.05f, 12, (float u) => r, inside: false); } MeshBuilder meshBuilder3 = new MeshBuilder(); float value = cfgRotorHeight.Value; float num5 = 0.4f; Vector3 a = default(Vector3); for (int num2 = 0; num2 < 4; num2++) { float num6 = ((float)num2 * 90f + 45f) * ((float)Math.PI / 180f); ((Vector3)(ref a))..ctor(Mathf.Cos(num6) * num5, num - 0.02f, Mathf.Sin(num6) * num5); meshBuilder3.Beam(a, new Vector3(0f, value - 0.12f, 0f), 0.022f); } meshBuilder3.Box(new Vector3(0f, value - 0.04f, 0f), new Vector3(0.05f, 0.09f, 0.05f), Quaternion.identity); meshBuilder3.Box(new Vector3(0f, num + 0.02f, 0f), new Vector3(0.43f, 0.015f, 0.015f), Quaternion.identity); meshBuilder3.Box(new Vector3(0f, num + 0.02f, 0f), new Vector3(0.015f, 0.015f, 0.43f), Quaternion.identity); bodyMeshes.Add(meshBuilder.ToMesh("BarrelWood")); bodyMats.Add(NewMaterial(new Color(0.45f, 0.28f, 0.13f))); bodyMeshes.Add(meshBuilder2.ToMesh("BarrelIron")); bodyMats.Add(NewMaterial(new Color(0.16f, 0.16f, 0.18f))); bodyMeshes.Add(meshBuilder3.ToMesh("CopterFrame")); bodyMats.Add(NewMaterial(new Color(0.3f, 0.3f, 0.33f))); MeshBuilder meshBuilder4 = new MeshBuilder(); meshBuilder4.Box(Vector3.zero, new Vector3(0.09f, 0.04f, 0.09f), Quaternion.identity); for (int num2 = 0; num2 < 4; num2++) { Quaternion val = Quaternion.Euler(0f, (float)num2 * 90f, 0f); Quaternion val2 = Quaternion.Euler(10f, 0f, 0f); Vector3 center = val * new Vector3(0f, 0f, 1.15f); meshBuilder4.Box(center, new Vector3(0.1f, 0.012f, 1.05f), val * val2); } rotorMesh = meshBuilder4.ToMesh("CopterRotor"); rotorMat = NewMaterial(new Color(0.62f, 0.5f, 0.34f)); } private static AudioClip BuildRotorClip() { if ((Object)(object)rotorClip != (Object)null) { return rotorClip; } float[] array = new float[22050]; Random random = new Random(7); for (int i = 0; i < array.Length; i++) { float num = (float)i / 22050f; float num2 = Mathf.Pow(0.5f + 0.5f * Mathf.Sin((float)Math.PI * 28f * num), 3f); float num3 = Mathf.Sin((float)Math.PI * 112f * num) * 0.5f + Mathf.Sin((float)Math.PI * 224f * num) * 0.25f; float num4 = (float)(random.NextDouble() * 2.0 - 1.0); array[i] = (num3 * 0.7f + num4 * 0.5f) * (0.25f + 0.75f * num2) * 0.6f; } rotorClip = AudioClip.Create("BarrelCopterRotor", array.Length, 1, 22050, false); rotorClip.SetData(array, 0); return rotorClip; } internal static GameObject CreateVisual(Transform parent, bool asItem) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_00b3: 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_00d3: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Expected O, but got Unknown //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Expected O, but got Unknown //IL_018b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)parent == (Object)null) { return null; } try { if (bodyMeshes.Count == 0) { BuildMeshes(); } GameObject val = new GameObject("BarrelCopterVisual"); val.transform.SetParent(parent, false); if (asItem) { val.transform.localPosition = new Vector3(0f, 0.05f, 0f); val.transform.localScale = Vector3.one * 0.22f; } else { val.transform.localPosition = new Vector3(0f, cfgOffsetY.Value, 0f); val.transform.localScale = Vector3.one * cfgScale.Value; } for (int i = 0; i < bodyMeshes.Count; i++) { GameObject val2 = new GameObject("part" + i); val2.transform.SetParent(val.transform, false); val2.AddComponent<MeshFilter>().sharedMesh = bodyMeshes[i]; ((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = bodyMats[i]; } GameObject val3 = new GameObject("Rotor"); val3.transform.SetParent(val.transform, false); val3.transform.localPosition = new Vector3(0f, cfgRotorHeight.Value, 0f); val3.AddComponent<MeshFilter>().sharedMesh = rotorMesh; ((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = rotorMat; return val; } catch (Exception ex) { Debug.LogWarning((object)("BarrelCopter: visual failed: " + ex)); return null; } } } public class CopterSync : MonoBehaviour { internal static readonly int FlagKey = StringExtensionMethods.GetStableHashCode("BC_Copter"); private static readonly FieldInfo fNView = AccessTools.Field(typeof(Character), "m_nview"); private Player player; private GameObject visual; private Transform rotor; private AudioSource src; private float born; private float spin; private float spinSpeed; private Vector3 lastPos; private bool IsLocal => (Object)(object)player != (Object)null && (Object)(object)player == (Object)(object)Player.m_localPlayer; private ZNetView NView => (ZNetView)((fNView != null) ? /*isinst with value type is only supported in some contexts*/: null); private void Awake() { player = ((Component)this).GetComponent<Player>(); born = Time.time; } private void Update() { if ((Object)(object)player == (Object)null) { return; } ZNetView nView = NView; if ((Object)(object)nView == (Object)null || !nView.IsValid()) { return; } ZDO zDO = nView.GetZDO(); if (zDO != null) { if (IsLocal && nView.IsOwner() && zDO.GetBool(FlagKey, false) != BarrelCopterPlugin.SeActive && (BarrelCopterPlugin.SeActive || Time.time - born > 3f)) { zDO.Set(FlagKey, BarrelCopterPlugin.SeActive); } bool flag = zDO.GetBool(FlagKey, false); if (flag && (Object)(object)visual == (Object)null) { Build(); } else if (!flag && (Object)(object)visual != (Object)null) { Teardown(); } if ((Object)(object)visual != (Object)null) { Animate(); } } } private void Build() { //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) visual = BarrelCopterPlugin.CreateVisual(((Component)player).transform, asItem: false); BarrelCopterPlugin.Riders.Add((Character)(object)player); rotor = (((Object)(object)visual != (Object)null) ? visual.transform.Find("Rotor") : null); lastPos = ((Component)player).transform.position; spinSpeed = 0f; if ((Object)(object)visual != (Object)null && BarrelCopterPlugin.cfgVolume.Value > 0f) { src = visual.AddComponent<AudioSource>(); src.clip = BarrelCopterPlugin.RotorClip; src.loop = true; src.playOnAwake = false; src.spatialBlend = (IsLocal ? 0.2f : 1f); src.rolloffMode = (AudioRolloffMode)1; src.minDistance = 5f; src.maxDistance = 55f; src.volume = BarrelCopterPlugin.cfgVolume.Value; src.Play(); } } private void Teardown() { BarrelCopterPlugin.Riders.Remove((Character)(object)player); if ((Object)(object)src != (Object)null) { src.Stop(); Object.Destroy((Object)(object)src); } src = null; if ((Object)(object)visual != (Object)null) { Object.Destroy((Object)(object)visual); } visual = null; rotor = null; } private void Animate() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: 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_0043: 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) Vector3 position = ((Component)player).transform.position; float num; if (!(Time.deltaTime > 0f)) { num = 0f; } else { Vector3 val = position - lastPos; num = ((Vector3)(ref val)).magnitude / Time.deltaTime; } float num2 = num; lastPos = position; float num3 = 360f + Mathf.Clamp(num2, 0f, 25f) * 40f; spinSpeed = Mathf.MoveTowards(spinSpeed, num3, 600f * Time.deltaTime); if ((Object)(object)rotor != (Object)null) { spin = (spin + spinSpeed * Time.deltaTime) % 360f; rotor.localRotation = Quaternion.Euler(0f, spin, 0f); } if ((Object)(object)src != (Object)null) { src.volume = BarrelCopterPlugin.cfgVolume.Value; src.pitch = Mathf.Lerp(0.8f, 1.25f, Mathf.Clamp01(spinSpeed / 1400f)); } } private void OnDestroy() { Teardown(); } } internal static class Patches { private static readonly FieldInfo fBody = BarrelCopterPlugin.fBody; private static readonly FieldInfo fMoveDir = AccessTools.Field(typeof(Character), "m_moveDir"); private static readonly FieldInfo fRun = AccessTools.Field(typeof(Character), "m_run"); private static readonly FieldInfo fVel = AccessTools.Field(typeof(Character), "m_currentVel"); private static readonly FieldInfo fMaxAir = AccessTools.Field(typeof(Character), "m_maxAirAltitude"); private static readonly FieldInfo fLookYaw = AccessTools.Field(typeof(Character), "m_lookYaw"); private static readonly FieldInfo fLastGround = AccessTools.Field(typeof(Character), "m_lastGroundTouch"); private static readonly MethodInfo mEye = AccessTools.Method(typeof(Character), "UpdateEyeRotation", (Type[])null, (Type[])null); private static readonly MethodInfo mTakeInput = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null); [HarmonyPatch(typeof(ObjectDB), "Awake")] [HarmonyPostfix] private static void ObjectDBAwake(ObjectDB __instance) { BarrelCopterPlugin.EnsureItems(__instance); } [HarmonyPostfix] [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] private static void ObjectDBCopy(ObjectDB __instance) { BarrelCopterPlugin.EnsureItems(__instance); } [HarmonyPatch(typeof(ZNetScene), "Awake")] [HarmonyPostfix] private static void ZNetSceneAwake(ZNetScene __instance) { BarrelCopterPlugin.EnsureItems(ObjectDB.instance); BarrelCopterPlugin.RegisterInScene(__instance); } [HarmonyPatch(typeof(Player), "Awake")] [HarmonyPostfix] private static void PlayerAwake(Player __instance) { if ((Object)(object)((Component)__instance).gameObject.GetComponent<CopterSync>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<CopterSync>(); } } [HarmonyPostfix] [HarmonyPatch(typeof(Player), "IsDebugFlying")] private static void IsDebugFlying(Player __instance, ref bool __result) { if (BarrelCopterPlugin.SeActive && (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { __result = true; } } [HarmonyPatch(typeof(Character), "UpdateDebugFly")] [HarmonyPrefix] private static bool UpdateDebugFly(Character __instance, float dt) { //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: 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_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0351: Unknown result type (might be due to invalid IL or missing references) Player val = (Player)(object)((__instance is Player) ? __instance : null); if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer || !BarrelCopterPlugin.SeActive) { return true; } Rigidbody val2 = (Rigidbody)((fBody != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val2 == (Object)null || fMoveDir == null || fVel == null) { return true; } bool flag = true; if (mTakeInput != null) { flag = (bool)mTakeInput.Invoke(val, null); } float num = ((fRun != null && (bool)fRun.GetValue(val)) ? BarrelCopterPlugin.cfgBoostSpeed.Value : BarrelCopterPlugin.cfgFlySpeed.Value); Vector3 val3 = (Vector3)fMoveDir.GetValue(val); Vector3 val4 = new Vector3(val3.x, 0f, val3.z) * num; float value = BarrelCopterPlugin.cfgVertSpeed.Value; bool flag2 = false; bool flag3 = false; if (flag) { flag2 = ZInput.GetButton("Jump"); flag3 = ZInput.GetKey((KeyCode)306, true) || ZInput.GetButton("Crouch"); } float value2 = BarrelCopterPlugin.cfgStamina.Value; bool flag4 = ((Vector3)(ref val4)).sqrMagnitude > 0.01f || flag2; if (value2 > 0f && flag4) { if (((Character)val).HaveStamina(value2 * dt)) { ((Character)val).UseStamina(value2 * dt); } else { flag2 = false; val4 = Vector3.zero; flag3 = true; } } float value3 = BarrelCopterPlugin.cfgMaxHeight.Value; if (value3 > 0f && flag2) { float num2 = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.GetGroundHeight(((Component)val).transform.position) : 0f); if (((Component)val).transform.position.y - num2 >= value3) { flag2 = false; } } if (flag2) { val4.y = value; } else if (flag3) { val4.y = 0f - value; } Vector3 val5 = (Vector3)fVel.GetValue(val); val5 = Vector3.Lerp(val5, val4, 0.12f); fVel.SetValue(val, val5); val2.linearVelocity = val5; val2.useGravity = false; if (fLastGround != null) { fLastGround.SetValue(val, 0f); } if (fMaxAir != null) { fMaxAir.SetValue(val, ((Component)val).transform.position.y); } if (fLookYaw != null) { val2.rotation = Quaternion.RotateTowards(((Component)val).transform.rotation, (Quaternion)fLookYaw.GetValue(val), 100f * dt); } val2.angularVelocity = Vector3.zero; if (mEye != null) { mEye.Invoke(val, null); } return false; } }