Decompiled source of Totally Normal Mod v0.1.20
plugins/TotallyNormalMod/TotallyNormalMod.dll
Decompiled 10 minutes ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UchShulker; using UnityEngine; using UnityEngine.Networking; [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("TotallyNormalMod")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("TotallyNormalMod")] [assembly: AssemblyTitle("TotallyNormalMod")] [assembly: AssemblyVersion("1.0.0.0")] namespace UchShulker { public struct Target { public int PlayerId; public float DistanceTiles; public bool Alive; public bool Visible; } public sealed class Rules { public const float RangeTiles = 7f; private float nextShot; public const float CooldownSeconds = 10f; public const double LevitationSeconds = 7.0; public const float SteeringScale = 0.35f; public bool Open { get; private set; } public static bool CanMount(int baseDirection, int supportOutwardNormal, bool validSupport, bool footprintClear) { if (validSupport && footprintClear && baseDirection >= 0 && baseDirection < 4) { return supportOutwardNormal == (baseDirection + 2) % 4; } return false; } public int? Tick(float now, Target[] players) { Target? target = null; for (int i = 0; i < players.Length; i++) { Target value = players[i]; if (value.Alive && value.Visible && value.DistanceTiles >= 0f && value.DistanceTiles <= 7f && (!target.HasValue || value.DistanceTiles < target.Value.DistanceTiles || (value.DistanceTiles == target.Value.DistanceTiles && value.PlayerId < target.Value.PlayerId))) { target = value; } } if (!target.HasValue) { Open = false; return null; } if (!Open) { nextShot = Math.Max(nextShot, now + 0.45f); } Open = true; if (now < nextShot) { return null; } nextShot = now + 10f; return target.Value.PlayerId; } public void Reset() { Open = false; nextShot = 0f; } public void Close() { Open = false; } public static double HitExpiry(double now) { return now + 7.0; } public static float LiftVelocity(float verticalSpeed, float stepSeconds) { float val = 2f - verticalSpeed; float num = 8f * Math.Max(0f, stepSeconds); return verticalSpeed + Math.Max(0f - num, Math.Min(num, val)); } } } namespace ShulkerMod { internal static class Phys { public static readonly Collider2D[] Buf = (Collider2D[])(object)new Collider2D[64]; public static readonly RaycastHit2D[] Hits = (RaycastHit2D[])(object)new RaycastHit2D[64]; private static ContactFilter2D filter; private static bool ready; private const int ProjectileStopMask = 33554560; private static ContactFilter2D F() { //IL_002b: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (!ready) { filter = new ContactFilter2D { useTriggers = true, useLayerMask = false }; ready = true; } return filter; } public static int Circle(Vector2 p, float r) { //IL_0000: 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) return Physics2D.OverlapCircle(p, r, F(), Buf); } public static int Box(Vector2 p, Vector2 size, float angle) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: 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) return Physics2D.OverlapBox(p, size, angle, F(), Buf); } public static int CircleCast(Vector2 from, float r, Vector2 dir, float dist) { //IL_0000: 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) return Physics2D.CircleCast(from, r, dir, F(), Hits, dist); } public static bool BlocksProjectiles(Collider2D c) { if ((Object)(object)c == (Object)null || c.isTrigger) { return false; } CollisionTag component = ((Component)c).GetComponent<CollisionTag>(); if ((Object)(object)component != (Object)null) { return component.ContainsAnyTag((Tag)33554560); } return false; } } internal static class Interact { private static readonly FieldRef<AnimalCannon, Transform> center = AccessTools.FieldRefAccess<AnimalCannon, Transform>("boosterCenter"); private static readonly Func<ActiveBlock, bool> active = AccessTools.MethodDelegate<Func<ActiveBlock, bool>>(AccessTools.PropertyGetter(typeof(ActiveBlock), "Active"), (object)null, true); public static Vector2 CannonCenter(AnimalCannon cannon) { //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) return Vector2.op_Implicit(center.Invoke(cannon).position); } public static bool CannonActive(AnimalCannon cannon) { if (Object.op_Implicit((Object)(object)cannon)) { return active((ActiveBlock)(object)cannon); } return false; } } public static class FlightTuning { public const float CannonCoastSeconds = 0.45f; public static float CannonSpeed(float cruise) { return 1.65f * Math.Max(0f, cruise); } public static float GravitySpeed(float previous, float current, float cruise) { float num = Math.Max(0f, current - previous); return Math.Min(current - 0.15f * num, Math.Max(0f, 2f * cruise)); } } internal static class Interactions { public const float ImpulseThreshold = 2.5f; private static Blackhole[] holes = (Blackhole[])(object)new Blackhole[0]; private static float nextRefresh; private static readonly FieldRef<Blackhole, List<Character>> sucking = AccessTools.FieldRefAccess<Blackhole, List<Character>>("currentlySucking"); public static bool BeingSucked(Character ch) { if (Time.time >= nextRefresh) { holes = Object.FindObjectsOfType<Blackhole>(); nextRefresh = Time.time + 0.25f; } Blackhole[] array = holes; foreach (Blackhole val in array) { if (!((Object)(object)val == (Object)null)) { List<Character> list = sucking.Invoke(val); if (list != null && list.Contains(ch)) { return true; } } } return false; } } [HarmonyPatch(typeof(InventoryPage), "displayContent")] internal static class InventoryBookShulker { private static void Prefix(InventoryPage __instance, bool __0) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012d: 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_0137: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_022e: 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_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) if (!__0 || (int)__instance.pageType < 3 || (int)__instance.pageType > 11) { return; } PickableBlock[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<PickableBlock>(true); if (componentsInChildren.Any((PickableBlock p) => Object.op_Implicit((Object)(object)p.placeablePrefab) && p.placeablePrefab.Name == "Shulker")) { return; } PickableBlock val = ((IEnumerable<PickableBlock>)componentsInChildren).FirstOrDefault((Func<PickableBlock, bool>)((PickableBlock p) => Object.op_Implicit((Object)(object)p.placeablePrefab) && p.placeablePrefab.Name == "Crossbow")); PlaceableMetadataList instance = PlaceableMetadataList.Instance; if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)instance) || instance.allBlockPrefabs == null) { return; } GameObject val2 = ((IEnumerable<GameObject>)instance.allBlockPrefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => Object.op_Implicit((Object)(object)p) && ((Object)p).name == "Shulker")); if (Object.op_Implicit((Object)(object)val2)) { Transform transform = ((Component)val).transform; Transform parent = transform.parent; Vector3 localPosition = transform.localPosition; float x = transform.localScale.x; BoxCollider2D val3 = val.PickColliders?.OfType<BoxCollider2D>().FirstOrDefault(); float num = Mathf.Max(Object.op_Implicit((Object)(object)val3) ? Mathf.Abs(parent.InverseTransformVector(((Component)val3).transform.TransformVector(Vector3.right * val3.size.x)).x) : Mathf.Abs(x), Mathf.Abs(x)) * 0.25f; PickableBlock val4 = Object.Instantiate<PickableBlock>(val2.GetComponent<Placeable>().PickableBlock, parent, false); val4.NetworkFindPartyBox = false; val4.NetworkInPartybox = false; val4.NetworkInLobby = val.NetworkInLobby; val4.NetworkVisible = val.NetworkVisible; Transform[] componentsInChildren2 = ((Component)val4).GetComponentsInChildren<Transform>(true); for (int num2 = 0; num2 < componentsInChildren2.Length; num2++) { ((Component)componentsInChildren2[num2]).gameObject.layer = ((Component)val).gameObject.layer; } ((Component)val4).transform.localRotation = transform.localRotation; ((Component)val4).transform.localPosition = localPosition + Vector3.right * num; ((Component)val4).gameObject.SetActive(true); val4.setInitialScale(x * 0.47f); val.setInitialScale(x * 0.47f); transform.localPosition = localPosition - Vector3.right * num; __instance.AddInstantiatedElements(((Component)val4).transform); Plugin.Log.LogInfo((object)("Added Shulker beside Crossbow on " + ((object)Unsafe.As<PageTypes, PageTypes>(ref __instance.pageType)/*cast due to .constrained prefix*/).ToString())); } } } internal static class Levitation { private class State { public double expiry; public float vx; public float vy; public float savedLeft; public float savedRight; public float savedGravityMult; public float particleTimer; public bool suspended; public Rigidbody2D rb; } private static readonly Dictionary<Character, State> active = new Dictionary<Character, State>(); private const float MaxSideSpeedTiles = 2.2f; private const float SideAccelTiles = 2.5f; private const float SideDriftDecayTiles = 0.5f; private const float StartLiftTiles = 1f; private const float JumpCapTiles = 3f; private static readonly FieldRef<Character, float> leftIn = AccessTools.FieldRefAccess<Character, float>("leftInput"); private static readonly FieldRef<Character, float> rightIn = AccessTools.FieldRefAccess<Character, float>("rightInput"); private static readonly FieldRef<Character, float> gravMult = AccessTools.FieldRefAccess<Character, float>("forcedGravityMultiplier"); private static readonly FieldRef<Character, float> holeX = AccessTools.FieldRefAccess<Character, float>("blackHoleX"); private static readonly FieldRef<Character, float> holeY = AccessTools.FieldRefAccess<Character, float>("blackholeY"); private static readonly FieldRef<Character, CharacterRaycaster> feet = AccessTools.FieldRefAccess<Character, CharacterRaycaster>("Feet"); private static readonly FieldRef<CharacterRaycaster, bool> raysOn = AccessTools.FieldRefAccess<CharacterRaycaster, bool>("raycastEnabled"); private static readonly Func<Character, bool> affectedByImpulse = AccessTools.MethodDelegate<Func<Character, bool>>(AccessTools.PropertyGetter(typeof(Character), "AffectedByImpulse"), (object)null, true); public static void Apply(Character ch) { //IL_0064: 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) double timeAsDouble = Time.timeAsDouble; double num = Rules.HitExpiry(timeAsDouble); if (active.TryGetValue(ch, out var value)) { if (num > value.expiry) { value.expiry = num; } return; } Rigidbody2D component = ((Component)ch).GetComponent<Rigidbody2D>(); float value2 = Plugin.BlockSize.Value; value = new State { expiry = num, rb = component, vx = (Object.op_Implicit((Object)(object)component) ? (component.velocity.x * 0.3f) : 0f), vy = Mathf.Max(Object.op_Implicit((Object)(object)component) ? component.velocity.y : 0f, 1f * value2), savedGravityMult = gravMult.Invoke(ch) }; active[ch] = value; if (Controls(ch)) { ch.ForceGravity((GravityType)0); ch.SetForcedGravityMultiplier(0f); } Plugin.Log.LogInfo((object)$"Levitating player {Characters.Id(ch)} for {num - timeAsDouble:0.0}s"); } public static void Clear() { foreach (KeyValuePair<Character, State> item in active) { if (Object.op_Implicit((Object)(object)item.Key)) { End(item.Key, item.Value); } } active.Clear(); } public static bool IsLevitating(Character ch) { if ((Object)(object)ch != (Object)null) { return active.ContainsKey(ch); } return false; } private static void End(Character ch, State s) { if (Controls(ch)) { SetFeetRays(ch, on: true); ch.RemoveForcedGravity(); ch.SetForcedGravityMultiplier(s.savedGravityMult); } } private static bool Expired(Character ch, State s) { if (Time.timeAsDouble < s.expiry && !Characters.IsDead(ch)) { return false; } End(ch, s); active.Remove(ch); return true; } internal static void BeforeMove(Character ch) { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) if (active.TryGetValue(ch, out var value) && !Expired(ch, value) && Controls(ch) && !((Object)(object)value.rb == (Object)null)) { if (Interactions.BeingSucked(ch)) { value.suspended = true; SetFeetRays(ch, on: true); return; } value.suspended = false; value.savedLeft = leftIn.Invoke(ch); value.savedRight = rightIn.Invoke(ch); leftIn.Invoke(ch) = 0f; rightIn.Invoke(ch) = 0f; SetFeetRays(ch, value.vy <= 0f); value.rb.velocity = new Vector2(value.vx, value.vy); } } internal static void AfterMove(Character ch) { //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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0101: 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_009c: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) if (!active.TryGetValue(ch, out var value)) { return; } float fixedDeltaTime = Time.fixedDeltaTime; value.particleTimer -= fixedDeltaTime; if (value.particleTimer <= 0f) { value.particleTimer = 0.15f; ShulkerParticle.Spawn(((Component)ch).transform.position + Vector2.op_Implicit(Random.insideUnitCircle * 0.4f), "Default", 0.6f, 0.2f); } if (!Controls(ch) || (Object)(object)value.rb == (Object)null) { return; } if (value.suspended) { value.vx = value.rb.velocity.x; value.vy = Mathf.Max(0f, value.rb.velocity.y); return; } leftIn.Invoke(ch) = value.savedLeft; rightIn.Invoke(ch) = value.savedRight; float value2 = Plugin.BlockSize.Value; Vector2 velocity = value.rb.velocity; if (Mathf.Abs(holeX.Invoke(ch)) > 0.0001f || Mathf.Abs(holeY.Invoke(ch)) > 0.0001f) { value.vx = velocity.x; value.vy = Rules.LiftVelocity(velocity.y / value2, fixedDeltaTime) * value2; return; } float num = value.vy; if (velocity.y > value.vy + 0.5f * value2) { num = (affectedByImpulse(ch) ? velocity.y : Mathf.Min(velocity.y, Mathf.Max(value.vy, 3f * value2))); } else if (velocity.y < value.vy - 0.5f * value2) { num = Mathf.Max(velocity.y, 0f); } value.vy = Rules.LiftVelocity(num / value2, fixedDeltaTime) * value2; float num2 = Mathf.Clamp(value.savedRight - value.savedLeft, -1f, 1f); float vx = ((Mathf.Abs(num2) > 0.1f) ? Mathf.MoveTowards(value.vx, num2 * 2.2f * value2, 2.5f * value2 * fixedDeltaTime) : Mathf.MoveTowards(value.vx, 0f, 0.5f * value2 * fixedDeltaTime)); if (Mathf.Abs(velocity.x - value.vx) > 10f * value2) { vx = velocity.x; } else if (Mathf.Abs(velocity.x) < 0.01f && Mathf.Abs(value.vx) > 0.05f) { vx = 0f; } value.vx = vx; } private static void SetFeetRays(Character ch, bool on) { CharacterRaycaster val = feet.Invoke(ch); if ((Object)(object)val != (Object)null) { raysOn.Invoke(val) = on; } } private static bool Controls(Character ch) { if (!((NetworkBehaviour)ch).hasAuthority) { return ((NetworkBehaviour)ch).isLocalPlayer; } return true; } } [HarmonyPatch(typeof(Character), "fullUpdate")] internal static class CharacterMovePatch { private static void Prefix(Character __instance) { Levitation.BeforeMove(__instance); } private static void Postfix(Character __instance) { Levitation.AfterMove(__instance); } } [HarmonyPatch(typeof(AnimalCannon), "OnProjectileEnterTrigger")] internal static class NativeIntake { private static void Postfix(AnimalCannon __instance, Collider2D __0) { ShulkerBullet shulkerBullet = default(ShulkerBullet); if (Object.op_Implicit((Object)(object)__0) && ((Component)__0).TryGetComponent<ShulkerBullet>(ref shulkerBullet) && Interact.CannonActive(__instance)) { shulkerBullet.Loaded(__instance); } } } [HarmonyPatch(typeof(AnimalCannon), "ShootProjectile")] internal static class NativeLaunch { private static void Postfix(AnimalCannon __instance, Projectile __0) { if (__0 is ShulkerBullet shulkerBullet) { shulkerBullet.Fired(__instance); } } } [HarmonyPatch(typeof(PartyBox), "ChoosePieces")] internal static class PartyBoxRules { private static readonly Action<PartyBox> RefreshWeights = Bind("InitializeWeightedBlockList"); private static readonly Action<PartyBox> RefreshVariants = Bind("InitializeFilteredVariantList"); private static readonly Action<PartyBox> RefreshExtras = Bind("InitializeFilteredBombsAndCoins"); private static Action<PartyBox> Bind(string method) { return AccessTools.MethodDelegate<Action<PartyBox>>(AccessTools.Method(typeof(PartyBox), method, (Type[])null, (Type[])null), (object)null, true); } private static void Prefix(PartyBox __instance) { RefreshWeights(__instance); RefreshVariants(__instance); RefreshExtras(__instance); } private static void Postfix(List<PickableBlock> ___pieces, WeightedBlockList ___currentBlockWeights) { GameObject val = Array.Find(PlaceableMetadataList.Instance.allBlockPrefabs, (GameObject go) => Object.op_Implicit((Object)(object)go) && ((Object)go).name == "Shulker"); if (Object.op_Implicit((Object)(object)val) && ___currentBlockWeights != null) { Placeable block = val.GetComponent<Placeable>(); int count = ___pieces.FindAll((PickableBlock pick) => Object.op_Implicit((Object)(object)pick) && (Object)(object)pick.placeablePrefab == (Object)(object)block).Count; Plugin.Log.LogInfo((object)$"Party box: Shulker draw weight {___currentBlockWeights.GetWeightForPlaceable(block)}, selected {count} of {___pieces.Count} pieces."); } } } [HarmonyPatch(typeof(Placeable), "ToPlayMode")] internal static class ShulkerPlayPatch { private static void Postfix(Placeable __instance) { ShulkerBrain component = ((Component)__instance).GetComponent<ShulkerBrain>(); if (Object.op_Implicit((Object)(object)component)) { component.OnPlayStart(); component.Paused = false; } } } [HarmonyPatch(typeof(Projectile), "OnTriggerEnter2D")] internal static class ProjectileHitsShulkerPatch { private static readonly FieldRef<Projectile, bool> collided = AccessTools.FieldRefAccess<Projectile, bool>("collided"); private static readonly FieldRef<Projectile, GameObject> hitObject = AccessTools.FieldRefAccess<Projectile, GameObject>("collidedWithObject"); private static readonly FieldRef<Projectile, int> number = AccessTools.FieldRefAccess<Projectile, int>("projectileNumber"); private static void Postfix(Projectile __instance, Collider2D c) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)c == (Object)null) && collided.Invoke(__instance) && !((Object)(object)hitObject.Invoke(__instance) != (Object)(object)((Component)c).gameObject)) { ShulkerBrain componentInParent = ((Component)c).GetComponentInParent<ShulkerBrain>(); if (Object.op_Implicit((Object)(object)componentInParent)) { componentInParent.OnShot(((Object)__instance).GetInstanceID(), number.Invoke(__instance)); } } } } [HarmonyPatch(typeof(HockeyShooter), "ShowProjectileTrigger")] internal static class PuckHitsShulkerPatch { private static void Postfix(HockeyShooter __instance, Vector3 impactPosition) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) Collider2D[] array = Physics2D.OverlapCircleAll(Vector2.op_Implicit(impactPosition), 0.08f); foreach (Collider2D val in array) { if (!((Object)(object)val == (Object)null) && !val.isTrigger) { ShulkerBrain componentInParent = ((Component)val).GetComponentInParent<ShulkerBrain>(); if (Object.op_Implicit((Object)(object)componentInParent)) { int projectileNumber = (Mathf.RoundToInt(impactPosition.x * 37f) * 92821) ^ Mathf.RoundToInt(impactPosition.y * 37f); componentInParent.OnShot(Time.frameCount ^ ((Object)__instance).GetInstanceID(), projectileNumber); break; } } } } } [HarmonyPatch(typeof(Placeable), "ToPlaceMode")] internal static class ShulkerPlacePatch { private static void Postfix(Placeable __instance) { ShulkerBrain component = ((Component)__instance).GetComponent<ShulkerBrain>(); if (Object.op_Implicit((Object)(object)component)) { component.Paused = true; component.ResetState(); Levitation.Clear(); } } } [HarmonyPatch(typeof(PlaceableMetadataList), "Awake")] internal static class ProbePatch { private static void Postfix(PlaceableMetadataList __instance) { //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: 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_02b0: 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_0257: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.WriteProbe.Value) { return; } try { StringBuilder stringBuilder = new StringBuilder(); GameObject[] array = (GameObject[])(((object)__instance.allBlockPrefabs) ?? ((object)new GameObject[0])); stringBuilder.AppendLine($"allBlockPrefabs: {array.Length}"); for (int i = 0; i < array.Length; i++) { GameObject val = array[i]; if ((Object)(object)val == (Object)null) { stringBuilder.AppendLine($"[{i}] null"); continue; } Placeable component = val.GetComponent<Placeable>(); stringBuilder.Append($"[{i}] {((Object)val).name}"); if ((Object)(object)component != (Object)null) { stringBuilder.Append($" | {((object)component).GetType().Name} name={component.Name} cat={component.Category} tag={component.placeableTag} orient={component.Orientation} rarity={component.BaseRarity}"); foreach (CheckColliding item in from c in val.GetComponentsInChildren<CheckColliding>(true) where c.Required || c.AntiRequired || c.ReverseAttach select c) { stringBuilder.Append($"\n check '{((Object)item).name}' req={item.Required} anti={item.AntiRequired} rev={item.ReverseAttach} mask={item.checkTagMask} pos={((Component)item).transform.localPosition}"); } if (component.PlacementGuides != null) { foreach (SpriteRenderer item2 in component.PlacementGuides.Where((SpriteRenderer g) => (Object)(object)g != (Object)null)) { stringBuilder.Append(string.Format("\n guide '{0}' sprite={1} pos={2}", ((Object)item2).name, Object.op_Implicit((Object)(object)item2.sprite) ? ((Object)item2.sprite).name : "none", ((Component)item2).transform.localPosition)); } } Collider2D componentInChildren = val.GetComponentInChildren<Collider2D>(true); if ((Object)(object)componentInChildren != (Object)null) { string name = ((object)componentInChildren).GetType().Name; Bounds bounds = componentInChildren.bounds; stringBuilder.Append($"\n collider {name} size={((Bounds)(ref bounds)).size}"); } } stringBuilder.AppendLine(); } string text = Path.Combine(Plugin.PluginDir, "probe.txt"); File.WriteAllText(text, stringBuilder.ToString()); Plugin.Log.LogInfo((object)("Probe written: " + text)); } catch (Exception ex) { Plugin.Log.LogError((object)("Probe failed: " + ex)); } } } internal static class PlacementRule { private const float FootY = -0.55f; private const float FootWidth = 0.7f; private const float FootHeight = 0.12f; public static bool AddFootSensor(GameObject shulker, Placeable p, GameObject[] prefabs) { //IL_00b7: 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_019d: Unknown result type (might be due to invalid IL or missing references) foreach (CheckColliding item in from c in shulker.GetComponentsInChildren<CheckColliding>(true) where c.Required select c) { item.Required = false; } var (val, val2) = FindTemplate(prefabs); if ((Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)"No stock 'required' placement sensor found. See probe.txt."); return false; } GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, shulker.transform); ((Object)val3).name = "ShulkerFootSensor"; val3.transform.localPosition = new Vector3(0f, -0.75f, 0f); val3.transform.localRotation = Quaternion.identity; CheckColliding component = val3.GetComponent<CheckColliding>(); if (!Object.op_Implicit((Object)(object)val3.GetComponent<CollisionTag>()) || !Object.op_Implicit((Object)(object)val3.GetComponent<Collider2D>())) { return false; } component.Required = true; component.AntiRequired = false; component.ReverseAttach = false; FieldInfo fieldInfo = AccessTools.Field(typeof(Placeable), "PlacementCollidersNew"); List<CheckColliding> list = ((List<CheckColliding>)fieldInfo.GetValue(p)) ?? new List<CheckColliding>(); if (!list.Contains(component)) { list.Add(component); } fieldInfo.SetValue(p, list); p.AllColliderControls = p.AllColliderControls ?? new List<ColliderModeControl>(); if (!p.AllColliderControls.Contains((ColliderModeControl)(object)component)) { p.AllColliderControls.Add((ColliderModeControl)(object)component); } AddArrow(shulker, p, val, val2); Plugin.Log.LogInfo((object)$"Foot sensor copied from '{((Object)val).name}/{((Object)val2).name}' mask={component.checkTagMask}"); return true; } private static (Placeable, CheckColliding) FindTemplate(GameObject[] prefabs) { List<(Placeable, CheckColliding, bool)> list = new List<(Placeable, CheckColliding, bool)>(); foreach (GameObject val in prefabs) { if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ProjectileLauncher>() != (Object)null) { continue; } Placeable component = val.GetComponent<Placeable>(); if ((Object)(object)component == (Object)null) { continue; } CheckColliding[] componentsInChildren = val.GetComponentsInChildren<CheckColliding>(true); foreach (CheckColliding val2 in componentsInChildren) { if (val2.Required && (Object)(object)((Component)val2).gameObject != (Object)(object)val) { list.Add((component, val2, component.PlacementGuides != null && component.PlacementGuides.Any((SpriteRenderer g) => (Object)(object)g != (Object)null))); } } } (Placeable, CheckColliding, bool) tuple = (from x in list orderby x.Item1.Name == "Ice" && x.Item3 descending, x.Item3 descending select x).FirstOrDefault(); return (tuple.Item1, tuple.Item2); } private static void AddArrow(GameObject shulker, Placeable p, Placeable srcPlaceable, CheckColliding srcCheck) { //IL_0067: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0125: 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_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: 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_01b3: 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_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) List<SpriteRenderer> list = srcPlaceable.PlacementGuides?.Where((SpriteRenderer g) => (Object)(object)g != (Object)null).ToList(); if (list == null || list.Count == 0) { return; } Vector3 srcFoot = ((Component)srcPlaceable).transform.InverseTransformPoint(((Component)srcCheck).transform.position); SpriteRenderer val = list.OrderBy(delegate(SpriteRenderer g) { //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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) Vector3 val6 = ((Component)srcPlaceable).transform.InverseTransformPoint(((Component)g).transform.position) - srcFoot; return ((Vector3)(ref val6)).sqrMagnitude; }).First(); GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, shulker.transform); ((Object)val2).name = "ShulkerFootArrow"; Component[] componentsInChildren = val2.GetComponentsInChildren<Component>(true); foreach (Component val3 in componentsInChildren) { if (!(val3 is Transform) && !(val3 is SpriteRenderer)) { Object.DestroyImmediate((Object)(object)val3); } } float num2 = Mathf.Atan2(srcFoot.y, srcFoot.x) * 57.29578f; Quaternion val4 = Quaternion.Inverse(((Component)srcPlaceable).transform.rotation) * ((Component)val).transform.rotation; float z = ((Quaternion)(ref val4)).eulerAngles.z; val2.transform.localRotation = Quaternion.Euler(0f, 0f, z + (-90f - num2)); val2.transform.localPosition = new Vector3(0f, -0.5f, 0f); SpriteRenderer component = val2.GetComponent<SpriteRenderer>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sprite)) { Bounds bounds = component.sprite.bounds; Vector3 val5 = Vector3.Scale(((Bounds)(ref bounds)).center, val2.transform.localScale); val2.transform.localPosition = new Vector3(0f, -0.85f, 0f) - val2.transform.localRotation * val5; p.PlacementGuides = ((IEnumerable<SpriteRenderer>)(((object)p.PlacementGuides) ?? ((object)new SpriteRenderer[0]))).Concat((IEnumerable<SpriteRenderer>)(object)new SpriteRenderer[1] { component }).ToArray(); } } } [BepInPlugin("uch.shulkermod", "Totally Normal Mod", "0.1.20")] public class Plugin : BaseUnityPlugin { public const string Guid = "uch.shulkermod"; public const string Version = "0.1.20"; internal static ManualLogSource Log; internal static string PluginDir; internal static ConfigEntry<float> BlockSize; internal static ConfigEntry<float> BulletSpeed; internal static ConfigEntry<float> BulletTurnRate; internal static ConfigEntry<float> BulletLifetime; internal static ConfigEntry<bool> BulletHoming; internal static ConfigEntry<float> SoundVolume; internal static ConfigEntry<bool> WriteProbe; private void Awake() { //IL_012d: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; PluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); BlockSize = ((BaseUnityPlugin)this).Config.Bind<float>("World", "BlockSizeUnits", 1f, "World units per grid tile. Only change if probe.txt shows blocks are not 1 unit."); BulletSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Shooting", "BulletSpeed", 4f, "Bullet speed (units/s)."); BulletTurnRate = ((BaseUnityPlugin)this).Config.Bind<float>("Shooting", "BulletTurnRateDegrees", 120f, "How fast a homing bullet turns (deg/s)."); BulletLifetime = ((BaseUnityPlugin)this).Config.Bind<float>("Shooting", "BulletLifetime", 8f, "Seconds before a bullet pops by itself."); BulletHoming = ((BaseUnityPlugin)this).Config.Bind<bool>("Shooting", "BulletHoming", true, "Bullets curve toward their target like Minecraft."); WriteProbe = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "WriteProbe", true, "Write probe.txt (every block prefab, its placement checkers and size) next to the DLL."); SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "Volume", 0.8f, "0..1 volume for files in art\\sounds."); ShulkerArt.Load(PluginDir); Sounds.Load(PluginDir); new Harmony("uch.shulkermod").PatchAll(typeof(Plugin).Assembly); Log.LogInfo((object)"Totally Normal Mod 0.1.20 loaded"); } } [HarmonyPatch(typeof(TabletBlockList), "Initialize")] internal static class ProbabilityMenu { private static void Prefix(TabletBlockList __instance) { TabletBlock[] tabletBlocks = __instance.tabletBlocks; PlaceableMetadataList instance = PlaceableMetadataList.Instance; if (!Object.op_Implicit((Object)(object)instance) || tabletBlocks == null || tabletBlocks.Length == 0) { return; } GameObject val = Array.Find(instance.allBlockPrefabs, (GameObject obj) => Object.op_Implicit((Object)(object)obj) && ((Object)obj).name == "Shulker"); if (!Object.op_Implicit((Object)(object)val)) { return; } PickableBlock pick = val.GetComponent<Placeable>().PickableBlock; if (!Object.op_Implicit((Object)(object)pick) || Array.Exists(tabletBlocks, (TabletBlock b) => Object.op_Implicit((Object)(object)b) && (Object)(object)b.pickableBlockPrefab == (Object)(object)pick)) { return; } int num = Array.FindIndex(tabletBlocks, (TabletBlock b) => Object.op_Implicit((Object)(object)b) && Object.op_Implicit((Object)(object)b.pickableBlockPrefab) && b.pickableBlockPrefab.placeablePrefab.Name == "Crossbow"); if (num < 0) { num = Array.FindLastIndex(tabletBlocks, (TabletBlock b) => Object.op_Implicit((Object)(object)b) && Object.op_Implicit((Object)(object)b.overlays)); } if (num < 0) { return; } TabletBlock val2 = tabletBlocks[num]; RectTransform overlays = val2.overlays; Transform parent = ((Transform)overlays).parent; int siblingIndex = ((Transform)overlays).GetSiblingIndex(); bool flag = !((Transform)overlays).IsChildOf(((Component)val2).transform); TabletBlock val3; try { if (flag) { ((Transform)overlays).SetParent(((Component)val2).transform, false); } val3 = Object.Instantiate<TabletBlock>(val2, ((Component)val2).transform.parent, false); } finally { if (flag) { ((Transform)overlays).SetParent(parent, false); ((Transform)overlays).SetSiblingIndex(siblingIndex); } } if (flag) { ((Transform)val3.overlays).SetParent(parent, false); } ((Object)val3).name = "ShulkerProbability"; val3.tabletBlockList = __instance; val3.displayedInList = true; val3.InitializeSprites(pick, (Material)null); List<TabletBlock> list = new List<TabletBlock>(tabletBlocks); list.Insert(num + 1, val3); __instance.tabletBlocks = list.ToArray(); Plugin.Log.LogInfo((object)"Added Shulker to the Block Probability menu."); } private static void Postfix(TabletBlockList __instance) { TabletBlock val = Array.Find(__instance.tabletBlocks, (TabletBlock b) => Object.op_Implicit((Object)(object)b) && ((Object)b).name == "ShulkerProbability"); if (!Object.op_Implicit((Object)(object)val)) { return; } int blockSerializeIndex = val.pickableBlockPrefab.blockSerializeIndex; if (blockSerializeIndex >= 0) { if (__instance.tabletBlocksByIndex.Length <= blockSerializeIndex) { Array.Resize(ref __instance.tabletBlocksByIndex, blockSerializeIndex + 1); } __instance.tabletBlocksByIndex[blockSerializeIndex] = val; __instance.ReorderList(); } } } [HarmonyPatch(typeof(PlaceableMetadataList), "Awake")] internal static class Registration { public const string BlockName = "Shulker"; private static bool done; [HarmonyPriority(200)] private static void Postfix(PlaceableMetadataList __instance) { if (done || (Object)(object)PlaceableMetadataList.Instance != (Object)(object)__instance) { return; } try { Register(__instance); done = true; } catch (Exception ex) { Plugin.Log.LogError((object)("Shulker registration failed: " + ex)); } } private static void Register(PlaceableMetadataList list) { //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) GameObject[] allBlockPrefabs = list.allBlockPrefabs; ProjectileLauncher? obj = (from o in allBlockPrefabs where Object.op_Implicit((Object)(object)o) select o.GetComponent<ProjectileLauncher>()).FirstOrDefault((Func<ProjectileLauncher, bool>)((ProjectileLauncher p) => Object.op_Implicit((Object)(object)p) && ((Placeable)p).Name == "Crossbow" && Object.op_Implicit((Object)(object)p.Ammo))); if (!Object.op_Implicit((Object)(object)obj)) { throw new InvalidOperationException("Crossbow projectile physics layer unavailable"); } ShulkerBullet.PhysicsLayer = ((Component)obj.Ammo).gameObject.layer; if (allBlockPrefabs.Any((GameObject p) => (Object)(object)p != (Object)null && p.GetComponent<Placeable>()?.Name == "Shulker")) { return; } GameObject val = ((IEnumerable<GameObject>)allBlockPrefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject val6) => Object.op_Implicit((Object)(object)val6) && val6.GetComponent<Placeable>()?.Name == "Block")); if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("One-cell block prefab unavailable."); } GameObject val2 = new GameObject("ShulkerModPrefabs"); val2.SetActive(false); Object.DontDestroyOnLoad((Object)(object)val2); GameObject val3 = Object.Instantiate<GameObject>(val, val2.transform); ((Object)val3).name = "Shulker"; int num = allBlockPrefabs.Length; Placeable component = val3.GetComponent<Placeable>(); component.Name = "Shulker"; ShulkerBrain.BlockScale = val3.transform.localScale; component.AttachesToParent = true; component.InventoryInstance = component; component.Category = (PieceCategory)1; component.Orientation = (OrientMode)0; component.BaseRarity = (Rarity)1000; component.FilterOverride = (Placeable[])(object)new Placeable[0]; PlaceableMetadata component2 = val3.GetComponent<PlaceableMetadata>(); if ((Object)(object)component2 != (Object)null) { component2.blockSerializeIndex = num; component2.placeableRef = component; } ShulkerArt.WorldStyle = ((IEnumerable<SpriteRenderer>)val3.GetComponentsInChildren<SpriteRenderer>(true)).FirstOrDefault((Func<SpriteRenderer, bool>)((SpriteRenderer r) => (Object)(object)r.sprite != (Object)null)); SpriteRenderer[] componentsInChildren = val3.GetComponentsInChildren<SpriteRenderer>(true); foreach (SpriteRenderer obj2 in componentsInChildren) { ((Renderer)obj2).enabled = false; obj2.sprite = null; } Animator componentInChildren = val3.GetComponentInChildren<Animator>(true); if (Object.op_Implicit((Object)(object)componentInChildren)) { ((Behaviour)componentInChildren).enabled = false; } SpriteRenderer[] artSprites = ShulkerBrain.EnsureVisuals(val3.transform, component); component.ArtSprites = artSprites; val3.AddComponent<ShulkerBrain>(); if (!PlacementRule.AddFootSensor(val3, component, allBlockPrefabs)) { Object.Destroy((Object)(object)val2); Plugin.Log.LogError((object)"Shulker NOT registered: no stock attach sensor to copy (see probe.txt)."); return; } if ((Object)(object)component.PickableBlock != (Object)null) { PickableBlock component3 = Object.Instantiate<GameObject>(((Component)component.PickableBlock).gameObject, val2.transform).GetComponent<PickableBlock>(); ((Object)component3).name = "ShulkerPickable"; component3.placeablePrefab = component; SetSerializeIndex(component3, num); Animator[] componentsInChildren2 = ((Component)component3).GetComponentsInChildren<Animator>(true); for (int num2 = 0; num2 < componentsInChildren2.Length; num2++) { ((Behaviour)componentsInChildren2[num2]).enabled = false; } componentsInChildren = ((Component)component3).GetComponentsInChildren<SpriteRenderer>(true); foreach (SpriteRenderer val4 in componentsInChildren) { if ((Object)(object)val4 != (Object)(object)component3.crossOut && (Object)(object)val4 != (Object)(object)component3.twitchLogo) { ((Renderer)val4).enabled = false; val4.sprite = null; } } Transform art = (((Object)(object)component3.ArtHolderTransform != (Object)null) ? component3.ArtHolderTransform : ((Component)component3).transform); SpriteRenderer val5 = component3.ArtSprites?.FirstOrDefault((Func<SpriteRenderer, bool>)((SpriteRenderer s) => (Object)(object)s != (Object)null)); component3.ArtSprites = ShulkerBoxPreview.Create(component3, art, val5, ShulkerArt.Pupils); componentsInChildren = component3.ArtSprites; for (int num2 = 0; num2 < componentsInChildren.Length; num2++) { ShulkerArt.MatchStyle(componentsInChildren[num2], val5); } component.PickableBlock = component3; GiveUniqueAssetId(((Component)component3).gameObject, "uch.shulkermod/pickable"); } GiveUniqueAssetId(val3, "uch.shulkermod/placeable"); list.allBlockPrefabs = allBlockPrefabs.Concat((IEnumerable<GameObject>)(object)new GameObject[1] { val3 }).ToArray(); AccessTools.Field(typeof(PlaceableMetadataList), "cachedBlockMap").SetValue(list, null); AccessTools.Field(typeof(PlaceableMetadataList), "nameToIndexMap").SetValue(list, null); Plugin.Log.LogInfo((object)string.Format("Registered '{0}' at index {1} (cloned from '{2}')", "Shulker", num, ((Object)val).name)); } private static void SetSerializeIndex(PickableBlock pick, int index) { AccessTools.Field(typeof(PickableBlock), "blockSerializeIndex")?.SetValue(pick, index); } private static void GiveUniqueAssetId(GameObject go, string key) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) NetworkIdentity component = go.GetComponent<NetworkIdentity>(); if (!((Object)(object)component == (Object)null)) { string text = string.Concat(from b in MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(key)) select b.ToString("x2")); typeof(NetworkIdentity).GetField("m_AssetId", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(component, NetworkHash128.Parse(text)); Plugin.Log.LogInfo((object)(((Object)go).name + " asset id = " + text)); } } } internal static class ShulkerArt { private enum PlaceholderPart { Base, Lid, Head, Bullet } public static Sprite ShellBase; public static Sprite ShellLid; public static Sprite Head; public static Sprite Pupils; public static Sprite[] BulletFrames; public static Sprite[] TrailFrames; public static SpriteRenderer WorldStyle; public static float BaseInset { get; private set; } public static Sprite Bullet => BulletFrames[0]; public static void MatchStyle(SpriteRenderer sr, SpriteRenderer like) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)sr == (Object)null) && !((Object)(object)like == (Object)null)) { if ((Object)(object)((Renderer)like).sharedMaterial != (Object)null) { ((Renderer)sr).sharedMaterial = ((Renderer)like).sharedMaterial; } ((Component)sr).gameObject.layer = ((Component)like).gameObject.layer; sr.maskInteraction = like.maskInteraction; sr.color = Color.white; } } public static void Load(string pluginDir) { //IL_0223: Unknown result type (might be due to invalid IL or missing references) string text = Path.Combine(pluginDir, "art"); Texture2D val = LoadTex(text, "shell_base.png"); float num = (((Object)(object)val != (Object)null) ? ((float)((Texture)val).width) : 16f); val = val ?? Placeholder(PlaceholderPart.Base); Color32[] pixels = val.GetPixels32(); int num2 = ((Texture)val).width / 2; int i; for (i = 0; i < ((Texture)val).height && pixels[i * ((Texture)val).width + num2].a < 128; i++) { } BaseInset = ((i < ((Texture)val).height) ? ((float)i / num) : 0f); ShellBase = ShellSprite(val, num); ShellLid = ShellSprite(LoadTex(text, "shell_lid.png") ?? Placeholder(PlaceholderPart.Lid), num); Head = MakeSprite(LoadTex(text, "head.png") ?? Placeholder(PlaceholderPart.Head), num); Texture2D val2 = LoadTex(text, "pupils.png"); Pupils = (((Object)(object)val2 != (Object)null) ? MakeSprite(val2, ((Texture)val2).width) : null); List<Sprite> list = new List<Sprite>(); for (int j = 1; j <= 8; j++) { Texture2D val3 = LoadTex(text, $"bullet_{j}.png"); if ((Object)(object)val3 == (Object)null) { break; } list.Add(MakeSprite(val3, (float)((Texture)val3).width * 1.35f)); } if (list.Count == 0) { Texture2D val4 = LoadTex(text, "bullet.png") ?? Placeholder(PlaceholderPart.Bullet); list.Add(MakeSprite(val4, (float)((Texture)val4).width * 1.35f)); } BulletFrames = list.ToArray(); List<Sprite> list2 = new List<Sprite>(); for (int num3 = 3; num3 >= 1; num3--) { Texture2D val5 = LoadTex(text, $"trail_{num3}.png"); if ((Object)(object)val5 != (Object)null) { list2.Add(MakeSprite(val5, (float)((Texture)val5).width * 3.6f)); } } if (list2.Count == 0) { Texture2D val6 = LoadTex(text, "particle.png") ?? Solid(2, 2, Color.white); list2.Add(MakeSprite(val6, (float)((Texture)val6).width * 12f)); } TrailFrames = list2.ToArray(); Plugin.Log.LogInfo((object)(string.Format("Art: {0} shell, {1} bullet frames, ", ((Object)(object)val != (Object)null) ? "custom" : "placeholder", BulletFrames.Length) + $"{TrailFrames.Length} trail sizes, pupils={(Object)(object)Pupils != (Object)null}, folder {text}")); } private static Texture2D LoadTex(string dir, string file) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_0083: Expected O, but got Unknown string text = Path.Combine(dir, file); if (!File.Exists(text)) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, File.ReadAllBytes(text))) { Plugin.Log.LogWarning((object)("Could not read " + text)); return null; } Texture2D val2 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true); val2.SetPixels32(val.GetPixels32()); val2.Apply(true); Object.Destroy((Object)(object)val); ((Texture)val2).filterMode = (FilterMode)2; ((Texture)val2).anisoLevel = 2; ((Texture)val2).wrapMode = (TextureWrapMode)1; return val2; } private static Sprite ShellSprite(Texture2D source, float ppu) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown Texture2D val = new Texture2D(((Texture)source).width + 32, ((Texture)source).height + 32, (TextureFormat)4, true); val.SetPixels32((Color32[])(object)new Color32[((Texture)val).width * ((Texture)val).height]); val.SetPixels32(16, 16, ((Texture)source).width, ((Texture)source).height, source.GetPixels32()); ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)2; val.Apply(true); Object.Destroy((Object)(object)source); return MakeSprite(val, ppu); } private static Sprite MakeSprite(Texture2D t, float ppu) { //IL_0019: 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) return Sprite.Create(t, new Rect(0f, 0f, (float)((Texture)t).width, (float)((Texture)t).height), new Vector2(0.5f, 0.5f), ppu, 0u, (SpriteMeshType)0); } private static Texture2D Placeholder(PlaceholderPart part) { //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_0161: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0148: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_0154: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); ((Color)(ref val))..ctor(0.55f, 0.36f, 0.6f); Color val2 = default(Color); ((Color)(ref val2))..ctor(0.35f, 0.2f, 0.4f); Color val3 = default(Color); ((Color)(ref val3))..ctor(0.95f, 0.9f, 0.6f); Color[] array = (Color[])(object)new Color[256]; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { Color val4 = Color.clear; switch (part) { case PlaceholderPart.Base: if (i < 8) { val4 = ((i == 7 || j == 0 || j == 15) ? val2 : val); } break; case PlaceholderPart.Lid: if (i >= 8) { val4 = ((i == 8 || j == 0 || j == 15 || i == 15) ? val2 : val); } break; case PlaceholderPart.Head: if (j >= 4 && j < 12 && i >= 5 && i < 13) { val4 = (((j == 6 || j == 9) && i == 10) ? Color.black : val3); } break; case PlaceholderPart.Bullet: { float num = (float)j - 7.5f; float num2 = (float)i - 7.5f; if (num * num + num2 * num2 < 36f) { val4 = (Color)((num * num + num2 * num2 < 9f) ? Color.white : new Color(0.95f, 0.85f, 0.55f)); } break; } } array[i * 16 + j] = val4; } } Texture2D val5 = new Texture2D(16, 16, (TextureFormat)4, false) { filterMode = (FilterMode)0 }; val5.SetPixels(array); val5.Apply(); return val5; } private static Texture2D Solid(int w, int h, Color c) { //IL_0004: 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_0011: Expected O, but got Unknown //IL_001c: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(w, h, (TextureFormat)4, false) { filterMode = (FilterMode)0 }; List<Color> list = new List<Color>(); for (int i = 0; i < w * h; i++) { list.Add(c); } val.SetPixels(list.ToArray()); val.Apply(); return val; } } internal sealed class ShulkerBoxPreview : MonoBehaviour { [SerializeField] private PickableBlock pick; [SerializeField] private Transform lid; [SerializeField] private Transform face; private float elapsed; public static SpriteRenderer[] Create(PickableBlock icon, Transform art, SpriteRenderer style, Sprite pupils) { ShulkerBoxPreview shulkerBoxPreview = ((Component)icon).gameObject.AddComponent<ShulkerBoxPreview>(); shulkerBoxPreview.pick = icon; SpriteRenderer val = Layer(art, "PreviewHead", ShulkerArt.Head, style, 0); SpriteRenderer val2 = Layer(((Component)val).transform, "PreviewPupils", pupils, style, 1); SpriteRenderer val3 = Layer(art, "PreviewBase", ShulkerArt.ShellBase, style, 2); SpriteRenderer val4 = Layer(art, "PreviewLid", ShulkerArt.ShellLid, style, 3); shulkerBoxPreview.face = ((Component)val).transform; shulkerBoxPreview.lid = ((Component)val4).transform; return (SpriteRenderer[])(object)new SpriteRenderer[4] { val, val2, val3, val4 }; } private static SpriteRenderer Layer(Transform parent, string name, Sprite image, SpriteRenderer style, int order) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); SpriteRenderer val2 = val.AddComponent<SpriteRenderer>(); val2.sprite = image; if (Object.op_Implicit((Object)(object)style)) { ((Renderer)val2).sortingLayerID = ((Renderer)style).sortingLayerID; } ((Renderer)val2).sortingOrder = (Object.op_Implicit((Object)(object)style) ? ((Renderer)style).sortingOrder : 0) + order; return val2; } private void LateUpdate() { //IL_00ab: 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_00c7: 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) if (!Object.op_Implicit((Object)(object)pick) || !pick.NetworkInPartybox || !pick.NetworkVisible || pick.Paused || pick.IHoveredCursors == null || pick.IHoveredCursors.Count == 0) { ResetPose(); return; } elapsed = Mathf.Min(elapsed + Time.unscaledDeltaTime, 4.1f); float num = Mathf.Min(elapsed, 4.1f - elapsed) / 0.55f; float num2 = Mathf.SmoothStep(0f, 1f, num); lid.localPosition = Vector3.up * (0.36f * num2); face.localPosition = Vector3.up * (0.22f * num2); } private void OnDisable() { ResetPose(); } private void ResetPose() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) elapsed = 0f; if (Object.op_Implicit((Object)(object)lid)) { lid.localPosition = Vector3.zero; } if (Object.op_Implicit((Object)(object)face)) { face.localPosition = Vector3.zero; } } } [HarmonyPatch(typeof(BlockGroup), "GetItemFilterWeight")] internal static class ShulkerBoxWeight { private static void Postfix(Placeable __0, ref int __result) { if (Object.op_Implicit((Object)(object)__0) && __0.Name == "Shulker") { __result = Mathf.RoundToInt((float)__result * 1.6666666f); } } } public class ShulkerBrain : MonoBehaviour { private struct BoxInfo { public BoxCollider2D box; public Vector2 size; public Vector2 offset; } private const float LidOpenLift = 0.5f; private const float HeadOpenLift = 0.32f; private const float OpenSpeed = 4f; private const float CloseSpeed = 3f; public bool Paused = true; private Transform lid; private Transform head; private Transform shellBase; private float openAmount; private readonly Rules rules = new Rules(); private readonly List<ShulkerBullet> bullets = new List<ShulkerBullet>(); private List<BoxInfo> solidBoxes; private float appliedLift = -1f; private static bool loggedHitbox; private static bool loggedColliders; private const float CloseDelay = 0.5f; private const float AmbientDelay = 0.3f; private const float AmbientCooldown = 20f; private float nextAmbient; private float ambientAt; private float closeHold; private bool visualOpen; private const int TeleportRadiusTiles = 7; private Vector3 homePos; private Quaternion homeRot; private bool hasHome; private Vector3? previousLanding; private Transform landingSupport; private Transform homeParent; internal static Vector3 BlockScale = Vector3.one; private Transform mount; private CrumblingBlock crumbleSupport; private bool watchingSupport; private Vector3 mountPoint; private Vector3 homeScale; private Quaternion mountRotation; private Vector3 homeLocal; private Quaternion homeLocalRot; private bool homeKeepRelative; private bool relocated; private int teleportCount; private readonly HashSet<int> handledProjectiles = new HashSet<int>(); public Placeable Placeable { get; private set; } private static float Clock => (float)Time.timeAsDouble; public string SortingLayer { get { if (!Object.op_Implicit((Object)(object)lid)) { return "Default"; } return ((Renderer)((Component)lid).GetComponent<SpriteRenderer>()).sortingLayerName; } } private void Awake() { Placeable = ((Component)this).GetComponent<Placeable>(); BuildVisuals(); ResetState(); } private void FixedUpdate() { FollowMount(); if (!Paused && Object.op_Implicit((Object)(object)Placeable) && Placeable.Placed && !Placeable.PickedUp) { Tick(Time.fixedDeltaTime); } } private void OnDestroy() { ClearBullets(); } private void BuildVisuals() { SpriteRenderer[] array = EnsureVisuals(((Component)this).transform, Placeable); head = ((Component)array[0]).transform; shellBase = ((Component)array[1]).transform; lid = ((Component)array[2]).transform; } public static SpriteRenderer[] EnsureVisuals(Transform owner, Placeable placeable) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Transform val = owner.Find("ShulkerArt"); if ((Object)(object)val == (Object)null) { val = new GameObject("ShulkerArt").transform; val.SetParent(owner, false); } val.localPosition = Vector3.down * ShulkerArt.BaseInset; string layer = "Default"; int num = 0; SpriteRenderer val2 = (((Object)(object)placeable != (Object)null && placeable.ArtSprites != null && placeable.ArtSprites.Length != 0) ? placeable.ArtSprites[0] : null); if ((Object)(object)val2 != (Object)null) { layer = ((Renderer)val2).sortingLayerName; num = ((Renderer)val2).sortingOrder; } Transform val3 = Part(val, "Head", ShulkerArt.Head, layer, num); List<SpriteRenderer> list = new List<SpriteRenderer> { ((Component)val3).GetComponent<SpriteRenderer>(), ((Component)Part(val, "ShellBase", ShulkerArt.ShellBase, layer, num + 2)).GetComponent<SpriteRenderer>(), ((Component)Part(val, "ShellLid", ShulkerArt.ShellLid, layer, num + 3)).GetComponent<SpriteRenderer>() }; if ((Object)(object)ShulkerArt.Pupils != (Object)null) { list.Add(((Component)Part(val3, "Pupils", ShulkerArt.Pupils, layer, num + 1)).GetComponent<SpriteRenderer>()); } return list.ToArray(); } private static Transform Part(Transform root, string name, Sprite sprite, string layer, int order) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) Transform val = root.Find(name); if ((Object)(object)val == (Object)null) { val = new GameObject(name).transform; val.SetParent(root, false); ((Component)val).gameObject.AddComponent<SpriteRenderer>(); } SpriteRenderer component = ((Component)val).GetComponent<SpriteRenderer>(); component.sprite = sprite; ShulkerArt.MatchStyle(component, ShulkerArt.WorldStyle); ((Renderer)component).sortingLayerName = layer; ((Renderer)component).sortingOrder = order; return val; } private void ApplyOpenVisual() { //IL_0045: 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) float num = openAmount * openAmount * (3f - 2f * openAmount); if (Object.op_Implicit((Object)(object)lid)) { lid.localPosition = new Vector3(0f, 0.5f * num, 0f); } if (Object.op_Implicit((Object)(object)head)) { head.localPosition = new Vector3(0f, 0.32f * num, 0f); } ApplyOpenHitbox(num); } private void ApplyOpenHitbox(float e) { //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00af: 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_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01af: 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_01c8: 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_01f0: 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_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0152: 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_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0284: 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_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: 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_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: 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_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) float num = 0.5f * e; if (Mathf.Abs(num - appliedLift) < 0.002f) { return; } if (solidBoxes == null) { if (num <= 0f) { appliedLift = num; return; } solidBoxes = new List<BoxInfo>(); BoxCollider2D[] componentsInChildren = ((Component)this).GetComponentsInChildren<BoxCollider2D>(true); foreach (BoxCollider2D val in componentsInChildren) { CheckColliding component = ((Component)val).GetComponent<CheckColliding>(); if (!((Object)(object)component != (Object)null) || (!component.Required && !component.AntiRequired && !component.ReverseAttach)) { solidBoxes.Add(new BoxInfo { box = val, size = val.size, offset = ((Collider2D)val).offset }); } } LogColliders(); } appliedLift = num; Vector3 val2 = ((Component)this).transform.TransformVector(Vector3.up); int num2 = 0; int num3 = 0; int num4 = 0; foreach (BoxInfo solidBox in solidBoxes) { if ((Object)(object)solidBox.box == (Object)null) { continue; } if (num > 0f && ((Collider2D)solidBox.box).isTrigger) { solidBox.box.size = solidBox.size; ((Collider2D)solidBox.box).offset = solidBox.offset; continue; } Transform transform = ((Component)solidBox.box).transform; Vector2 val3 = Vector2.op_Implicit(transform.InverseTransformVector(val2)); float magnitude = ((Vector2)(ref val3)).magnitude; if (!(magnitude < 1E-05f)) { Vector2 val4 = val3 / magnitude; float num5 = 0.5f * (Mathf.Abs(solidBox.size.x * val4.x) + Mathf.Abs(solidBox.size.y * val4.y)) / magnitude; float y = ((Component)this).transform.InverseTransformPoint(transform.TransformPoint(Vector2.op_Implicit(solidBox.offset))).y; float num6 = y - num5; float num7 = y + num5; if (num6 >= -0.05f) { solidBox.box.size = solidBox.size; ((Collider2D)solidBox.box).offset = solidBox.offset + val3 * num; num2++; } else if (num7 <= 0.05f) { solidBox.box.size = solidBox.size; ((Collider2D)solidBox.box).offset = solidBox.offset; num3++; } else { Vector2 val5 = val3 * num; solidBox.box.size = solidBox.size + new Vector2(Mathf.Abs(val5.x), Mathf.Abs(val5.y)); ((Collider2D)solidBox.box).offset = solidBox.offset + val5 * 0.5f; num4++; } } } if (!loggedHitbox && num >= 0.49f) { loggedHitbox = true; Plugin.Log.LogInfo((object)$"Shulker open hitbox: {solidBoxes.Count} solid boxes, {num2} moved up, {num4} stretched, {num3} kept (lift {num:0.00} tiles)"); } } private void LogColliders() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) if (!loggedColliders) { loggedColliders = true; StringBuilder stringBuilder = new StringBuilder("Shulker colliders in play mode:"); Collider2D[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider2D>(true); foreach (Collider2D val in componentsInChildren) { CheckColliding component = ((Component)val).GetComponent<CheckColliding>(); CollisionTag component2 = ((Component)val).GetComponent<CollisionTag>(); BoxCollider2D val2 = (BoxCollider2D)(object)((val is BoxCollider2D) ? val : null); string text = ((val2 != null) ? $" size={val2.size} off={((Collider2D)val2).offset}" : ""); stringBuilder.Append($"\n {((Object)val).name} {((object)val).GetType().Name} trigger={val.isTrigger} enabled={((Behaviour)val).enabled} active={((Component)val).gameObject.activeInHierarchy}{text}" + string.Format(" check={0} tag={1} layer={2}", Object.op_Implicit((Object)(object)component) ? $"req={component.Required} anti={component.AntiRequired}" : "no", Object.op_Implicit((Object)(object)component2) ? ((object)Unsafe.As<Tag, Tag>(ref component2.bitMask)/*cast due to .constrained prefix*/).ToString() : "none", ((Component)val).gameObject.layer)); } Plugin.Log.LogInfo((object)stringBuilder.ToString()); } } private void RememberHome() { //IL_0007: 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_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) homePos = ((Component)this).transform.position; homeRot = ((Component)this).transform.rotation; homeParent = ((Component)this).transform.parent; homeLocal = ((Component)this).transform.localPosition; homeScale = ((Component)this).transform.localScale; homeLocalRot = ((Component)this).transform.localRotation; homeKeepRelative = Placeable.KeepRelativeAttachPosition; hasHome = true; } public void OnPlayStart() { //IL_0013: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) RestoreHome(); RememberHome(); Collider2D val = FindSupport(((Component)this).transform.position, ((Component)this).transform.up, Mathf.Max(0.01f, Plugin.BlockSize.Value)); Transform val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).transform : homeParent); if (Object.op_Implicit((Object)(object)homeParent) && Object.op_Implicit((Object)(object)((Component)homeParent).GetComponentInParent<HoneyPiece>())) { val2 = homeParent; } Vector3 seated = ((Component)this).transform.position; if (Object.op_Implicit((Object)(object)val)) { TrySeat(val, seated, ((Component)this).transform.up, Plugin.BlockSize.Value, out seated); } if (Object.op_Implicit((Object)(object)val2)) { Mount(val2, seated, ((Component)this).transform.rotation); } } private void Mount(Transform surface, Vector3 position, Quaternion rotation) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: 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_009f: Unknown result type (might be due to invalid IL or missing references) relocated = true; Placeable.KeepRelativeAttachPosition = false; ((Component)this).transform.SetParent((Transform)null, true); ((Component)this).transform.localScale = BlockScale; ((Component)this).transform.SetPositionAndRotation(position, rotation); mount = surface; watchingSupport = (Object)(object)surface != (Object)null; crumbleSupport = (Object.op_Implicit((Object)(object)surface) ? ((Component)surface).GetComponentInParent<CrumblingBlock>() : null); if (Object.op_Implicit((Object)(object)mount)) { mountPoint = mount.InverseTransformPoint(position); mountRotation = Quaternion.Inverse(mount.rotation) * rotation; } } private void FollowMount() { //IL_006a: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) if (!Paused && relocated && watchingSupport) { if (!Object.op_Implicit((Object)(object)mount) || !((Component)mount).gameObject.activeInHierarchy || IsBroken(crumbleSupport)) { watchingSupport = false; Teleport(5458000, "support broke"); } else { ((Component)this).transform.SetPositionAndRotation(mount.TransformPoint(mountPoint), mount.rotation * mountRotation); } } } private static bool IsBroken(CrumblingBlock block) { if (Object.op_Implicit((Object)(object)block)) { if (!block.falling) { return ((Placeable)block).damageLevel == ((Placeable)block).DestroyedDamageLevel; } return true; } return false; } private void LateUpdate() { FollowMount(); } private void RestoreHome() { //IL_004e: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_009f: 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) if (!hasHome) { return; } hasHome = false; if (relocated) { relocated = false; mount = null; crumbleSupport = null; watchingSupport = false; ((Component)this).transform.SetParent(homeParent, false); ((Component)this).transform.localScale = homeScale; Placeable.KeepRelativeAttachPosition = homeKeepRelative; if (Object.op_Implicit((Object)(object)homeParent)) { homePos = homeParent.TransformPoint(homeLocal); homeRot = homeParent.rotation * homeLocalRot; } ((Component)this).transform.SetPositionAndRotation(homePos, homeRot); Physics2D.SyncTransforms(); appliedLift = -1f; } } public void OnShot(int hitId, int projectileNumber) { if (!Paused && handledProjectiles.Add(hitId)) { Sounds.Play(visualOpen ? "hurt" : "hurt_closed"); Teleport(projectileNumber, "projectile hit"); } } private void Teleport(int eventSeed, string reason) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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) if (!hasHome) { RememberHome(); } int seed = (eventSeed * 73856093) ^ (Mathf.RoundToInt(homePos.x * 100f) * 19349663) ^ (Mathf.RoundToInt(homePos.y * 100f) * 83492791) ^ ++teleportCount; if (TryFindSpot(new Random(seed), out var pos, out var rot)) { previousLanding = ((Component)this).transform.position; Burst(((Component)this).transform.position); Mount(landingSupport, pos, rot); Physics2D.SyncTransforms(); appliedLift = -1f; ApplyOpenVisual(); Burst(pos); Sounds.Play("teleport"); ManualLogSource log = Plugin.Log; object[] obj = new object[6] { reason, previousLanding, pos, Vector3.Distance(previousLanding.Value, pos) / Plugin.BlockSize.Value, ((Quaternion)(ref rot)).eulerAngles.z, null }; Transform obj2 = landingSupport; object obj3 = ((obj2 == null) ? null : ((Component)obj2).GetComponentInParent<Placeable>()?.Name); if (obj3 == null) { Transform obj4 = landingSupport; obj3 = ((obj4 != null) ? ((Object)obj4).name : null) ?? "out-of-bounds fallback"; } obj[5] = obj3; log.LogInfo((object)string.Format("Shulker teleported ({0}) from {1} to {2} ({3:0.00} blocks), rotation {4:0}, support {5}", obj)); } } private void Burst(Vector3 at) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < 12; i++) { ShulkerParticle.Spawn(at, SortingLayer, 0.7f, 1.5f, (i % 2 == 0) ? 49 : 51); } } private bool TryFindSpot(Random rnd, out Vector3 pos, out Quaternion rot) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //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_0053: 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_00fb: 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_0108: 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) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0163: 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_017b: 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_0193: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) //IL_03e2: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Unknown result type (might be due to invalid IL or missing references) //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_041a: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_0459: Unknown result type (might be due to invalid IL or missing references) //IL_045e: Unknown result type (might be due to invalid IL or missing references) //IL_0463: Unknown result type (might be due to invalid IL or missing references) //IL_046a: Unknown result type (might be due to invalid IL or missing references) //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_0471: Unknown result type (might be due to invalid IL or missing references) //IL_0479: Unknown result type (might be due to invalid IL or missing references) //IL_0483: Unknown result type (might be due to invalid IL or missing references) //IL_049d: Unknown result type (might be due to invalid IL or missing references) //IL_04a2: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: 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_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_04be: Unknown result type (might be due to invalid IL or missing references) //IL_04c3: Unknown result type (might be due to invalid IL or missing references) //IL_04c5: Unknown result type (might be due to invalid IL or missing references) //IL_04c7: Unknown result type (might be due to invalid IL or missing references) //IL_04c8: Unknown result type (might be due to invalid IL or missing references) //IL_04cd: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_04df: Unknown result type (might be due to invalid IL or missing references) //IL_04e1: Unknown result type (might be due to invalid IL or missing references) //IL_0516: Unknown result type (might be due to invalid IL or missing references) //IL_0520: Unknown result type (might be due to invalid IL or missing references) //IL_0228: 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_04f3: Unknown result type (might be due to invalid IL or missing references) //IL_04f5: Unknown result type (might be due to invalid IL or missing references) //IL_0577: Unknown result type (might be due to invalid IL or missing references) //IL_0578: Unknown result type (might be due to invalid IL or missing references) //IL_057e: Unknown result type (might be due to invalid IL or missing references) //IL_0585: Unknown result type (might be due to invalid IL or missing references) //IL_0599: Unknown result type (might be due to invalid IL or missing references) //IL_059e: Unknown result type (might be due to invalid IL or missing references) //IL_05a3: Unknown result type (might be due to invalid IL or missing references) //IL_024d: 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_054e: Unknown result type (might be due to invalid IL or missing references) //IL_0553: Unknown result type (might be due to invalid IL or missing references) //IL_0557: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_028f: 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_02a5: 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_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: 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_02cd: 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_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_035e: 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) float num = Mathf.Max(0.01f, Plugin.BlockSize.Value); Vector3 position = ((Component)this).transform.position; List<Vector2Int> list = new List<Vector2Int>(); int num2 = 14; for (int i = -num2; i <= num2; i++) { for (int j = -num2; j <= num2; j++) { if ((i != 0 || j != 0) && i * i + j * j <= num2 * num2) { list.Add(new Vector2Int(i, j)); } } } for (int num3 = list.Count - 1; num3 > 0; num3--) { int index = rnd.Next(num3 + 1); Vector2Int value = list[num3]; list[num3] = list[index]; list[index] = value; } Level val = Object.FindObjectOfType<Level>(); Bounds val2 = (Bounds)(Object.op_Implicit((Object)(object)val) ? val.GetCursorBounds() : new Bounds(position, Vector3.one * num * 14f)); landingSupport = null; int num4 = -1; pos = position; rot = ((Component)this).transform.rotation; int num5 = rnd.Next(4); Vector3 val7; foreach (Vector2Int item in list) { Vector2Int current = item; Vector3 val3 = position + new Vector3((float)((Vector2Int)(ref current)).x, (float)((Vector2Int)(ref current)).y) * (num * 0.5f); float num6 = num * 0.5f; if (val3.x - num6 >= ((Bounds)(ref val2)).min.x && val3.x + num6 <= ((Bounds)(ref val2)).max.x && val3.y - num6 >= ((Bounds)(ref val2)).min.y) { _ = val3.y + num6 <= ((Bounds)(ref val2)).max.y; } else _ = 0; for (int k = 0; k < 4; k++) { Quaternion val4 = Quaternion.Euler(0f, 0f, (float)(90 * ((num5 + k) % 4))); Vector3 val5 = val4 * Vector3.up; Collider2D val6 = FindSupport(val3, val5, num); if (!Object.op_Implicit((Object)(object)val6) || !TrySeat(val6, val3, val5, num, out var seated)) { continue; } float num7 = Vector3.Distance(position, seated) / num; if (num7 < 0.95f || num7 > 7.0001f || !IsFree(Vector2.op_Implicit(seated), num)) { continue; } bool num8 = ((Bounds)(ref val2)).Contains(new Vector3(seated.x - num6, seated.y - num6, ((Bounds)(ref val2)).center.z)) && ((Bounds)(ref val2)).Contains(new Vector3(seated.x + num6, seated.y + num6, ((Bounds)(ref val2)).center.z)); bool flag = IsFree(Vector2.op_Implicit(seated + val5 * num6), num); int num9 = (num8 ? 16 : 0) + (flag ? 8 : 0) + ((Quaternion.Angle(val4, ((Component)this).transform.rotation) > 10f) ? 4 : 0); int num10; if (previousLanding.HasValue) { val7 = val3 - previousLanding.Value; if (!(((Vector3)(ref val7)).sqrMagnitude > num6 * num6)) { num10 = 0; goto IL_033b; } } num10 = 2; goto IL_033b; IL_033b: int num11 = num9 + num10; if (num11 > num4) { num4 = num11; landingSupport = ((Component)val6).transform; pos = seated; rot = val4; } } } if (num4 >= 0) { return true; } Vector3[] obj = new Vector3[4] { position + Vector3.left * num * (float)Mathf.Max(1, Mathf.CeilToInt((position.x - ((Bounds)(ref val2)).min.x) / num + 1f)), position + Vector3.right * num * (float)Mathf.Max(1, Mathf.CeilToInt((((Bounds)(ref val2)).max.x - position.x) / num + 1f)), position + Vector3.down * num * (float)Mathf.Max(1, Mathf.CeilToInt((position.y - ((Bounds)(ref val2)).min.y) / num + 1f)), position + Vector3.up * num * (float)Mathf.Max(1, Mathf.CeilToInt((((Bounds)(ref val2)).max.y - position.y) / num + 1f)) }; float num12 = float.PositiveInfinity; Vector3[] array = (Vector3[])(object)obj; foreach (Vector3 val8 in array) { val7 = val8 - position; float sqrMagnitude = ((Vector3)(ref val7)).sqrMagnitude; if (!(sqrMagnitude >= num12) && IsFree(Vector2.op_Implicit(val8), num)) { num12 = sqrMagnitude; pos = val8; } } if (float.IsPositiveInfinity(num12)) { float num13 = Mathf.Max(((Bounds)(ref val2)).max.y, position.y); Collider2D[] array2 = Object.FindObjectsOfType<Collider2D>(); foreach (Collider2D val9 in array2) { if (BlocksTeleport(val9)) { float num14 = num13; Bounds bounds = val9.bounds; num13 = Mathf.Max(num14, ((Bounds)(ref bounds)).max.y); } } pos = position + Vector3.up * num * Mathf.Ceil((num13 - position.y) / num + 2f); } return true; } private bool IsFree(Vector2 p, float tile) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references) int num = Phys.Box(p, Vector2.one * tile * 0.96f, 0f); for (int i = 0; i < num; i++) { if (BlocksTeleport(Phys.Buf[i])) { return false; } } return num < Phys.Buf.Length; } private Collider2D FindSupport(Vector3 center, Vector3 outward, float tile) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: 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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due t