Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ExplodingTurtle v0.2.1
TurtleMod.dll
Decompiled 20 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; using UnityEngine.Audio; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TurtleMod { internal static class GameRefs { public const string ThumperName = "Crawler"; public const string HydrogereName = "Blob"; private static AudioMixerGroup sfxGroup; private static float cachedTargetSpeed = -1f; public static AudioMixerGroup EnemySfxGroup { get { if ((Object)(object)sfxGroup != (Object)null) { return sfxGroup; } try { EnemyType val = FindEnemyType("Crawler"); EnemyAI val2 = (((Object)(object)val != (Object)null && (Object)(object)val.enemyPrefab != (Object)null) ? val.enemyPrefab.GetComponent<EnemyAI>() : null); if ((Object)(object)val2 != (Object)null && (Object)(object)val2.creatureSFX != (Object)null) { sfxGroup = val2.creatureSFX.outputAudioMixerGroup; } } catch { } return sfxGroup; } } public static float TargetSpeed { get { if (TurtleConfig.TargetSpeedOverride.Value > 0f) { return TurtleConfig.TargetSpeedOverride.Value; } if (cachedTargetSpeed > 0f) { return cachedTargetSpeed; } float num = -1f; try { EnemyType val = FindEnemyType("Blob"); NavMeshAgent val2 = (((Object)(object)val != (Object)null && (Object)(object)val.enemyPrefab != (Object)null) ? val.enemyPrefab.GetComponentInChildren<NavMeshAgent>(true) : null); if ((Object)(object)val2 != (Object)null) { num = val2.speed; } } catch { } if (num < 0.5f) { num = TurtleConfig.TargetSpeedFallback.Value; } cachedTargetSpeed = num; Plugin.Log.LogInfo((object)("Hydrogere speed used for the Target phase: " + num)); return num; } } public static EnemyType FindEnemyType(string internalName) { return ((IEnumerable<EnemyType>)Resources.FindObjectsOfTypeAll<EnemyType>()).FirstOrDefault((Func<EnemyType, bool>)((EnemyType e) => (Object)(object)e != (Object)null && e.enemyName == internalName)); } public static void CopyVoiceRange(AudioSource dst) { //IL_008e: 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_00a0: Invalid comparison between Unknown and I4 try { PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; AudioSource val = null; PlayerControllerB[] array = allPlayerScripts; foreach (PlayerControllerB val2 in array) { if ((Object)(object)val2 != (Object)null && (Object)(object)val2.currentVoiceChatAudioSource != (Object)null) { val = val2.currentVoiceChatAudioSource; break; } } if ((Object)(object)val != (Object)null && val.maxDistance > 1f) { dst.minDistance = val.minDistance; dst.maxDistance = val.maxDistance; dst.rolloffMode = val.rolloffMode; if ((int)val.rolloffMode == 2) { dst.SetCustomCurve((AudioSourceCurveType)0, val.GetCustomCurve((AudioSourceCurveType)0)); } return; } } catch { } dst.minDistance = 3f; dst.maxDistance = TurtleConfig.HelloRangeFallback.Value; dst.rolloffMode = (AudioRolloffMode)1; } } internal static class MaterialFixer { private static readonly Dictionary<string, Color> Fallback = new Dictionary<string, Color> { { "Material.003", new Color(0.8f, 0.022f, 0f) }, { "Material.001", new Color(0.068f, 0.799f, 0f) }, { "Material", new Color(0.8f, 0.8f, 0.8f) }, { "Material.002", new Color(0.144f, 0.084f, 0.012f) }, { "Material.004", new Color(0.02f, 0.02f, 0.02f) } }; public static void Fix(GameObject model) { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_013a: 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_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Expected O, but got Unknown //IL_019b: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("HDRP/Lit"); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"HDRP/Lit shader not found; leaving materials alone."); return; } Renderer[] componentsInChildren = model.GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { Material[] sharedMaterials = val2.sharedMaterials; bool flag = false; for (int j = 0; j < sharedMaterials.Length; j++) { Material val3 = sharedMaterials[j]; if ((Object)(object)val3 == (Object)null) { continue; } string text = (((Object)(object)val3.shader != (Object)null) ? ((Object)val3.shader).name : ""); if (!text.StartsWith("HDRP/") && !text.StartsWith("Shader Graphs/")) { Color val4 = Color.white; Texture val5 = null; string text2 = ((Object)val3).name.Replace(" (Instance)", ""); Color value; if (val3.HasProperty("_BaseColor")) { val4 = val3.GetColor("_BaseColor"); } else if (val3.HasProperty("_Color")) { val4 = val3.GetColor("_Color"); } else if (Fallback.TryGetValue(text2, out value)) { val4 = ((Color)(ref value)).gamma; } if (val3.HasProperty("_BaseColorMap")) { val5 = val3.GetTexture("_BaseColorMap"); } else if (val3.HasProperty("_MainTex")) { val5 = val3.GetTexture("_MainTex"); } Material val6 = new Material(val) { name = text2 }; val6.SetColor("_BaseColor", val4); if ((Object)(object)val5 != (Object)null) { val6.SetTexture("_BaseColorMap", val5); } val6.SetFloat("_Smoothness", 0.25f); sharedMaterials[j] = val6; flag = true; } } if (flag) { val2.sharedMaterials = sharedMaterials; } } } } [BepInPlugin("kachowe.ExplodingTurtle", "ExplodingTurtle", "0.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "kachowe.ExplodingTurtle"; public const string PluginName = "ExplodingTurtle"; public const string PluginVersion = "0.2.0"; internal static ManualLogSource Log; internal static EnemyType TurtleType; internal static AudioClip HelloClip; internal static AudioClip BoomClip; private void Awake() { //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; TurtleConfig.Bind(((BaseUnityPlugin)this).Config); string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName, "turtlebundle"); AssetBundle val = AssetBundle.LoadFromFile(text); if ((Object)(object)val == (Object)null) { Log.LogError((object)("Could not load asset bundle at: " + text + " (is 'turtlebundle' next to the DLL?)")); return; } GameObject val2 = null; string[] array = new string[4] { "turtle3", "turtle2", "turtled", "turtle" }; foreach (string text2 in array) { val2 = val.LoadAsset<GameObject>(text2); if ((Object)(object)val2 != (Object)null) { break; } } if ((Object)(object)val2 == (Object)null) { GameObject[] array2 = val.LoadAllAssets<GameObject>(); foreach (GameObject val3 in array2) { if ((Object)(object)val3.GetComponentInChildren<MeshFilter>(true) != (Object)null) { val2 = val3; break; } } } HelloClip = val.LoadAsset<AudioClip>("hello"); BoomClip = val.LoadAsset<AudioClip>("boom"); if ((Object)(object)val2 == (Object)null) { Log.LogError((object)"Bundle contains no model (expected 'turtle3')."); return; } if ((Object)(object)HelloClip == (Object)null) { Log.LogWarning((object)"Bundle has no clip called 'hello'."); } if ((Object)(object)BoomClip == (Object)null) { Log.LogWarning((object)"Bundle has no clip called 'boom'."); } try { BuildEnemy(val2); } catch (Exception ex) { Log.LogError((object)("Failed to build the turtle: " + ex)); return; } Harmony val4 = new Harmony("kachowe.ExplodingTurtle"); try { val4.CreateClassProcessor(typeof(TurtleSpawnSync)).Patch(); } catch (Exception ex2) { Log.LogError((object)("Spawn-sync patch failed (turtle won't spawn): " + ex2)); } try { val4.CreateClassProcessor(typeof(TurtleHitPatch)).Patch(); } catch (Exception ex3) { Log.LogError((object)("Hit patch failed (turtle won't react to being hit): " + ex3)); } Log.LogInfo((object)"Exploding Turtle loaded."); } private void BuildEnemy(GameObject modelAsset) { //IL_0027: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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_00f7: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: 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_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Expected O, but got Unknown //IL_03f5: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Expected O, but got Unknown //IL_03fd: Unknown result type (might be due to invalid IL or missing references) //IL_0403: Expected O, but got Unknown //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Expected O, but got Unknown float num = TurtleConfig.PlayerHeight.Value * TurtleConfig.SizeFraction.Value; GameObject val = NetworkPrefabs.CreateNetworkPrefab("ExplodingTurtle"); Transform transform = new GameObject("Visual").transform; transform.SetParent(val.transform, false); GameObject val2 = Object.Instantiate<GameObject>(modelAsset, transform, false); ((Object)val2).name = "Model"; val2.transform.localRotation = Quaternion.Euler(0f, TurtleConfig.ModelYaw.Value, 0f); MaterialFixer.Fix(val2); Bounds val3 = Measure(transform); float num2 = ((((Bounds)(ref val3)).size.y > 0.0001f) ? (num / ((Bounds)(ref val3)).size.y) : 1f); transform.localScale = Vector3.one * num2; transform.localPosition = new Vector3((0f - ((Bounds)(ref val3)).center.x) * num2, (0f - ((Bounds)(ref val3)).min.y) * num2, (0f - ((Bounds)(ref val3)).center.z) * num2); Vector3 val4 = ((Bounds)(ref val3)).size * num2; Log.LogInfo((object)("Turtle model fitted: " + val4.x.ToString("0.00") + " x " + val4.y.ToString("0.00") + " x " + val4.z.ToString("0.00") + " (target height " + num.ToString("0.00") + ")")); int num3 = LayerMask.NameToLayer("Enemies"); if (num3 >= 0) { Transform[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Transform>(true); foreach (Transform val5 in componentsInChildren) { ((Component)val5).gameObject.layer = num3; } } NavMeshAgent val6 = val.AddComponent<NavMeshAgent>(); val6.radius = Mathf.Clamp(Mathf.Max(val4.x, val4.z) * 0.5f, 0.12f, 0.35f); val6.height = Mathf.Max(0.3f, num); val6.baseOffset = 0f; val6.speed = TurtleConfig.RoamSpeed.Value; val6.acceleration = 20f; val6.angularSpeed = 360f; val6.stoppingDistance = 0f; val6.autoBraking = false; AudioSource creatureVoice = AddAudio(val, "Voice"); AudioSource creatureSFX = AddAudio(val, "Sfx"); Transform transform2 = new GameObject("Eye").transform; transform2.SetParent(val.transform, false); transform2.localPosition = new Vector3(0f, num * 0.8f, 0f); AddHitbox(val, val4); AddScanNode(val, val4); EnemyType val7 = ScriptableObject.CreateInstance<EnemyType>(); ((Object)val7).name = "ExplodingTurtleType"; val7.enemyName = "Turtle"; val7.enemyPrefab = val; val7.PowerLevel = TurtleConfig.PowerLevel.Value; val7.MaxCount = TurtleConfig.MaxCount.Value; val7.probabilityCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[2] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) }); val7.isOutsideEnemy = false; val7.isDaytimeEnemy = false; val7.canDie = true; val7.destroyOnDeath = true; val7.canBeStunned = false; ((Object)val7).hideFlags = (HideFlags)61; TurtleType = val7; TurtleAI turtleAI = val.AddComponent<TurtleAI>(); ((EnemyAI)turtleAI).enemyType = val7; ((EnemyAI)turtleAI).agent = val6; ((EnemyAI)turtleAI).eye = transform2; ((EnemyAI)turtleAI).creatureVoice = creatureVoice; ((EnemyAI)turtleAI).creatureSFX = creatureSFX; ((EnemyAI)turtleAI).enemyHP = 1; ((EnemyAI)turtleAI).enemyBehaviourStates = (EnemyBehaviourState[])(object)new EnemyBehaviourState[3] { new EnemyBehaviourState(), new EnemyBehaviourState(), new EnemyBehaviourState() }; Reflect.TrySet(turtleAI, "AIIntervalTime", 0.2f); Reflect.TrySet(turtleAI, "updatePositionThreshold", 0.1f); Reflect.TrySet(turtleAI, "agentMaxSpeed", TurtleConfig.RoamSpeed.Value); Reflect.TrySet(turtleAI, "agentMaxAcceleration", 20f); } private static AudioSource AddAudio(GameObject root, string childName) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown GameObject val = new GameObject(childName); val.transform.SetParent(root.transform, false); AudioSource val2 = val.AddComponent<AudioSource>(); val2.playOnAwake = false; val2.spatialBlend = 1f; val2.dopplerLevel = 0f; val2.rolloffMode = (AudioRolloffMode)1; val2.minDistance = 3f; val2.maxDistance = 30f; return val2; } private static void AddScanNode(GameObject root, Vector3 size) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_002a: 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) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00cc: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("ScanNode"); val.transform.SetParent(root.transform, false); val.transform.localPosition = new Vector3(0f, size.y * 0.5f, 0f); try { int num = LayerMask.NameToLayer("ScanNode"); if (num >= 0) { val.layer = num; } } catch (Exception ex) { Log.LogWarning((object)("Could not set ScanNode layer: " + ex.Message)); } BoxCollider val2 = val.AddComponent<BoxCollider>(); ((Collider)val2).isTrigger = true; val2.size = new Vector3(Mathf.Max(0.4f, size.x), Mathf.Max(0.4f, size.y), Mathf.Max(0.4f, size.z)); ScanNodeProperties target = val.AddComponent<ScanNodeProperties>(); Reflect.TrySet(target, "maxRange", 20); Reflect.TrySet(target, "minRange", 1); Reflect.TrySet(target, "requiresLineOfSight", true); Reflect.TrySet(target, "headerText", "Turtle"); Reflect.TrySet(target, "subText", "Danger: explodes!"); Reflect.TrySet(target, "nodeType", 1); Reflect.TrySet(target, "creatureScanID", -1); Reflect.TrySet(target, "scrapValue", 0); } private static void AddHitbox(GameObject root, Vector3 size) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0084: 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_00a4: 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_00c0: 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) GameObject val = new GameObject("Hitbox"); val.transform.SetParent(root.transform, false); try { int num = LayerMask.NameToLayer("Enemies"); if (num >= 0) { val.layer = num; } val.tag = "Enemy"; } catch (Exception ex) { Log.LogWarning((object)("Could not set Enemy tag/layer on hitbox: " + ex.Message)); } BoxCollider val2 = val.AddComponent<BoxCollider>(); ((Collider)val2).isTrigger = true; val2.size = new Vector3(Mathf.Max(0.2f, size.x), Mathf.Max(0.2f, size.y), Mathf.Max(0.2f, size.z)); val2.center = new Vector3(0f, size.y * 0.5f, 0f); val.AddComponent<EnemyAICollisionDetect>(); } private static Bounds Measure(Transform reference) { //IL_0002: 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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_011b: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_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_0120: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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) Matrix4x4 worldToLocalMatrix = reference.worldToLocalMatrix; bool flag = false; Bounds result = default(Bounds); MeshFilter[] componentsInChildren = ((Component)reference).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { if ((Object)(object)val.sharedMesh == (Object)null) { continue; } Bounds bounds = val.sharedMesh.bounds; Matrix4x4 val2 = worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; for (int j = 0; j < 8; j++) { Vector3 val3 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3(((j & 1) == 0) ? (-1f) : 1f, ((j & 2) == 0) ? (-1f) : 1f, ((j & 4) == 0) ? (-1f) : 1f)); Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(val3); if (!flag) { ((Bounds)(ref result))..ctor(val4, Vector3.zero); flag = true; } else { ((Bounds)(ref result)).Encapsulate(val4); } } } return result; } } internal static class Reflect { public static void TrySet(object target, string field, object value) { FieldInfo fieldInfo = AccessTools.Field(target.GetType(), field); if (fieldInfo == null) { return; } try { fieldInfo.SetValue(target, Convert.ChangeType(value, fieldInfo.FieldType)); } catch (Exception) { } } } public class TurtleAI : EnemyAI { public enum Phase : byte { Roaming, Still, Targeting } private enum PartKind { Head, HeadAttached, Neck, Shell, ShellAttached, Foot } private class Part { public Transform t; public Vector3 basePos; public Quaternion baseRot; public PartKind kind; public float offset; } private Phase phase = Phase.Roaming; private float phaseTimer; private bool cameFromTarget; private bool detonating; private float spawnClock; private PlayerControllerB turtleTarget; private readonly AISearchRoutine roamRoutine = new AISearchRoutine(); private float helloTimer; private float nextHello; private Random helloRng; private readonly List<Part> parts = new List<Part>(); private Part headPart; private Part shellPart; private Transform visual; private Vector3 lastPos; private float walkBlend; private float walkClock; private static readonly FieldInfo AgentMaxSpeedField = typeof(EnemyAI).GetField("agentMaxSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); public override void Start() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).Start(); TurtleNet.EnsureRegistered(); visual = ((Component)this).transform.Find("Visual"); CacheParts(); EnemyAICollisionDetect[] componentsInChildren = ((Component)this).GetComponentsInChildren<EnemyAICollisionDetect>(true); foreach (EnemyAICollisionDetect val in componentsInChildren) { val.mainScript = (EnemyAI)(object)this; } lastPos = ((Component)this).transform.position; helloRng = new Random((int)(((NetworkBehaviour)this).NetworkObjectId % 100000) + 17); nextHello = NextHelloDelay(); if ((Object)(object)base.creatureVoice != (Object)null) { base.creatureVoice.outputAudioMixerGroup = GameRefs.EnemySfxGroup; } if ((Object)(object)base.creatureSFX != (Object)null) { base.creatureSFX.outputAudioMixerGroup = GameRefs.EnemySfxGroup; } if (((NetworkBehaviour)this).IsServer) { EnterPhase(Phase.Roaming); } } public override void Update() { ((EnemyAI)this).Update(); if (!base.isEnemyDead) { float deltaTime = Time.deltaTime; spawnClock += deltaTime; TickHello(deltaTime); TickWalkAnimation(deltaTime); if (((NetworkBehaviour)this).IsServer && !detonating) { TickServer(deltaTime); } } } public override void DoAIInterval() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) ((EnemyAI)this).DoAIInterval(); if (!((NetworkBehaviour)this).IsServer || base.isEnemyDead || detonating || StartOfRound.Instance.allPlayersDead) { return; } switch (phase) { case Phase.Roaming: if (!roamRoutine.inProgress) { ((EnemyAI)this).StartSearch(((Component)this).transform.position, roamRoutine); } break; case Phase.Targeting: if (!IsValidTarget(turtleTarget)) { turtleTarget = PickTarget(); } if ((Object)(object)turtleTarget != (Object)null) { ((EnemyAI)this).SetDestinationToPosition(((Component)turtleTarget).transform.position, false); } break; } } private void TickServer(float dt) { phaseTimer -= dt; if (phaseTimer <= 0f) { AdvancePhase(); } if (spawnClock > 1f && !StartOfRound.Instance.allPlayersDead) { CheckForSteppedOn(); } } private void AdvancePhase() { switch (phase) { case Phase.Roaming: EnterPhase(Phase.Still); break; case Phase.Still: if (cameFromTarget) { cameFromTarget = false; EnterPhase(Phase.Roaming); } else { EnterPhase(Phase.Targeting); } break; case Phase.Targeting: cameFromTarget = true; EnterPhase(Phase.Still); break; } } private void EnterPhase(Phase next) { //IL_00c6: Unknown result type (might be due to invalid IL or missing references) phase = next; switch (next) { case Phase.Roaming: phaseTimer = Jitter(TurtleConfig.RoamSeconds.Value); SetSpeed(TurtleConfig.RoamSpeed.Value); turtleTarget = null; break; case Phase.Still: phaseTimer = Jitter(TurtleConfig.StillSeconds.Value); ((EnemyAI)this).StopSearch(roamRoutine, true); base.moveTowardsDestination = false; turtleTarget = null; if ((Object)(object)base.agent != (Object)null && ((Behaviour)base.agent).enabled && base.agent.isOnNavMesh) { base.agent.ResetPath(); base.agent.velocity = Vector3.zero; } break; case Phase.Targeting: phaseTimer = TurtleConfig.TargetSeconds.Value; ((EnemyAI)this).StopSearch(roamRoutine, true); SetSpeed(GameRefs.TargetSpeed); turtleTarget = PickTarget(); break; } TurtleNet.SendPhase(((NetworkBehaviour)this).NetworkObjectId, (byte)next); } public void ApplyPhaseOnClient(Phase p) { if (!((NetworkBehaviour)this).IsServer) { phase = p; } } private static float Jitter(float seconds) { return seconds * Random.Range(0.9f, 1.1f); } private void SetSpeed(float speed) { if ((Object)(object)base.agent != (Object)null) { base.agent.speed = speed; } if (AgentMaxSpeedField != null) { AgentMaxSpeedField.SetValue(this, speed); } } private static bool IsValidTarget(PlayerControllerB p) { return (Object)(object)p != (Object)null && p.isPlayerControlled && !p.isPlayerDead; } private PlayerControllerB PickTarget() { List<PlayerControllerB> list = StartOfRound.Instance.allPlayerScripts.Where(IsValidTarget).ToList(); if (list.Count == 0) { return null; } List<PlayerControllerB> list2 = list.Where((PlayerControllerB p) => p.isInsideFactory).ToList(); List<PlayerControllerB> list3 = ((list2.Count > 0) ? list2 : list); return list3[Random.Range(0, list3.Count)]; } private void CheckForSteppedOn() { //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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)this).transform.position; float num = TurtleConfig.StepRadius.Value * TurtleConfig.StepRadius.Value; float value = TurtleConfig.StepHeight.Value; PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (IsValidTarget(val)) { Vector3 val2 = ((Component)val).transform.position - position; float y = val2.y; val2.y = 0f; if (((Vector3)(ref val2)).sqrMagnitude <= num && y > -0.6f && y < value) { ServerBeginDetonation(); break; } } } } private void ServerBeginDetonation() { if (!detonating) { TurtleNet.SendDetonate(((NetworkBehaviour)this).NetworkObjectId); BeginDetonationLocal(); ((MonoBehaviour)this).StartCoroutine(ServerCleanup()); } } public void BeginDetonationLocal() { if (!detonating) { detonating = true; ((MonoBehaviour)this).StartCoroutine(ExplodeAfterFuse()); } } private IEnumerator ExplodeAfterFuse() { yield return (object)new WaitForSeconds(TurtleConfig.ExplosionDelay.Value); Explode(); } private void Explode() { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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) Vector3 val = ((Component)this).transform.position + Vector3.up * 0.5f; if ((Object)(object)visual != (Object)null) { ((Component)visual).gameObject.SetActive(false); } PlayBoom(val); SpawnExplosionVisual(val); Landmine.SpawnExplosion(val, false, TurtleConfig.KillRange.Value, TurtleConfig.DamageRange.Value, TurtleConfig.ExplosionDamage.Value, 0f, (GameObject)null, false); } private static void SpawnExplosionVisual(Vector3 pos) { //IL_005f: 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) GameObject val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.explosionPrefab : null); if (!((Object)(object)val == (Object)null)) { Transform val2 = (((Object)(object)RoundManager.Instance != (Object)null && (Object)(object)RoundManager.Instance.mapPropsContainer != (Object)null) ? RoundManager.Instance.mapPropsContainer.transform : null); GameObject val3 = Object.Instantiate<GameObject>(val, pos, Quaternion.Euler(-90f, 0f, 0f), val2); val3.SetActive(true); AudioSource[] componentsInChildren = val3.GetComponentsInChildren<AudioSource>(true); foreach (AudioSource val4 in componentsInChildren) { val4.playOnAwake = false; val4.Stop(); val4.mute = true; val4.volume = 0f; ((Behaviour)val4).enabled = false; } Object.Destroy((Object)(object)val3, 10f); } } private static void PlayBoom(Vector3 pos) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) AudioClip boomClip = Plugin.BoomClip; if (!((Object)(object)boomClip == (Object)null)) { GameObject val = new GameObject("TurtleBoomSfx"); val.transform.position = pos; AudioSource val2 = val.AddComponent<AudioSource>(); val2.clip = boomClip; val2.spatialBlend = 1f; val2.dopplerLevel = 0f; val2.rolloffMode = (AudioRolloffMode)1; val2.minDistance = 10f; val2.maxDistance = TurtleConfig.BoomMaxDistance.Value; val2.volume = TurtleConfig.BoomVolume.Value; val2.outputAudioMixerGroup = GameRefs.EnemySfxGroup; val2.Play(); Object.Destroy((Object)(object)val, boomClip.length + 0.5f); } } private IEnumerator ServerCleanup() { yield return (object)new WaitForSeconds(TurtleConfig.ExplosionDelay.Value + 0.6f); if (!((Object)(object)this == (Object)null)) { ((EnemyAI)this).KillEnemyOnOwnerClient(true); yield return (object)new WaitForSeconds(1f); if ((Object)(object)this != (Object)null && ((NetworkBehaviour)this).IsServer && (Object)(object)((NetworkBehaviour)this).NetworkObject != (Object)null && ((NetworkBehaviour)this).NetworkObject.IsSpawned) { ((NetworkBehaviour)this).NetworkObject.Despawn(true); } } } private float NextHelloDelay() { float num = Mathf.Max(1f, TurtleConfig.HelloIntervalMin.Value); float num2 = Mathf.Max(num, TurtleConfig.HelloIntervalMax.Value); return num + (float)helloRng.NextDouble() * (num2 - num); } private void TickHello(float dt) { if (!detonating && !((Object)(object)base.creatureVoice == (Object)null) && !((Object)(object)Plugin.HelloClip == (Object)null)) { helloTimer += dt; if (!(helloTimer < nextHello)) { helloTimer = 0f; nextHello = NextHelloDelay(); GameRefs.CopyVoiceRange(base.creatureVoice); base.creatureVoice.PlayOneShot(Plugin.HelloClip, TurtleConfig.HelloVolume.Value); } } } private void CacheParts() { //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_019b: Unknown result type (might be due to invalid IL or missing references) parts.Clear(); headPart = null; shellPart = null; if ((Object)(object)visual == (Object)null) { return; } int num = 0; foreach (Transform item2 in from x in ((Component)visual).GetComponentsInChildren<Transform>(true) orderby ((Object)x).name select x) { string text = ((Object)item2).name.ToLowerInvariant(); PartKind? partKind = null; if (text.Contains("head")) { partKind = PartKind.Head; } else if (text.Contains("eye") || text.Contains("mouth")) { partKind = PartKind.HeadAttached; } else if (text.Contains("neck")) { partKind = PartKind.Neck; } else if (text.Contains("shell")) { partKind = PartKind.Shell; } else if (text.Contains("button")) { partKind = PartKind.ShellAttached; } else if (text.Contains("feet") || text.Contains("foot") || text.Contains("leg")) { partKind = PartKind.Foot; } if (partKind.HasValue) { Part item = new Part { t = item2, basePos = item2.localPosition, baseRot = item2.localRotation, kind = partKind.Value, offset = ((partKind.Value == PartKind.Foot) ? ((float)(num++ % 2) * MathF.PI) : 0f) }; parts.Add(item); if (partKind == PartKind.Head && headPart == null) { headPart = item; } if (partKind == PartKind.Shell && shellPart == null) { shellPart = item; } } } if (headPart != null) { parts.RemoveAll((Part p) => p.kind == PartKind.HeadAttached && p.t.IsChildOf(headPart.t)); } } public void OnDamaged() { if (((NetworkBehaviour)this).IsServer && !base.isEnemyDead && !detonating) { ServerBeginDetonation(); } } private void TickWalkAnimation(float dt) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: 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_0206: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_03de: 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_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_028d: 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_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: 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_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: 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_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: 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_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0404: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_046f: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_0422: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0426: 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_0432: 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_04fa: Unknown result type (might be due to invalid IL or missing references) //IL_0501: Unknown result type (might be due to invalid IL or missing references) //IL_0506: Unknown result type (might be due to invalid IL or missing references) //IL_050b: Unknown result type (might be due to invalid IL or missing references) //IL_0512: Unknown result type (might be due to invalid IL or missing references) //IL_0517: Unknown result type (might be due to invalid IL or missing references) //IL_0396: 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_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Unknown result type (might be due to invalid IL or missing references) if (parts.Count == 0 || dt <= 0f) { return; } Vector3 position = ((Component)this).transform.position; Vector3 val = position - lastPos; float num = ((Vector3)(ref val)).magnitude / dt; lastPos = position; bool flag = (phase == Phase.Targeting || phase == Phase.Roaming) && num > 0.15f && !detonating; walkBlend = Mathf.MoveTowards(walkBlend, flag ? 1f : 0f, dt * 4f); if (walkBlend <= 0.001f && !flag) { foreach (Part part in parts) { part.t.localPosition = part.basePos; part.t.localRotation = part.baseRot; } return; } walkClock += dt * TurtleConfig.WalkCycleSpeed.Value; float num2 = TurtleConfig.HeadSwayDegrees.Value * walkBlend; float num3 = TurtleConfig.ShellRockDegrees.Value * walkBlend; float num4 = TurtleConfig.FootSwayFraction.Value * walkBlend; Quaternion val2 = Quaternion.AngleAxis(Mathf.Sin(walkClock) * num2, Vector3.up) * Quaternion.AngleAxis(Mathf.Sin(walkClock + MathF.PI / 2f) * num2 * 0.4f, Vector3.forward); Quaternion val3 = Quaternion.AngleAxis(Mathf.Sin(walkClock) * num3, Vector3.forward) * Quaternion.AngleAxis(Mathf.Sin(walkClock * 2f) * num3 * 0.4f, Vector3.right); Vector3 val4 = ((shellPart != null) ? shellPart.basePos : Vector3.zero); bool flag2 = shellPart != null; foreach (Part part2 in parts) { switch (part2.kind) { case PartKind.Shell: part2.t.localRotation = val3 * part2.baseRot; break; case PartKind.ShellAttached: part2.t.localPosition = val4 + val3 * (part2.basePos - val4); part2.t.localRotation = val3 * part2.baseRot; break; case PartKind.Head: { Vector3 localPosition = (flag2 ? (val4 + val3 * (part2.basePos - val4)) : part2.basePos); part2.t.localPosition = localPosition; part2.t.localRotation = val3 * val2 * part2.baseRot; break; } case PartKind.HeadAttached: { Vector3 val5 = ((headPart != null) ? headPart.basePos : part2.basePos); Vector3 val6 = val5 + val2 * (part2.basePos - val5); if (flag2) { val6 = val4 + val3 * (val6 - val4); } part2.t.localPosition = val6; part2.t.localRotation = val3 * val2 * part2.baseRot; break; } case PartKind.Neck: { Quaternion val7 = Quaternion.AngleAxis(Mathf.Sin(walkClock) * num2 * 0.5f, Vector3.up); part2.t.localPosition = (flag2 ? (val4 + val3 * (part2.basePos - val4)) : part2.basePos); part2.t.localRotation = val3 * val7 * part2.baseRot; break; } case PartKind.Foot: { float num5 = Mathf.Max(0.0001f, ((Object)(object)part2.t.parent != (Object)null) ? part2.t.parent.lossyScale.y : 1f); float num6 = TurtleConfig.PlayerHeight.Value * TurtleConfig.SizeFraction.Value; float num7 = Mathf.Sin(walkClock + part2.offset) * num4 * num6 / num5; float num8 = Mathf.Max(0f, Mathf.Cos(walkClock + part2.offset)) * TurtleConfig.FootLiftFraction.Value * num6 * walkBlend / num5; part2.t.localPosition = part2.basePos + Vector3.forward * num7 + Vector3.up * num8; break; } } } } } internal static class TurtleConfig { public static ConfigEntry<float> PlayerHeight; public static ConfigEntry<float> SizeFraction; public static ConfigEntry<float> ModelYaw; public static ConfigEntry<float> RoamSeconds; public static ConfigEntry<float> StillSeconds; public static ConfigEntry<float> TargetSeconds; public static ConfigEntry<float> RoamSpeed; public static ConfigEntry<float> TargetSpeedOverride; public static ConfigEntry<float> TargetSpeedFallback; public static ConfigEntry<float> ExplosionDelay; public static ConfigEntry<int> ExplosionDamage; public static ConfigEntry<float> KillRange; public static ConfigEntry<float> DamageRange; public static ConfigEntry<float> StepRadius; public static ConfigEntry<float> StepHeight; public static ConfigEntry<float> BoomMaxDistance; public static ConfigEntry<float> BoomVolume; public static ConfigEntry<float> HelloIntervalMin; public static ConfigEntry<float> HelloIntervalMax; public static ConfigEntry<float> HelloVolume; public static ConfigEntry<float> HelloRangeFallback; public static ConfigEntry<int> RarityOverride; public static ConfigEntry<int> FallbackRarity; public static ConfigEntry<float> PowerLevel; public static ConfigEntry<int> MaxCount; public static ConfigEntry<float> RarityMultiplier; public static ConfigEntry<float> HeadSwayDegrees; public static ConfigEntry<float> FootSwayFraction; public static ConfigEntry<float> FootLiftFraction; public static ConfigEntry<float> ShellRockDegrees; public static ConfigEntry<float> WalkCycleSpeed; public static void Bind(ConfigFile c) { PlayerHeight = c.Bind<float>("Size", "PlayerHeight", 2f, "Height of a standing player in Unity units. Turtle height = this x SizeFraction."); SizeFraction = c.Bind<float>("Size", "SizeFraction", 0.2f, "1/5 of a player = 0.2"); ModelYaw = c.Bind<float>("Size", "ModelYawOffset", 0f, "Degrees to rotate the model around Y if it faces the wrong way (try 90, 180, 270)."); RoamSeconds = c.Bind<float>("Phases", "RoamSeconds", 25f, "Phase 1: how long the turtle wanders before standing still (+/-10% random)."); StillSeconds = c.Bind<float>("Phases", "StillSeconds", 35f, "Phase 1: how long the turtle stands its ground (+/-10% random)."); TargetSeconds = c.Bind<float>("Phases", "TargetSeconds", 90f, "Phase 2: how long it hunts before giving up (1:30)."); RoamSpeed = c.Bind<float>("Phases", "RoamSpeed", 1.2f, "Walking speed while roaming (Phase 1)."); TargetSpeedOverride = c.Bind<float>("Phases", "TargetSpeedOverride", -1f, "Phase 2 speed. -1 = copy the Hydrogere's speed automatically."); TargetSpeedFallback = c.Bind<float>("Phases", "TargetSpeedFallback", 3.5f, "Phase 2 speed used if the Hydrogere's speed can't be read (check the log line 'Hydrogere speed')."); ExplosionDelay = c.Bind<float>("Explosion", "DelaySeconds", 0.3f, "Time between being stepped on and the explosion."); ExplosionDamage = c.Bind<int>("Explosion", "Damage", 120, "Damage dealt to players inside the damage range (players have 100 HP)."); KillRange = c.Bind<float>("Explosion", "KillRange", 5.7f, "Landmine default is 5.7."); DamageRange = c.Bind<float>("Explosion", "DamageRange", 6f, "Landmine default is 6 (the game caps the search at 6)."); StepRadius = c.Bind<float>("Explosion", "StepRadius", 0.55f, "Horizontal distance (feet to turtle) that counts as 'stepped on'."); StepHeight = c.Bind<float>("Explosion", "StepHeight", 0.7f, "How high above the turtle a player's feet can be and still count. Jumping higher clears it."); BoomMaxDistance = c.Bind<float>("Explosion", "BoomMaxDistance", 80f, "Max distance the boom can be heard from."); BoomVolume = c.Bind<float>("Explosion", "BoomVolume", 1.2f, "Volume of boom.m4a/wav."); HelloIntervalMin = c.Bind<float>("Hello", "IntervalMinSeconds", 15f, "Shortest gap between hello sounds while the turtle is alive in the facility."); HelloIntervalMax = c.Bind<float>("Hello", "IntervalMaxSeconds", 20f, "Longest gap between hello sounds (each gap is random between min and max)."); HelloVolume = c.Bind<float>("Hello", "Volume", 1f, "Volume of the hello sound."); HelloRangeFallback = c.Bind<float>("Hello", "RangeFallback", 30f, "Used only if the real proximity-chat range can't be read from a player."); RarityOverride = c.Bind<int>("Spawning", "RarityOverride", -1, "-1 = copy the Thumper's rarity on each moon. 0 or more = force this rarity everywhere (e.g. 500 to test)."); PowerLevel = c.Bind<float>("Spawning", "PowerLevel", 1f, "Spawn power (enemy budget) each turtle uses. Thumper is 3. Lower = more turtles fit."); MaxCount = c.Bind<int>("Spawning", "MaxCount", 3, "Most turtles that can exist at the same time."); RarityMultiplier = c.Bind<float>("Spawning", "RarityMultiplier", 2f, "Multiplies the Thumper's rarity on each moon. 2 = twice as likely to be picked."); FallbackRarity = c.Bind<int>("Spawning", "FallbackRarity", 3, "Rarity on moons that don't list a Thumper."); HeadSwayDegrees = c.Bind<float>("Animation", "HeadSwayDegrees", 16f, "Side-to-side head swing while hunting."); FootSwayFraction = c.Bind<float>("Animation", "FootSwayFraction", 0.18f, "How far each foot swings forward/back, as a fraction of turtle height."); FootLiftFraction = c.Bind<float>("Animation", "FootLiftFraction", 0.08f, "How far each foot lifts off the ground mid-step, as a fraction of turtle height."); ShellRockDegrees = c.Bind<float>("Animation", "ShellRockDegrees", 5f, "How far the shell rocks side to side while walking (0 = off)."); WalkCycleSpeed = c.Bind<float>("Animation", "WalkCycleSpeed", 7f, "Speed of the sway cycle."); } } [HarmonyPatch(typeof(EnemyAI), "HitEnemy")] internal static class TurtleHitPatch { [HarmonyPostfix] private static void Postfix(EnemyAI __instance) { TurtleAI turtleAI = __instance as TurtleAI; if ((Object)(object)turtleAI != (Object)null) { turtleAI.OnDamaged(); } } } internal static class TurtleNet { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__Handle; } private const string MsgName = "ExplodingTurtle.Msg"; public const byte KindPhase = 0; public const byte KindDetonate = 1; public static void EnsureRegistered() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null) { CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager; object obj = <>O.<0>__Handle; if (obj == null) { HandleNamedMessageDelegate val = Handle; <>O.<0>__Handle = val; obj = (object)val; } customMessagingManager.RegisterNamedMessageHandler("ExplodingTurtle.Msg", (HandleNamedMessageDelegate)obj); } } public static void SendPhase(ulong netId, byte phase) { Send(0, netId, phase); } public static void SendDetonate(ulong netId) { Send(1, netId, 0); } private unsafe static void Send(byte kind, ulong netId, byte arg) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsServer || singleton.CustomMessagingManager == null) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref kind, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref netId, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref arg, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessageToAll("ExplodingTurtle.Msg", val, (NetworkDelivery)2); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } private static void Handle(ulong senderClientId, FastBufferReader reader) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) byte b = default(byte); ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives)); ulong key = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives)); byte p = default(byte); ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref p, default(ForPrimitives)); NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.SpawnManager.SpawnedObjects.TryGetValue(key, out var value)) { return; } TurtleAI component = ((Component)value).GetComponent<TurtleAI>(); if (!((Object)(object)component == (Object)null)) { switch (b) { case 0: component.ApplyPhaseOnClient((TurtleAI.Phase)p); break; case 1: component.BeginDetonationLocal(); break; } } } } [HarmonyPatch(typeof(RoundManager), "LoadNewLevel")] internal static class TurtleSpawnSync { [HarmonyPrefix] private static void Prefix(object[] __args) { SelectableLevel val = __args.OfType<SelectableLevel>().FirstOrDefault(); if ((Object)(object)val != (Object)null) { Sync(val); } } internal static void Sync(SelectableLevel level) { //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown EnemyType turtle = Plugin.TurtleType; if ((Object)(object)turtle == (Object)null || level.Enemies == null) { return; } SpawnableEnemyWithRarity val = ((IEnumerable<SpawnableEnemyWithRarity>)level.Enemies).FirstOrDefault((Func<SpawnableEnemyWithRarity, bool>)((SpawnableEnemyWithRarity e) => e != null && (Object)(object)e.enemyType != (Object)null && e.enemyType.enemyName == "Crawler")); if (val != null) { EnemyType enemyType = val.enemyType; if (enemyType.probabilityCurve != null) { turtle.probabilityCurve = enemyType.probabilityCurve; } } turtle.PowerLevel = TurtleConfig.PowerLevel.Value; turtle.MaxCount = TurtleConfig.MaxCount.Value; int num = ((TurtleConfig.RarityOverride.Value >= 0) ? TurtleConfig.RarityOverride.Value : ((val != null) ? Mathf.Max(1, Mathf.RoundToInt((float)val.rarity * TurtleConfig.RarityMultiplier.Value)) : TurtleConfig.FallbackRarity.Value)); SpawnableEnemyWithRarity val2 = ((IEnumerable<SpawnableEnemyWithRarity>)level.Enemies).FirstOrDefault((Func<SpawnableEnemyWithRarity, bool>)((SpawnableEnemyWithRarity e) => e != null && (Object)(object)e.enemyType == (Object)(object)turtle)); if (val2 == null) { level.Enemies.Add(new SpawnableEnemyWithRarity(turtle, num)); } else { val2.rarity = num; } Plugin.Log.LogInfo((object)("Turtle on '" + level.PlanetName + "': rarity " + num + ((val != null) ? " (copied from Thumper)" : " (no Thumper here, fallback)"))); } } }