using System; using System.Collections; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [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: AssemblyCompany("MyFirstMod")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0")] [assembly: AssemblyProduct("MyFirstMod")] [assembly: AssemblyTitle("MyFirstMod")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/wokajing/MyFirstMod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace MyFirstMod { [BepInPlugin("io.github.wokajing.toremaincalm", "ToRemainCalm", "1.0.0")] public class MyFirstModPlugin : BaseUnityPlugin { internal static MyFirstModPlugin Instance; public static ConfigEntry ModEnabled { get; private set; } public static ConfigEntry ToggleKey { get; private set; } private void Awake() { //IL_0042: 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_009c: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Expected O, but got Unknown Instance = this; ModEnabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "是否启用模组功能"); ToggleKey = ((BaseUnityPlugin)this).Config.Bind("General", "Toggle Key", new KeyboardShortcut((KeyCode)283, Array.Empty()), "切换模组启用状态的快捷键"); Log($"Plugin {((BaseUnityPlugin)this).Info.Metadata.Name} loaded! (Enabled: {ModEnabled.Value})"); Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); MethodInfo methodInfo = AccessTools.Method(typeof(ObjectPool), "Spawn", new Type[4] { typeof(GameObject), typeof(Transform), typeof(Vector3), typeof(Quaternion) }, (Type[])null); if (methodInfo != null) { val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "OnProjectileSpawnedPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log("Patched ObjectPool.Spawn"); } else { Log("Failed to find ObjectPool.Spawn"); } } private void Update() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = ToggleKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { ModEnabled.Value = !ModEnabled.Value; Log("模组已" + (ModEnabled.Value ? "启用" : "禁用")); } } public static void Log(string msg) { MyFirstModPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)msg); } } public static void StartCoroutineOnInstance(IEnumerator coroutine) { try { if ((Object)(object)Instance != (Object)null && ModEnabled.Value) { ((MonoBehaviour)Instance).StartCoroutine(coroutine); } } catch (Exception arg) { Log($"StartCoroutine error: {arg}"); } } } public static class Patches { public static void OnProjectileSpawnedPostfix(GameObject __result) { if (!MyFirstModPlugin.ModEnabled.Value) { return; } try { if (!((Object)(object)__result == (Object)null) && (Object)(object)__result.GetComponent() == (Object)null) { __result.AddComponent(); MyFirstModPlugin.Log("Added AirSteering to " + ((Object)__result).name); } } catch (Exception arg) { MyFirstModPlugin.Log($"OnProjectileSpawnedPostfix error: {arg}"); } } } public class AirSteering : MonoBehaviour { private Rigidbody2D? rb; private float angleTimer = 0f; private float targetAngle = 0f; private float currentAngle = 0f; private float angularSpeed = 0f; private bool isReady = false; private float minTurnInterval = 0.2f; private float maxTurnInterval = 1.2f; private float minAngularSpeed = 100f; private float maxAngularSpeed = 400f; private void Awake() { rb = ((Component)this).GetComponent(); if ((Object)(object)rb == (Object)null) { ((Behaviour)this).enabled = false; MyFirstModPlugin.Log("AirSteering: no Rigidbody2D on " + ((Object)((Component)this).gameObject).name + ", disabled."); } } private void Start() { if ((Object)(object)rb != (Object)null) { MyFirstModPlugin.StartCoroutineOnInstance(InitializeLater()); } } private IEnumerator InitializeLater() { int frameCount = 0; Vector2? lastDir = null; Vector2 linearVelocity; while (frameCount < 10) { yield return null; int num; if (!((Object)(object)rb == (Object)null)) { linearVelocity = rb.linearVelocity; num = ((((Vector2)(ref linearVelocity)).magnitude < 0.01f) ? 1 : 0); } else { num = 1; } if (num != 0) { frameCount++; continue; } linearVelocity = rb.linearVelocity; Vector2 currentDir = ((Vector2)(ref linearVelocity)).normalized; if (lastDir.HasValue) { float angleChange = Vector2.Angle(lastDir.Value, currentDir); if (angleChange < 5f) { break; } } lastDir = currentDir; frameCount++; } int num2; if (!((Object)(object)rb == (Object)null)) { linearVelocity = rb.linearVelocity; num2 = ((((Vector2)(ref linearVelocity)).magnitude < 0.01f) ? 1 : 0); } else { num2 = 1; } if (num2 != 0) { MyFirstModPlugin.Log("AirSteering: " + ((Object)((Component)this).gameObject).name + " no velocity, disabling."); ((Behaviour)this).enabled = false; yield break; } linearVelocity = rb.linearVelocity; Vector2 finalDir = ((Vector2)(ref linearVelocity)).normalized; rb.gravityScale = 0f; linearVelocity = rb.linearVelocity; float originalSpeed = ((Vector2)(ref linearVelocity)).magnitude; float newSpeed = originalSpeed * 0.75f; rb.linearVelocity = finalDir * newSpeed; MyFirstModPlugin.Log($"Slowed {((Object)((Component)this).gameObject).name} to {newSpeed:F1}"); currentAngle = Mathf.Atan2(rb.linearVelocity.y, rb.linearVelocity.x) * 57.29578f; GenerateNewTurn(); isReady = true; MyFirstModPlugin.Log("AirSteering ready for " + ((Object)((Component)this).gameObject).name); } private void FixedUpdate() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) if (!MyFirstModPlugin.ModEnabled.Value) { ((Behaviour)this).enabled = false; } else { if (!isReady || (Object)(object)rb == (Object)null) { return; } Vector2 linearVelocity = rb.linearVelocity; if (((Vector2)(ref linearVelocity)).magnitude < 0.01f) { return; } try { angleTimer -= Time.fixedDeltaTime; if (angleTimer <= 0f) { GenerateNewTurn(); } float num = angularSpeed * Time.fixedDeltaTime; float num2 = Mathf.DeltaAngle(currentAngle, targetAngle); num = ((!(Mathf.Abs(num2) < Mathf.Abs(num))) ? (Mathf.Sign(num2) * Mathf.Min(Mathf.Abs(num), Mathf.Abs(num2))) : num2); currentAngle += num; Vector2 val = Vector2.op_Implicit(Quaternion.Euler(0f, 0f, currentAngle) * Vector2.op_Implicit(Vector2.right)); Rigidbody2D? obj = rb; linearVelocity = rb.linearVelocity; obj.linearVelocity = val * ((Vector2)(ref linearVelocity)).magnitude; } catch (Exception arg) { MyFirstModPlugin.Log($"AirSteering.FixedUpdate error: {arg}"); ((Behaviour)this).enabled = false; } } } private void GenerateNewTurn() { try { targetAngle = Random.Range(-180f, 180f); float num = Random.Range(minTurnInterval, maxTurnInterval); float num2 = Mathf.DeltaAngle(currentAngle, targetAngle); float num3 = Mathf.Abs(num2) / num; angularSpeed = Mathf.Clamp(num3, minAngularSpeed, maxAngularSpeed); if (num3 > maxAngularSpeed) { num = Mathf.Abs(num2) / maxAngularSpeed; angularSpeed = maxAngularSpeed; } if (num < minTurnInterval) { num = minTurnInterval; } angleTimer = num; } catch (Exception arg) { MyFirstModPlugin.Log($"GenerateNewTurn error: {arg}"); } } } }