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 MCMaceMod v1.0.1
Mace.dll
Decompiled an hour ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("Luca")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Mace weapon for R.E.P.O.")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0+33734e01256d5a2ccefcde59aeb451a78119049b")] [assembly: AssemblyProduct("Mace")] [assembly: AssemblyTitle("Mace")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Mace { public static class MaceBalance { internal const float DefaultSecondKneeDamage = 500f; internal const float DefaultSecondKneeSlopeScale = 0.5f; internal static void ResolveSecondKnee(float rawSecondKneeDamage, float rawSecondKneeSlopeScale, out float secondKneeDamage, out float secondKneeSlopeScale) { if (rawSecondKneeDamage == 0f && rawSecondKneeSlopeScale == 0f) { secondKneeDamage = 500f; secondKneeSlopeScale = 0.5f; } else { secondKneeDamage = rawSecondKneeDamage; secondKneeSlopeScale = rawSecondKneeSlopeScale; } } public static int ComputeDamage(float height, MaceSettings settings) { if ((Object)(object)settings == (Object)null) { return 0; } return ComputeDamage(height, settings, settings.baseDamage); } public static int ComputeDamage(float height, MaceSettings settings, int baseDamage) { if ((Object)(object)settings == (Object)null) { return 0; } float deadHeight = settings.deadHeight; float damagePerMeter = settings.damagePerMeter; int kneeDamage = settings.kneeDamage; float postKneeSlopeScale = settings.postKneeSlopeScale; ResolveSecondKnee(settings.secondKneeDamage, settings.secondKneeSlopeScale, out var secondKneeDamage, out var secondKneeSlopeScale); if (!IsFinite(height) || !IsFinite(deadHeight) || !IsFinite(damagePerMeter) || !IsFinite(postKneeSlopeScale)) { return baseDamage; } if (damagePerMeter <= 0f || kneeDamage <= baseDamage) { return baseDamage; } if (height <= deadHeight) { return baseDamage; } float num = deadHeight + (float)(((double)kneeDamage - (double)baseDamage) / (double)damagePerMeter); if (height <= num) { double value = (double)baseDamage + (double)damagePerMeter * (double)(height - deadHeight); return RoundToInt(value); } float num2 = ((postKneeSlopeScale > 0f) ? postKneeSlopeScale : 0f); double num3 = (double)damagePerMeter * (double)num2; bool flag = num3 > 0.0 && IsFinite(secondKneeDamage) && secondKneeDamage > (float)kneeDamage && IsFinite(secondKneeSlopeScale) && secondKneeSlopeScale >= 0f; double num4 = (flag ? ((double)num + ((double)secondKneeDamage - (double)kneeDamage) / num3) : double.NaN); double num5 = (flag ? (num3 * (double)secondKneeSlopeScale) : 0.0); double value2 = ((flag && !((double)height <= num4)) ? ((double)secondKneeDamage + num5 * ((double)height - num4)) : ((double)kneeDamage + num3 * (double)(height - num))); return RoundToInt(value2); } internal static bool TryComputeKneeInfo(MaceSettings settings, int baseDamage, out float kneeHeight, out float postKneeSlope, out float secondKneeDamage, out float secondKneeSlopeScale, out float secondKneeHeight, out float secondKneeSlope) { kneeHeight = float.NaN; postKneeSlope = float.NaN; secondKneeDamage = float.NaN; secondKneeSlopeScale = float.NaN; secondKneeHeight = float.NaN; secondKneeSlope = float.NaN; if ((Object)(object)settings == (Object)null) { return false; } float deadHeight = settings.deadHeight; float damagePerMeter = settings.damagePerMeter; int kneeDamage = settings.kneeDamage; float postKneeSlopeScale = settings.postKneeSlopeScale; ResolveSecondKnee(settings.secondKneeDamage, settings.secondKneeSlopeScale, out secondKneeDamage, out secondKneeSlopeScale); if (!IsFinite(deadHeight) || !IsFinite(damagePerMeter) || !IsFinite(postKneeSlopeScale)) { return false; } if (damagePerMeter <= 0f || kneeDamage <= baseDamage) { return false; } kneeHeight = deadHeight + (float)(((double)kneeDamage - (double)baseDamage) / (double)damagePerMeter); float num = ((postKneeSlopeScale > 0f) ? postKneeSlopeScale : 0f); double num2 = (double)damagePerMeter * (double)num; postKneeSlope = (float)num2; if (num2 > 0.0 && IsFinite(secondKneeDamage) && secondKneeDamage > (float)kneeDamage && IsFinite(secondKneeSlopeScale) && secondKneeSlopeScale >= 0f) { secondKneeHeight = (float)((double)kneeHeight + ((double)secondKneeDamage - (double)kneeDamage) / num2); secondKneeSlope = (float)(num2 * (double)secondKneeSlopeScale); } return true; } public static bool IsSpecial(int damage, MaceSettings settings) { if ((Object)(object)settings != (Object)null) { return damage > settings.baseDamage; } return false; } public static bool IsSpecial(int damage, MaceSettings settings, int baseDamage) { if ((Object)(object)settings != (Object)null) { return damage > baseDamage; } return false; } public static int CostBars(int damage, MaceSettings settings) { if ((Object)(object)settings == (Object)null) { return 0; } if (damage <= settings.heavyCostDamageThreshold) { return settings.normalCostBars; } return settings.heavyCostBars; } private static bool IsFinite(float value) { if (!float.IsNaN(value)) { return !float.IsInfinity(value); } return false; } private static int RoundToInt(double value) { if (double.IsNaN(value)) { return 0; } if (value >= 2147483647.0) { return int.MaxValue; } if (value <= -2147483648.0) { return int.MinValue; } return (int)Math.Round(value, MidpointRounding.AwayFromZero); } } public class MaceBehaviour : MonoBehaviour { private struct RemoteHeight { public float Height; public float Time; } public MaceSettings settings; public Sound critSound; public Sound airHitSound; public Sound smashGroundSound; public Sound smashGroundHeavySound; public GameObject healthyModel; public GameObject brokenModel; public Material[] hitParticleMaterials = (Material[])(object)new Material[0]; public Material[] shockwaveParticleMaterials = (Material[])(object)new Material[0]; public Material[] stunParticleMaterials = (Material[])(object)new Material[0]; [Tooltip("命中粒子粒径下限(米)。非法值回退默认,下限大于上限时自动交换。")] public float hitParticleMinSize = 0.18f; [Tooltip("命中粒子粒径上限(米)。")] public float hitParticleMaxSize = 0.3f; [Tooltip("冲击波粒子粒径下限(米)。非法值回退默认,下限大于上限时自动交换。")] public float shockwaveParticleMinSize = 0.12f; [Tooltip("冲击波粒子粒径上限(米)。")] public float shockwaveParticleMaxSize = 0.24f; [Tooltip("眩晕粒子粒径下限(米)。非法值回退默认,下限大于上限时自动交换。")] public float stunParticleMinSize = 0.12f; [Tooltip("眩晕粒子粒径上限(米)。")] public float stunParticleMaxSize = 0.2f; public int hitParticleCount = 20; [Tooltip("冲击波粒子数量(颗);<=0 跳过冲击波效果。密度越高越有冲击力,可按需调高。")] public int shockwaveParticleCount = 128; [Tooltip("冲击波内径(米):环形粒子分布的内边界,相对特效中心。")] public float shockwaveParticleInnerRadius = 4f; [Tooltip("冲击波外径(米):环形粒子分布的外边界,相对特效中心。")] public float shockwaveParticleOuterRadius = 8f; [Tooltip("冲击波高度下限(米):粒子相对特效中心的垂直位置最小值。")] public float shockwaveParticleMinHeight; [Tooltip("冲击波高度上限(米):粒子相对特效中心的垂直位置最大值。")] public float shockwaveParticleMaxHeight = 1.2f; public int stunParticleCount = 10; public float particleLifetime = 3f; internal const int HeavySmashThreshold = 250; private const float MinHeightReportInterval = 0.05f; private const float NoFallTime = -9999f; private const float DefaultSwingContinuationGrace = 0.3f; private const float DefaultAirHitClearanceThreshold = 0.5f; private const string HealthyModelName = "Mace Healthy"; private const string BrokenModelName = "Mace Broken"; private int _groundLayerMask; private readonly Collider[] _groundOverlaps = (Collider[])(object)new Collider[32]; private readonly RaycastHit[] _groundHits = (RaycastHit[])(object)new RaycastHit[32]; private static readonly Dictionary<HurtCollider, MaceBehaviour> ByHurtCollider = new Dictionary<HurtCollider, MaceBehaviour>(8); private static readonly Dictionary<ItemMelee, MaceBehaviour> ByItemMelee = new Dictionary<ItemMelee, MaceBehaviour>(8); private ItemMelee _itemMelee; private ItemBattery _itemBattery; private PhysGrabObject _physGrabObject; private PhotonView _photonView; private HurtCollider[] _hurtColliders; private bool _modelStateInitialized; private bool _modelStateBroken; private bool _hitVisualDiagnosed; private bool _missingParticleMaterialWarned; private bool _missingBrokenModelWarned; private bool _modelFallbackWarned; private bool _disabled; private bool _initialized; private bool _damageLocked; private int _lockedDamage; private float _lockedHeight; private float _lockedEffectiveHeight; private float _lockedTargetClearance; private bool _lockedIsAirHit; private bool _lockedClearanceValid; private PlayerAvatar _lockedAttacker; private bool _swingHitConsumed; private bool _swingCostConsumed; private bool _swingShockwaveDone; private bool _airborne; private float _airPeakY; private float _currentTotalDrop; private float _lastTotalDrop; private float _lastTotalDropTime = -9999f; private float _swingDrop; private bool _swingSessionActive; private float _lastSwingExitTime = -9999f; private bool _hasSwingExited; private int _swingSeq; private bool _swingContinued; private float _swingIdleGap = float.NaN; private float _nextHeightReportTime; private readonly Dictionary<int, RemoteHeight> _remoteHeights = new Dictionary<int, RemoteHeight>(4); private readonly List<Vector3> _stunParticlePositions = new List<Vector3>(8); public MaceSettings Settings => settings; internal int EffectiveBaseDamage => Plugin.ResolveBaseDamage(settings); internal int SwingSeq => _swingSeq; internal bool SwingContinued => _swingContinued; internal float SwingIdleGap => _swingIdleGap; public float LockedHeight => _lockedHeight; public float LockedEffectiveHeight => _lockedEffectiveHeight; public float LockedTargetClearance => _lockedTargetClearance; public bool LockedIsAirHit => _lockedIsAirHit; public bool LockedClearanceValid => _lockedClearanceValid; public PlayerAvatar LockedAttacker => _lockedAttacker; private void Awake() { _groundLayerMask = LayerMask.GetMask(new string[3] { "Default", "NavmeshOnly", "PlayerOnlyCollision" }); _itemMelee = ((Component)this).GetComponent<ItemMelee>(); _itemBattery = ((Component)this).GetComponent<ItemBattery>(); _physGrabObject = ((Component)this).GetComponent<PhysGrabObject>(); _photonView = ((Component)this).GetComponent<PhotonView>(); _hurtColliders = ((Component)this).GetComponentsInChildren<HurtCollider>(true); if ((Object)(object)settings == (Object)null) { Fail("缺少 MaceSettings 资产引用:请在 Unity 中 Create > Mace > Mace Settings 创建资产、填好数值后拖到 MaceBehaviour 的 Settings 字段(旧 prefab 内嵌 settings 已不再使用)。"); return; } if ((Object)(object)_itemMelee == (Object)null) { Fail("缺少 ItemMelee 组件(应挂在 Item Mace 根节点)。"); return; } if ((Object)(object)_physGrabObject == (Object)null) { Fail("缺少 PhysGrabObject 组件(应挂在 Item Mace 根节点)。"); return; } if ((Object)(object)_photonView == (Object)null) { Fail("缺少 PhotonView 组件(应挂在 Item Mace 根节点)。"); return; } if (_hurtColliders == null || _hurtColliders.Length == 0) { Fail("找不到任何 HurtCollider(子物体),Mace 无法命中。"); return; } if (_hurtColliders.Length > 1) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("[Mace] 发现 " + _hurtColliders.Length + " 个 HurtCollider;约定只应有 1 个,全部注册但请检查 prefab。")); } } if ((Object)(object)_itemBattery == (Object)null) { Fail("缺少 ItemBattery 组件(Mace 的扣电依赖 RemoveFullBar)。"); return; } ResolveModelReferencesByName(); ByItemMelee[_itemMelee] = this; for (int i = 0; i < _hurtColliders.Length; i++) { HurtCollider val = _hurtColliders[i]; if ((Object)(object)val != (Object)null) { ByHurtCollider[val] = this; } } _initialized = true; } private void Start() { if (_disabled || (Object)(object)settings == (Object)null || (Object)(object)_itemMelee == (Object)null) { return; } _itemMelee.durabilityDrain = 0f; if (_itemMelee.durabilityDrainOnEnemiesAndPVP > 0f) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("[Mace] ItemMelee.durabilityDrainOnEnemiesAndPVP = " + _itemMelee.durabilityDrainOnEnemiesAndPVP + ";原版 EnemyOrPVPSwingHitRPC 仍会按此扣电,请确认与 RemoveFullBar 的口径一致。")); } } Sound soundHit = _itemMelee.soundHit; if (soundHit == null || soundHit.Sounds == null) { ManualLogSource log2 = Plugin.Log; if (log2 != null) { log2.LogError((object)"[Mace] ItemMelee.soundHit 及其 Sounds 数组不能为 null;不使用原版命中音时请设为空数组。"); } } } private void Update() { if (!_disabled && !((Object)(object)settings == (Object)null)) { SampleLocalFall(); EnforceSwingSessionState(); if (ShouldReportHeight()) { ReportHeightToMaster(); } UpdateBrokenModel(); } } private void OnDestroy() { ForceEndSwingSession(); if (_itemMelee != null && ByItemMelee.TryGetValue(_itemMelee, out var value) && (Object)(object)value == (Object)(object)this) { ByItemMelee.Remove(_itemMelee); } if (_hurtColliders != null) { for (int i = 0; i < _hurtColliders.Length; i++) { HurtCollider val = _hurtColliders[i]; if (val != null && ByHurtCollider.TryGetValue(val, out var value2) && (Object)(object)value2 == (Object)(object)this) { ByHurtCollider.Remove(val); } } } _remoteHeights.Clear(); } public static bool TryGet(HurtCollider hurtCollider, out MaceBehaviour behaviour) { behaviour = null; if ((Object)(object)hurtCollider == (Object)null) { return false; } if (ByHurtCollider.TryGetValue(hurtCollider, out var value)) { if ((Object)(object)value != (Object)null) { behaviour = value; return true; } ByHurtCollider.Remove(hurtCollider); } value = ((Component)hurtCollider).GetComponentInParent<MaceBehaviour>(); if ((Object)(object)value != (Object)null && value._initialized && !value._disabled) { ByHurtCollider[hurtCollider] = value; behaviour = value; return true; } return false; } public static bool TryGet(ItemMelee itemMelee, out MaceBehaviour behaviour) { behaviour = null; if ((Object)(object)itemMelee == (Object)null) { return false; } if (ByItemMelee.TryGetValue(itemMelee, out var value)) { if ((Object)(object)value != (Object)null) { behaviour = value; return true; } ByItemMelee.Remove(itemMelee); } value = ((Component)itemMelee).GetComponent<MaceBehaviour>(); if ((Object)(object)value != (Object)null && value._initialized && !value._disabled) { ByItemMelee[itemMelee] = value; behaviour = value; return true; } return false; } internal void OnMeleeStateApplied(State oldState, State newState) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 if (!_disabled) { if ((int)newState == 2) { EnterSwinging(); } else if ((int)newState == 3 || (int)newState == 4) { ForceEndSwingSession(); } else if ((int)oldState == 2) { LeaveSwinging(); } } } public void BeginSwing() { if (!_disabled && !((Object)(object)settings == (Object)null)) { _damageLocked = false; _lockedDamage = 0; _lockedHeight = 0f; _lockedEffectiveHeight = 0f; _lockedTargetClearance = 0f; _lockedIsAirHit = false; _lockedClearanceValid = false; _lockedAttacker = null; _swingHitConsumed = false; _swingCostConsumed = false; _swingShockwaveDone = false; _swingDrop = 0f; if ((Object)(object)_physGrabObject != (Object)null && _physGrabObject.grabbedLocal) { _swingDrop = GetLocalHeight(); } _swingSeq++; _swingSessionActive = true; _swingContinued = false; _swingIdleGap = (_hasSwingExited ? (Time.time - _lastSwingExitTime) : float.NaN); _hasSwingExited = false; } } private void EnterSwinging() { if (!_swingSessionActive) { float num = ResolveSwingContinuationGrace(); float num2 = (_hasSwingExited ? Mathf.Max(0f, Time.time - _lastSwingExitTime) : float.NaN); if (_hasSwingExited && num2 <= num) { _swingSessionActive = true; _swingContinued = true; _swingIdleGap = num2; _hasSwingExited = false; } else { BeginSwing(); } } } private void LeaveSwinging() { if (_swingSessionActive) { _swingSessionActive = false; _lastSwingExitTime = Time.time; _hasSwingExited = true; } } private void ForceEndSwingSession() { _swingSessionActive = false; _hasSwingExited = false; _lastSwingExitTime = -9999f; } private void EnforceSwingSessionState() { //IL_0015: 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) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Invalid comparison between Unknown and I4 if (!((Object)(object)_itemMelee == (Object)null)) { State currentState = _itemMelee.currentState; if (((int)currentState == 3 || (int)currentState == 4) && (_swingSessionActive || _hasSwingExited)) { ForceEndSwingSession(); } } } private float ResolveSwingContinuationGrace() { if ((Object)(object)settings == (Object)null) { return 0.3f; } float swingContinuationGrace = settings.swingContinuationGrace; if (float.IsNaN(swingContinuationGrace) || float.IsInfinity(swingContinuationGrace)) { return 0.3f; } if (!(swingContinuationGrace < 0f)) { return swingContinuationGrace; } return 0f; } public int GetDamage(PlayerAvatar attacker) { return GetDamage(attacker, null); } public int GetDamage(PlayerAvatar attacker, Enemy target) { if (_disabled || (Object)(object)settings == (Object)null) { return 0; } if (!SemiFunc.IsMasterClientOrSingleplayer()) { return 0; } if (_damageLocked) { return _lockedDamage; } float num = (((Object)(object)attacker != (Object)null && attacker.isLocal) ? GetLocalHeight() : GetRemoteHeight(attacker)); if (!IsFinite(num) || num < 0f) { num = 0f; } float num2 = 0f; bool lockedClearanceValid = false; if ((Object)(object)target != (Object)null && MaceTargetClearance.TryGet(target, settings, _physGrabObject, out var result)) { num2 = result.Clearance; lockedClearanceValid = result.Valid; } if (!IsFinite(num2) || num2 < 0f) { num2 = 0f; } float num3 = num - num2; if (!IsFinite(num3) || num3 < 0f) { num3 = 0f; } int num4 = MaceBalance.ComputeDamage(num3, settings, EffectiveBaseDamage); if (num4 < 0) { num4 = 0; } bool lockedIsAirHit = ResolveIsAirHit(num2, num4); if (settings.debugHeightLogging && !Plugin.DetailedHitLoggingEnabled) { string text = (((Object)(object)attacker != (Object)null) ? ((Object)attacker).name : "<none>"); string text2 = (((Object)(object)attacker != (Object)null && attacker.isLocal) ? "local" : "remote"); MaceBalance.TryComputeKneeInfo(settings, EffectiveBaseDamage, out var _, out var _, out var _, out var _, out var secondKneeHeight, out var _); string text3 = (IsFinite(secondKneeHeight) ? secondKneeHeight.ToString("F2") : "N/A"); string text4 = (IsFinite(secondKneeHeight) ? (num3 > secondKneeHeight).ToString() : "N/A"); ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)("[Mace] 高度结算 attacker=" + text + " source=" + text2 + " rawHeight=" + num.ToString("F2") + " clearance=" + num2.ToString("F2") + " clearanceValid=" + lockedClearanceValid + " effectiveHeight=" + num3.ToString("F2") + " isAirHit=" + lockedIsAirHit + " damage=" + num4 + " secondKneeHeight=" + text3 + " pastSecondKnee=" + text4)); } } _lockedHeight = num; _lockedEffectiveHeight = num3; _lockedTargetClearance = num2; _lockedClearanceValid = lockedClearanceValid; _lockedIsAirHit = lockedIsAirHit; _lockedAttacker = attacker; _lockedDamage = num4; _damageLocked = true; return num4; } private bool ResolveIsAirHit(float clearance, int damage) { if (damage <= EffectiveBaseDamage) { return false; } return clearance > ResolveAirHitClearanceThreshold(); } private float ResolveAirHitClearanceThreshold() { float num = (((Object)(object)settings != (Object)null) ? settings.airHitClearanceThreshold : 0f); if (!IsFinite(num) || num <= 0f) { return 0.5f; } return num; } internal void OnEnemyHurt(Enemy enemy, int damage, MaceHitDiagnostics.HealthSnapshot healthBefore, MaceHitDiagnostics.HealthSnapshot healthAfter) { //IL_00d2: 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) if (_disabled || (Object)(object)settings == (Object)null || (Object)(object)enemy == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer()) { return; } bool detailedHitLoggingEnabled = Plugin.DetailedHitLoggingEnabled; bool heavyCostEnabled = Plugin.HeavyCostEnabled; bool costCapApplied; int num2; if (healthBefore.Valid) { int num = healthBefore.HealthCurrent; costCapApplied = num >= 0 && num < damage; if (num < 0) { num = 0; } else if (num > damage) { num = damage; } num2 = num; } else { num2 = damage; costCapApplied = false; } bool chargedThisHit = false; int num3 = 0; float batteryLifeBefore = 0f; int batteryLifeIntBefore = 0; if (detailedHitLoggingEnabled) { batteryLifeBefore = (((Object)(object)_itemBattery != (Object)null) ? _itemBattery.batteryLife : 0f); batteryLifeIntBefore = (((Object)(object)_itemBattery != (Object)null) ? _itemBattery.batteryLifeInt : 0); } if (!_swingHitConsumed) { _swingHitConsumed = true; PlayHitSound(damage, GetEnemyPoint(enemy), _lockedIsAirHit); } if (!_swingCostConsumed && num2 > 0) { num3 = (heavyCostEnabled ? MaceBalance.CostBars(num2, settings) : settings.normalCostBars); if (num3 > 0 && (Object)(object)_itemBattery != (Object)null) { _itemBattery.RemoveFullBar(num3); } _swingCostConsumed = true; chargedThisHit = num3 > 0; } float batteryLifeAfter = 0f; int batteryLifeIntAfter = 0; if (detailedHitLoggingEnabled) { batteryLifeAfter = (((Object)(object)_itemBattery != (Object)null) ? _itemBattery.batteryLife : 0f); batteryLifeIntAfter = (((Object)(object)_itemBattery != (Object)null) ? _itemBattery.batteryLifeInt : 0); } BroadcastEnemyHitParticle(GetEnemyPoint(enemy)); if (!_swingShockwaveDone && MaceBalance.IsSpecial(damage, settings, EffectiveBaseDamage)) { _swingShockwaveDone = true; ApplyShockwave(enemy); } if (detailedHitLoggingEnabled) { MaceHitDiagnostics.LogEnemyHit(this, enemy, damage, num2, costCapApplied, chargedThisHit, num3, batteryLifeBefore, batteryLifeAfter, batteryLifeIntBefore, batteryLifeIntAfter, healthBefore, healthAfter, _lockedHeight, _lockedTargetClearance, _lockedEffectiveHeight, _lockedIsAirHit, _lockedClearanceValid); } } private void SampleLocalFall() { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Invalid comparison between Unknown and I4 if ((Object)(object)_physGrabObject == (Object)null || !_physGrabObject.grabbedLocal) { return; } PlayerController instance = PlayerController.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.CollisionController == (Object)null) { return; } PlayerCollisionController collisionController = instance.CollisionController; if (SemiFunc.MenuLevel() || ((Object)(object)instance.playerAvatarScript != (Object)null && instance.playerAvatarScript.fallDamageResetState) || instance.featherTimer > 0f || instance.antiGravityTimer > 0f) { ResetLocalDrop(); return; } float num = (((Object)(object)instance.rb != (Object)null) ? instance.rb.linearVelocity.y : 0f); bool grounded = collisionController.Grounded; bool flag = grounded && IsStandingOnEnemy(instance.CollisionGrounded); bool flag2 = !grounded || flag || num > 0.1f; float y = ((Component)collisionController).transform.position.y; if (!flag2) { if (_airborne) { if (TryGetTotalDrop(collisionController, _airPeakY, out var totalDrop)) { _currentTotalDrop = totalDrop; } float time = Time.time; if (time - _lastTotalDropTime > settings.landingGrace || _currentTotalDrop >= _lastTotalDrop) { _lastTotalDrop = _currentTotalDrop; _lastTotalDropTime = time; } if ((Object)(object)_itemMelee != (Object)null && (int)_itemMelee.currentState == 2) { _swingDrop = Mathf.Max(_swingDrop, _lastTotalDrop); } _airborne = false; } } else { if (!_airborne) { _airborne = true; _airPeakY = y; _currentTotalDrop = 0f; } else if (y > _airPeakY) { _airPeakY = y; } _currentTotalDrop = (TryGetTotalDrop(collisionController, _airPeakY, out var totalDrop2) ? totalDrop2 : GetFallDistanceFallback(collisionController)); } } private float GetLocalHeight() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 bool flag = (Object)(object)_itemMelee != (Object)null && (int)_itemMelee.currentState == 2; if (_airborne) { if (!flag) { return _currentTotalDrop; } return Mathf.Max(_swingDrop, _currentTotalDrop); } PlayerController instance = PlayerController.instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.CollisionController != (Object)null && !instance.CollisionController.Grounded) { float fallDistanceFallback = GetFallDistanceFallback(instance.CollisionController); if (!flag) { return fallDistanceFallback; } return Mathf.Max(_swingDrop, fallDistanceFallback); } if (flag) { float num = ((Time.time - _lastTotalDropTime <= settings.landingGrace) ? _lastTotalDrop : 0f); return Mathf.Max(_swingDrop, num); } return 0f; } private bool TryGetTotalDrop(PlayerCollisionController collision, float peakY, out float totalDrop) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) totalDrop = 0f; float groundRaycastDistance = settings.groundRaycastDistance; if (!IsFinite(groundRaycastDistance) || groundRaycastDistance <= 0f) { return false; } Vector3 val = ((Component)collision).transform.position + Vector3.up * 0.1f; int num = Physics.RaycastNonAlloc(val, Vector3.down, _groundHits, groundRaycastDistance, _groundLayerMask, (QueryTriggerInteraction)1); float num2 = float.MaxValue; float num3 = 0f; bool flag = false; for (int i = 0; i < num; i++) { RaycastHit val2 = _groundHits[i]; if (!IsEnemyCollider(((RaycastHit)(ref val2)).collider)) { PhysGrabObject componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<PhysGrabObject>(); if ((!((Object)(object)componentInParent != (Object)null) || !((Object)(object)componentInParent == (Object)(object)_physGrabObject)) && !(Vector3.Dot(((RaycastHit)(ref val2)).normal, Vector3.up) < 0.35f) && !(((RaycastHit)(ref val2)).distance >= num2)) { num2 = ((RaycastHit)(ref val2)).distance; num3 = ((RaycastHit)(ref val2)).point.y; flag = true; } } } if (!flag) { return false; } totalDrop = Mathf.Max(0f, peakY - num3); return IsFinite(totalDrop); } private bool IsStandingOnEnemy(PlayerCollisionGrounded collisionGrounded) { //IL_0023: 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) if ((Object)(object)collisionGrounded == (Object)null) { return false; } SphereCollider component = ((Component)collisionGrounded).GetComponent<SphereCollider>(); if ((Object)(object)component == (Object)null) { return false; } int num = Physics.OverlapSphereNonAlloc(((Component)collisionGrounded).transform.position, component.radius, _groundOverlaps, LayerMask.op_Implicit(collisionGrounded.LayerMask)); for (int i = 0; i < num; i++) { if (IsEnemyCollider(_groundOverlaps[i])) { return true; } } return false; } private static bool IsEnemyCollider(Collider collider) { if ((Object)(object)collider == (Object)null) { return false; } PhysGrabObject componentInParent = ((Component)collider).GetComponentInParent<PhysGrabObject>(); if ((Object)(object)componentInParent != (Object)null && componentInParent.isEnemy) { return true; } if (!((Object)(object)((Component)collider).GetComponentInParent<EnemyRigidbody>() != (Object)null)) { return (Object)(object)((Component)collider).GetComponentInParent<Enemy>() != (Object)null; } return true; } private static float GetFallDistanceFallback(PlayerCollisionController collision) { float fallDistance = collision.fallDistance; if (!IsFinite(fallDistance) || !(fallDistance > 0f)) { return 0f; } return fallDistance; } private void ResetLocalDrop() { _airborne = false; _airPeakY = 0f; _currentTotalDrop = 0f; _lastTotalDrop = 0f; _lastTotalDropTime = -9999f; _swingDrop = 0f; } private bool ShouldReportHeight() { if (!SemiFunc.IsMultiplayer() || SemiFunc.IsMasterClient()) { return false; } if ((Object)(object)_physGrabObject == (Object)null || !_physGrabObject.grabbedLocal) { return false; } if ((Object)(object)_photonView == (Object)null) { return false; } return Time.time >= _nextHeightReportTime; } private void ReportHeightToMaster() { float num = settings.heightReportInterval; if (!IsFinite(num) || num < 0.05f) { num = 0.05f; } _nextHeightReportTime = Time.time + num; float num2 = GetLocalHeight(); if (!IsFinite(num2) || num2 < 0f) { num2 = 0f; } _photonView.RPC("ReportHeightRPC", (RpcTarget)2, new object[1] { num2 }); } [PunRPC] private void ReportHeightRPC(float height, PhotonMessageInfo info = default(PhotonMessageInfo)) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (SemiFunc.IsMasterClientOrSingleplayer() && info.Sender != null && IsFinite(height) && !(height < 0f)) { int actorNumber = info.Sender.ActorNumber; if (IsGrabbedByActor(actorNumber)) { RemoteHeight value = default(RemoteHeight); value.Height = height; value.Time = Time.time; _remoteHeights[actorNumber] = value; } } } private bool IsGrabbedByActor(int actorNumber) { if ((Object)(object)_physGrabObject == (Object)null || _physGrabObject.playerGrabbing == null) { return false; } List<PhysGrabber> playerGrabbing = _physGrabObject.playerGrabbing; for (int i = 0; i < playerGrabbing.Count; i++) { PhysGrabber val = playerGrabbing[i]; if (!((Object)(object)val == (Object)null)) { PlayerAvatar playerAvatar = val.playerAvatar; if (!((Object)(object)playerAvatar == (Object)null) && !((Object)(object)playerAvatar.photonView == (Object)null) && playerAvatar.photonView.Owner != null && playerAvatar.photonView.Owner.ActorNumber == actorNumber) { return true; } } } return false; } private float GetRemoteHeight(PlayerAvatar attacker) { if ((Object)(object)attacker == (Object)null || (Object)(object)attacker.photonView == (Object)null || attacker.photonView.Owner == null) { return 0f; } int actorNumber = attacker.photonView.Owner.ActorNumber; if (!_remoteHeights.TryGetValue(actorNumber, out var value)) { return 0f; } float remoteHeightMaxAge = settings.remoteHeightMaxAge; if (!IsFinite(remoteHeightMaxAge) || remoteHeightMaxAge <= 0f || Time.time - value.Time > remoteHeightMaxAge) { _remoteHeights.Remove(actorNumber); return 0f; } return value.Height; } private void PlayHitSound(int damage, Vector3 position, bool isAirHit) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (SemiFunc.IsMultiplayer() && (Object)(object)_photonView != (Object)null) { _photonView.RPC("HitSoundRPC", (RpcTarget)0, new object[3] { position, damage, isAirHit }); } else { PlayHitSoundLocal(damage, position, isAirHit); } } [PunRPC] private void HitSoundRPC(Vector3 position, int damage, bool isAirHit, PhotonMessageInfo info = default(PhotonMessageInfo)) { //IL_0000: 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) if (SemiFunc.MasterOnlyRPC(info)) { PlayHitSoundLocal(damage, position, isAirHit); } } private void PlayHitSoundLocal(int damage, Vector3 position, bool isAirHit) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)settings == (Object)null) { return; } if (isAirHit) { if (airHitSound != null && airHitSound.Sounds != null && airHitSound.Sounds.Length != 0) { PlaySoundSafe(airHitSound, position); } else { PlaySoundSafe(critSound, position); } return; } PlaySoundSafe(critSound, position); if (damage >= 250) { PlaySoundSafe(smashGroundHeavySound, position); } else if (MaceBalance.IsSpecial(damage, settings, EffectiveBaseDamage)) { PlaySoundSafe(smashGroundSound, position); } } private static void PlaySoundSafe(Sound sound, Vector3 position) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (sound != null && sound.Sounds != null && sound.Sounds.Length != 0) { sound.Play(position, 1f, 1f, 1f, 1f); } } private void ApplyShockwave(Enemy mainTarget) { //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) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0191: 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_01e1: 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) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0253: 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_0278: Unknown result type (might be due to invalid IL or missing references) //IL_0288: 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_0291: 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_029d: 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_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: 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_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) Vector3 enemyPoint = GetEnemyPoint(mainTarget); float num = SanitizeShockwaveRadius(shockwaveParticleInnerRadius, 4f); float num2 = SanitizeShockwaveRadius(shockwaveParticleOuterRadius, 8f); float num3 = SanitizeShockwaveHeight(shockwaveParticleMinHeight, 0f); float num4 = SanitizeShockwaveHeight(shockwaveParticleMaxHeight, 1.2f); if (num > num2) { float num5 = num; num = num2; num2 = num5; } if (num3 > num4) { float num6 = num3; num3 = num4; num4 = num6; } BroadcastShockwaveParticle(enemyPoint, num, num2, num3, num4); EnemyDirector instance = EnemyDirector.instance; if ((Object)(object)instance == (Object)null || instance.enemiesSpawned == null) { return; } float aoeRadius = settings.aoeRadius; if (!IsFinite(aoeRadius) || aoeRadius <= 0f) { return; } float num7 = aoeRadius * aoeRadius; float num8 = settings.aoeHitForce; float num9 = settings.aoeUpwardForce; float num10 = settings.aoeHitTorque; float num11 = settings.aoeStunTime; if (!IsFinite(num8)) { num8 = 0f; } if (!IsFinite(num9)) { num9 = 0f; } if (!IsFinite(num10)) { num10 = 0f; } if (!IsFinite(num11) || num11 < 0f) { num11 = 0f; } _stunParticlePositions.Clear(); List<EnemyParent> enemiesSpawned = instance.enemiesSpawned; for (int i = 0; i < enemiesSpawned.Count; i++) { EnemyParent val = enemiesSpawned[i]; if ((Object)(object)val == (Object)null) { continue; } Enemy enemy = val.Enemy; if ((Object)(object)enemy == (Object)null || (Object)(object)enemy == (Object)(object)mainTarget) { continue; } Vector3 val2 = GetEnemyPoint(enemy) - enemyPoint; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude > num7) { continue; } if (num11 > 0f && enemy.HasStateStunned && (Object)(object)enemy.StateStunned != (Object)null) { enemy.StateStunned.Set(num11); _stunParticlePositions.Add(GetEnemyPoint(enemy)); } if (enemy.HasRigidbody && !((Object)(object)enemy.Rigidbody == (Object)null) && (num8 != 0f || num9 != 0f || num10 != 0f)) { val2.y = 0f; float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude; Vector3 val3; if (sqrMagnitude2 > 0.0001f) { val3 = val2 / Mathf.Sqrt(sqrMagnitude2); } else { val3 = Random.insideUnitSphere; val3.y = 0f; val3 = ((((Vector3)(ref val3)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val3)).normalized : Vector3.forward); } Vector3 val4 = val3 * num8 + Vector3.up * num9; Vector3 val5 = Vector3.Cross(Vector3.up, val3) * num10; enemy.Rigidbody.FreezeForces(val4, val5); } } BroadcastStunParticles(); } private void BroadcastEnemyHitParticle(Vector3 position) { //IL_0055: 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) if (hitParticleCount > 0) { if (!HasAnyMaterial(hitParticleMaterials)) { WarnMissingParticleMaterialOnce(); } else if (SemiFunc.IsMultiplayer() && (Object)(object)_photonView != (Object)null) { _photonView.RPC("EnemyHitParticleRPC", (RpcTarget)0, new object[1] { position }); } else { SpawnEnemyHitParticleLocal(position); } } } [PunRPC] private void EnemyHitParticleRPC(Vector3 position, PhotonMessageInfo info = default(PhotonMessageInfo)) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (SemiFunc.MasterOnlyRPC(info)) { SpawnEnemyHitParticleLocal(position); } } private unsafe void SpawnEnemyHitParticleLocal(Vector3 position) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) int num = hitParticleCount; if (num <= 0) { return; } Material val = PickRandomMaterial(hitParticleMaterials); if ((Object)(object)val == (Object)null) { WarnMissingParticleMaterialOnce(); return; } MaceProceduralParticles.SpawnHit(position, val, num, GetParticleDestroyDelay(0.5f), hitParticleMinSize, hitParticleMaxSize); if ((Object)(object)settings != (Object)null && settings.debugHeightLogging && !_hitVisualDiagnosed) { _hitVisualDiagnosed = true; ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)("[Mace] 首次本地命中粒子 position=" + ((object)(*(Vector3*)(&position))/*cast due to .constrained prefix*/).ToString() + " material=" + ((Object)val).name + " count=" + num)); } } } private void BroadcastShockwaveParticle(Vector3 position, float innerRadius, float outerRadius, float minHeight, float maxHeight) { //IL_0088: 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) if (shockwaveParticleCount > 0) { if (!HasAnyMaterial(shockwaveParticleMaterials) && !HasAnyMaterial(hitParticleMaterials)) { WarnMissingParticleMaterialOnce(); } else if (SemiFunc.IsMultiplayer() && (Object)(object)_photonView != (Object)null) { _photonView.RPC("ShockwaveParticleRPC", (RpcTarget)0, new object[5] { position, innerRadius, outerRadius, minHeight, maxHeight }); } else { SpawnShockwaveParticleLocal(position, innerRadius, outerRadius, minHeight, maxHeight); } } } [PunRPC] private void ShockwaveParticleRPC(Vector3 position, float innerRadius, float outerRadius, float minHeight, float maxHeight, PhotonMessageInfo info = default(PhotonMessageInfo)) { //IL_0000: 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) if (SemiFunc.MasterOnlyRPC(info)) { SpawnShockwaveParticleLocal(position, innerRadius, outerRadius, minHeight, maxHeight); } } private void SpawnShockwaveParticleLocal(Vector3 position, float innerRadius, float outerRadius, float minHeight, float maxHeight) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) int num = shockwaveParticleCount; if (num > 0) { Material val = ResolveShockwaveMaterial(); if (!((Object)(object)val == (Object)null)) { MaceProceduralParticles.SpawnShockwave(position, val, innerRadius, outerRadius, minHeight, maxHeight, num, GetParticleDestroyDelay(0.8f), shockwaveParticleMinSize, shockwaveParticleMaxSize); } } } private void BroadcastStunParticles() { if (stunParticleCount <= 0 || _stunParticlePositions.Count == 0) { _stunParticlePositions.Clear(); return; } if (!HasAnyMaterial(stunParticleMaterials) && !HasAnyMaterial(hitParticleMaterials)) { WarnMissingParticleMaterialOnce(); _stunParticlePositions.Clear(); return; } Vector3[] array = _stunParticlePositions.ToArray(); _stunParticlePositions.Clear(); if (SemiFunc.IsMultiplayer() && (Object)(object)_photonView != (Object)null) { _photonView.RPC("StunParticlesRPC", (RpcTarget)0, new object[1] { array }); } else { SpawnStunParticlesLocal(array); } } [PunRPC] private void StunParticlesRPC(Vector3[] positions, PhotonMessageInfo info = default(PhotonMessageInfo)) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (SemiFunc.MasterOnlyRPC(info)) { SpawnStunParticlesLocal(positions); } } private void SpawnStunParticlesLocal(Vector3[] positions) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) int num = stunParticleCount; if (num <= 0 || positions == null) { return; } float particleDestroyDelay = GetParticleDestroyDelay(0.4f); for (int i = 0; i < positions.Length; i++) { Material val = ResolveStunMaterial(); if ((Object)(object)val == (Object)null) { break; } MaceProceduralParticles.SpawnStun(positions[i], val, num, particleDestroyDelay, stunParticleMinSize, stunParticleMaxSize); } } private Material ResolveShockwaveMaterial() { Material val = PickRandomMaterial(shockwaveParticleMaterials); if (!((Object)(object)val != (Object)null)) { return PickRandomMaterial(hitParticleMaterials); } return val; } private Material ResolveStunMaterial() { Material val = PickRandomMaterial(stunParticleMaterials); if (!((Object)(object)val != (Object)null)) { return PickRandomMaterial(hitParticleMaterials); } return val; } private static bool HasAnyMaterial(Material[] materials) { if (materials == null) { return false; } for (int i = 0; i < materials.Length; i++) { if ((Object)(object)materials[i] != (Object)null) { return true; } } return false; } private static Material PickRandomMaterial(Material[] materials) { if (materials == null || materials.Length == 0) { return null; } int num = 0; for (int i = 0; i < materials.Length; i++) { if ((Object)(object)materials[i] != (Object)null) { num++; } } if (num == 0) { return null; } int num2 = Random.Range(0, num); for (int j = 0; j < materials.Length; j++) { if (!((Object)(object)materials[j] == (Object)null)) { if (num2 == 0) { return materials[j]; } num2--; } } return null; } private float GetParticleDestroyDelay(float effectLifetime) { float num = particleLifetime; if (!IsFinite(num) || num < 0.1f) { num = 0.1f; } float num2 = ((IsFinite(effectLifetime) && effectLifetime > 0f) ? effectLifetime : 0f) + 0.25f; if (!(num > num2)) { return num2; } return num; } private void WarnMissingParticleMaterialOnce() { if (!_missingParticleMaterialWarned && !((Object)(object)settings == (Object)null) && settings.debugHeightLogging) { _missingParticleMaterialWarned = true; ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)"[Mace] 粒子材质数组没有有效材质:命中粒子跳过;未单独接线的冲击波/眩晕粒子也会回退 hit 数组后跳过。请在 Item Mace 的 MaceBehaviour 上给 hitParticleMaterials 等数组指定 Assets/Mace/Material/particle*.mat。"); } } } private void ResolveModelReferencesByName() { bool flag = (Object)(object)healthyModel == (Object)null; bool flag2 = (Object)(object)brokenModel == (Object)null; if (!flag && !flag2) { return; } Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true); if (flag) { healthyModel = FindGameObjectByName(componentsInChildren, "Mace Healthy"); } if (flag2) { brokenModel = FindGameObjectByName(componentsInChildren, "Mace Broken"); } if (((flag && !((Object)(object)healthyModel != (Object)null)) || (flag2 && !((Object)(object)brokenModel != (Object)null))) && !_modelFallbackWarned && !((Object)(object)settings == (Object)null) && settings.debugHeightLogging) { _modelFallbackWarned = true; ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("[Mace] 模型引用按名称回退失败(healthyModel=" + (((Object)(object)healthyModel != (Object)null) ? ((Object)healthyModel).name : "null") + " brokenModel=" + (((Object)(object)brokenModel != (Object)null) ? ((Object)brokenModel).name : "null") + "):请确认 prefab 中存在名为 'Mace Healthy' / 'Mace Broken' 的节点,或手动接线。")); } } } private static GameObject FindGameObjectByName(Transform[] transforms, string name) { if (transforms == null) { return null; } foreach (Transform val in transforms) { if ((Object)(object)val != (Object)null && string.Equals(((Object)val).name, name, StringComparison.Ordinal)) { return ((Component)val).gameObject; } } foreach (Transform val2 in transforms) { if ((Object)(object)val2 != (Object)null && string.Equals(((Object)val2).name, name, StringComparison.OrdinalIgnoreCase)) { return ((Component)val2).gameObject; } } return null; } private void UpdateBrokenModel() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 bool flag = ((Object)(object)_itemMelee != (Object)null && (int)_itemMelee.currentState == 3) || ((Object)(object)_itemBattery != (Object)null && _itemBattery.batteryLife <= 0f); if (_modelStateInitialized && flag == _modelStateBroken) { return; } _modelStateInitialized = true; _modelStateBroken = flag; if ((Object)(object)settings != (Object)null && settings.debugHeightLogging) { string text = (((Object)(object)_itemMelee != (Object)null) ? ((object)Unsafe.As<State, State>(ref _itemMelee.currentState)/*cast due to .constrained prefix*/).ToString() : "<none>"); string text2 = (((Object)(object)_itemBattery != (Object)null) ? _itemBattery.batteryLife.ToString("F1") : "<none>"); ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)("[Mace] 模型状态切换 broken=" + flag + " state=" + text + " batteryLife=" + text2)); } } ApplyModelState(flag); } private void ApplyModelState(bool broken) { if (!broken) { if ((Object)(object)healthyModel != (Object)null) { healthyModel.SetActive(true); } if ((Object)(object)brokenModel != (Object)null) { brokenModel.SetActive(false); } } else if ((Object)(object)brokenModel != (Object)null) { if ((Object)(object)healthyModel != (Object)null) { healthyModel.SetActive(false); } brokenModel.SetActive(true); } else { WarnMissingBrokenModelOnce(); if ((Object)(object)healthyModel != (Object)null) { healthyModel.SetActive(true); } } } private void WarnMissingBrokenModelOnce() { if (!_missingBrokenModelWarned && !((Object)(object)settings == (Object)null) && settings.debugHeightLogging) { _missingBrokenModelWarned = true; ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)"[Mace] brokenModel 未接线:损坏时保持 healthyModel 可见。请在 Item Mace 的 MaceBehaviour 上指定损坏模型根节点。"); } } } private static Vector3 GetEnemyPoint(Enemy enemy) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)enemy == (Object)null) { return Vector3.zero; } Transform centerTransform = enemy.CenterTransform; if (!((Object)(object)centerTransform != (Object)null)) { return ((Component)enemy).transform.position; } return centerTransform.position; } private static float SanitizeShockwaveRadius(float value, float fallback) { if (!IsFinite(value)) { return fallback; } if (!(value < 0f)) { return value; } return 0f; } private static float SanitizeShockwaveHeight(float value, float fallback) { if (!IsFinite(value)) { return fallback; } return value; } private static bool IsFinite(float value) { if (!float.IsNaN(value)) { return !float.IsInfinity(value); } return false; } private void Fail(string message) { _disabled = true; ((Behaviour)this).enabled = false; ManualLogSource log = Plugin.Log; if (log != null) { log.LogError((object)("[Mace] MaceBehaviour 初始化失败:" + message)); } } } [HarmonyPatch(typeof(HurtCollider), "EnemyHurt", new Type[] { typeof(Enemy) })] internal class MaceEnemyHurtPatch { internal sealed class HurtState { public MaceBehaviour Behaviour; public int Damage; public int EnemyDamage; public bool EnemyStun; public float EnemyStunTime; public EnemyType EnemyStunType; public float EnemyHitForce; public float EnemyHitTorque; public MaceHitDiagnostics.HealthSnapshot HealthBefore; public bool Restored; } private static bool Prefix(HurtCollider __instance, Enemy _enemy, out HurtState __state) { //IL_0068: 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_00cf: Unknown result type (might be due to invalid IL or missing references) __state = null; if (!SemiFunc.IsMasterClientOrSingleplayer()) { return true; } if (!MaceBehaviour.TryGet(__instance, out var behaviour) || (Object)(object)behaviour == (Object)null) { return true; } int damage = behaviour.GetDamage(__instance.playerCausingHurt, _enemy); (__state = new HurtState { Behaviour = behaviour, Damage = damage, EnemyDamage = __instance.enemyDamage, EnemyStun = __instance.enemyStun, EnemyStunTime = __instance.enemyStunTime, EnemyStunType = __instance.enemyStunType, EnemyHitForce = __instance.enemyHitForce, EnemyHitTorque = __instance.enemyHitTorque }).HealthBefore = MaceHitDiagnostics.CaptureHealth(_enemy); __instance.enemyDamage = damage; if (MaceBalance.IsSpecial(damage, behaviour.Settings, behaviour.EffectiveBaseDamage)) { __instance.enemyStun = true; __instance.enemyStunTime = behaviour.Settings.primaryStunTime; __instance.enemyStunType = (EnemyType)4; __instance.enemyHitForce = behaviour.Settings.primaryHitForce; __instance.enemyHitTorque = behaviour.Settings.primaryHitTorque; } return true; } private static void Postfix(HurtCollider __instance, Enemy _enemy, HurtState __state, bool __result) { if (__state != null) { Restore(__instance, __state); if (__result && !((Object)(object)__state.Behaviour == (Object)null)) { MaceHitDiagnostics.HealthSnapshot healthAfter = MaceHitDiagnostics.CaptureHealth(_enemy); __state.Behaviour.OnEnemyHurt(_enemy, __state.Damage, __state.HealthBefore, healthAfter); } } } private static Exception Finalizer(HurtCollider __instance, HurtState __state, Exception __exception) { if (__state != null && !__state.Restored) { Restore(__instance, __state); } return __exception; } private static void Restore(HurtCollider instance, HurtState state) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) instance.enemyDamage = state.EnemyDamage; instance.enemyStun = state.EnemyStun; instance.enemyStunTime = state.EnemyStunTime; instance.enemyStunType = state.EnemyStunType; instance.enemyHitForce = state.EnemyHitForce; instance.enemyHitTorque = state.EnemyHitTorque; state.Restored = true; } } internal static class MaceHitDiagnostics { internal readonly struct HealthSnapshot { public readonly bool Valid; public readonly int HealthCurrent; public readonly float DamageResistance; public HealthSnapshot(bool valid, int healthCurrent, float damageResistance) { Valid = valid; HealthCurrent = healthCurrent; DamageResistance = damageResistance; } } private static FieldRef<EnemyHealth, float> _damageResistanceRef; private static bool _damageResistanceRefResolved; private static bool _failureWarned; internal static HealthSnapshot CaptureHealth(Enemy enemy) { try { if ((Object)(object)enemy == (Object)null) { return default(HealthSnapshot); } if (!enemy.HasHealth) { return default(HealthSnapshot); } EnemyHealth health = enemy.Health; if ((Object)(object)health == (Object)null) { return default(HealthSnapshot); } return new HealthSnapshot(valid: true, health.healthCurrent, ReadDamageResistance(health)); } catch (Exception e) { WarnFailureOnce(e); return default(HealthSnapshot); } } private static float ReadDamageResistance(EnemyHealth health) { if (!_damageResistanceRefResolved) { _damageResistanceRef = AccessTools.FieldRefAccess<EnemyHealth, float>("damageResistance"); _damageResistanceRefResolved = true; } return _damageResistanceRef.Invoke(health); } internal static void LogEnemyHit(MaceBehaviour behaviour, Enemy enemy, int damage, int costDamage, bool costCapApplied, bool chargedThisHit, int actualCostBars, float batteryLifeBefore, float batteryLifeAfter, int batteryLifeIntBefore, int batteryLifeIntAfter, HealthSnapshot healthBefore, HealthSnapshot healthAfter, float rawPlayerDrop, float targetClearance, float adjustedHeight, bool isAirHit, bool clearanceValid) { try { if ((Object)(object)behaviour == (Object)null) { return; } MaceSettings settings = behaviour.Settings; int num = (((Object)(object)settings != (Object)null) ? settings.baseDamage : 0); int effectiveBaseDamage = behaviour.EffectiveBaseDamage; float num2 = (((Object)(object)settings != (Object)null) ? settings.deadHeight : float.NaN); float slope = (((Object)(object)settings != (Object)null) ? settings.damagePerMeter : float.NaN); int num3 = (((Object)(object)settings != (Object)null) ? settings.kneeDamage : 0); MaceBalance.TryComputeKneeInfo(settings, effectiveBaseDamage, out var kneeHeight, out var postKneeSlope, out var secondKneeDamage, out var _, out var secondKneeHeight, out var secondKneeSlope); PlayerAvatar lockedAttacker = behaviour.LockedAttacker; float time = Time.time; int swingSeq = behaviour.SwingSeq; float swingIdleGap = behaviour.SwingIdleGap; bool swingContinued = behaviour.SwingContinued; string value = DescribeCurveSegment(adjustedHeight, num2, kneeHeight, secondKneeHeight); bool flag = IsFinite(kneeHeight); bool flag2 = IsFinite(secondKneeHeight); string value2; if (!flag && !flag2) { value2 = "N/A"; } else { string text = ""; if (flag && adjustedHeight > kneeHeight) { text = "第一"; } if (flag2 && adjustedHeight > secondKneeHeight) { text = ((text.Length == 0) ? "第二" : (text + "/第二")); } value2 = ((text.Length == 0) ? "无" : (text + "拐点")); } string value3 = (((Object)(object)settings != (Object)null) ? YesNo(MaceBalance.IsSpecial(damage, settings, effectiveBaseDamage)) : "N/A"); string value4; string value5; string value6; if (healthBefore.Valid && healthAfter.Valid) { value4 = I(healthBefore.HealthCurrent) + "->" + I(healthAfter.HealthCurrent); value5 = I(healthBefore.HealthCurrent - healthAfter.HealthCurrent); value6 = F2(healthBefore.DamageResistance); } else { value4 = (healthBefore.Valid ? (I(healthBefore.HealthCurrent) + "->N/A") : (healthAfter.Valid ? ("N/A->" + I(healthAfter.HealthCurrent)) : "N/A")); value5 = "N/A"; value6 = (healthBefore.Valid ? F2(healthBefore.DamageResistance) : ((!healthAfter.Valid) ? "N/A" : F2(healthAfter.DamageResistance))); } string value7 = (healthBefore.Valid ? I(healthBefore.HealthCurrent) : "N/A"); string value8 = (((Object)(object)enemy != (Object)null) ? ((Object)enemy).name : "<N/A>"); string value9 = (((Object)(object)lockedAttacker != (Object)null) ? ((Object)lockedAttacker).name : "<无>"); string value10 = (isAirHit ? "空中" : "普通档"); StringBuilder stringBuilder = new StringBuilder(512); stringBuilder.Append("[MaceHit] 伤害=").Append(I(damage)).Append(" 高度=") .Append(F2(adjustedHeight)) .Append('m') .Append("(原始") .Append(F2(rawPlayerDrop)) .Append(" - 净空") .Append(F2(targetClearance)) .Append(",有效=") .Append(B(clearanceValid)) .Append(')') .Append(" | 目标=") .Append(value8) .Append(" | 曲线=") .Append(value) .Append(" | 特殊=") .Append(value3) .Append(" | 音效=") .Append(value10) .Append(" | 主机=") .Append(B(SemiFunc.IsMasterClientOrSingleplayer())); stringBuilder.Append(Environment.NewLine); stringBuilder.Append("[MaceHit] 曲线: 有效基础=").Append(I(effectiveBaseDamage)); if (num != effectiveBaseDamage) { stringBuilder.Append("(配置=").Append(I(num)).Append(')'); } stringBuilder.Append(" 起步=").Append(IsFinite(num2) ? (F2(num2) + "m") : "N/A").Append(" | ") .Append(FormatSegment("第一段", slope, num3, kneeHeight)) .Append(" | ") .Append(FormatSegment("第二段", postKneeSlope, secondKneeDamage, secondKneeHeight)) .Append(" | "); stringBuilder.Append(IsFinite(secondKneeSlope) ? ("第三段 " + F2(secondKneeSlope) + "/m") : "第三段 N/A"); stringBuilder.Append(" | 越过=").Append(value2); stringBuilder.Append(Environment.NewLine); stringBuilder.Append("[MaceHit] 能量: 计费=").Append(I(costDamage)).Append("/阈值=") .Append(((Object)(object)settings != (Object)null) ? I(settings.heavyCostDamageThreshold) : "N/A") .Append(" 重扣=") .Append(Plugin.HeavyCostEnabled ? "开" : "关") .Append(" | 扣") .Append(I(actualCostBars)) .Append("格 ") .Append(I(batteryLifeIntBefore)) .Append("→") .Append(I(batteryLifeIntAfter)) .Append(" (") .Append(F1(batteryLifeBefore)) .Append("→") .Append(F1(batteryLifeAfter)) .Append(')') .Append(" | 封顶=") .Append(YesNo(costCapApplied)) .Append(" 剩余HP=") .Append(value7) .Append(" 本次扣费=") .Append(YesNo(chargedThisHit)); stringBuilder.Append(Environment.NewLine); stringBuilder.Append("[MaceHit] 结果: 生命 ").Append(value4).Append(" (实际=") .Append(value5) .Append(" 抗性=") .Append(value6) .Append(')') .Append(" | 挥击#") .Append(I(swingSeq)) .Append(' ') .Append(swingContinued ? "续挥" : "新挥击") .Append(" gap=") .Append(F2(swingIdleGap)) .Append('s') .Append(" | time=") .Append(F2(time)) .Append(" | 攻击者=") .Append(value9); ManualLogSource log = Plugin.Log; if (log != null) { log.LogInfo((object)stringBuilder.ToString()); } } catch (Exception e) { WarnFailureOnce(e); } } private static void WarnFailureOnce(Exception e) { if (!_failureWarned) { _failureWarned = true; ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("[MaceHit] 命中诊断读取/格式化失败(已忽略,不影响命中):" + e.Message)); } } } private static string DescribeCurveSegment(float height, float deadHeight, float kneeHeight, float secondKneeHeight) { if (!IsFinite(height) || !IsFinite(deadHeight)) { return "N/A"; } if (height < deadHeight) { return "基础段"; } if (!IsFinite(kneeHeight)) { return "N/A"; } if (height < kneeHeight) { return "第一段"; } if (!IsFinite(secondKneeHeight)) { return "N/A"; } if (height < secondKneeHeight) { return "第二段"; } return "第三段"; } private static string FormatSegment(string name, float slope, float damage, float atHeight) { bool flag = IsFinite(slope); bool flag2 = IsFinite(damage) && IsFinite(atHeight); if (!flag && !flag2) { return name + " N/A"; } StringBuilder stringBuilder = new StringBuilder(32); stringBuilder.Append(name); if (flag) { stringBuilder.Append(' ').Append(F2(slope)).Append("/m"); } if (flag2) { stringBuilder.Append(" → ").Append(N(damage)).Append('@') .Append(F2(atHeight)) .Append('m'); } return stringBuilder.ToString(); } private static string F1(float value) { if (!IsFinite(value)) { return "N/A"; } return value.ToString("F1", CultureInfo.InvariantCulture); } private static string N(float value) { if (!IsFinite(value)) { return "N/A"; } float num = Mathf.Round(value); if (!(Mathf.Abs(value - num) < 0.005f)) { return F2(value); } return num.ToString("F0", CultureInfo.InvariantCulture); } private static string YesNo(bool value) { if (!value) { return "否"; } return "是"; } private static string F2(float value) { if (!IsFinite(value)) { return "N/A"; } return value.ToString("F2", CultureInfo.InvariantCulture); } private static string I(int value) { return value.ToString(CultureInfo.InvariantCulture); } private static string B(bool value) { if (!value) { return "False"; } return "True"; } private static bool IsFinite(float value) { if (!float.IsNaN(value)) { return !float.IsInfinity(value); } return false; } } [Serializable] public sealed class MaceMaterialSwap { [Tooltip("正常材质。留空表示将 Broken Material 应用于所有模型材质槽,适用于 glTF 嵌入材质。")] public Material healthyMaterial; [Tooltip("进入 Broken 状态时替换成的材质;留空则保留正常材质。")] public Material brokenMaterial; } internal static class MaceProceduralParticles { private const float DefaultHitMinSize = 0.18f; private const float DefaultHitMaxSize = 0.3f; private const float DefaultShockwaveMinSize = 0.12f; private const float DefaultShockwaveMaxSize = 0.24f; private const float DefaultStunMinSize = 0.12f; private const float DefaultStunMaxSize = 0.2f; internal static void SpawnHit(Vector3 position, Material material, int count, float destroyDelay, float minSize, float maxSize) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)material == (Object)null) && count > 0) { SanitizeSizeRange(ref minSize, ref maxSize, 0.18f, 0.3f); ParticleSystem val = Create("MaceHitParticles", position, Quaternion.identity, 1f, destroyDelay); MainModule main = val.main; ((MainModule)(ref main)).duration = 0.2f; ((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.35f, 0.5f); ((MainModule)(ref main)).startSpeed = new MinMaxCurve(3f, 5f); ((MainModule)(ref main)).startSize = new MinMaxCurve(minSize, maxSize); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white); ((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(1.2f); ((MainModule)(ref main)).maxParticles = Mathf.Max(1, count); ShapeModule shape = val.shape; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0; ((ShapeModule)(ref shape)).radius = 0.15f; ((ShapeModule)(ref shape)).radiusThickness = 1f; ApplyRenderer(val, material); PlayAndEmit(val, count); } } internal static void SpawnShockwave(Vector3 position, Material material, float innerRadius, float outerRadius, float minHeight, float maxHeight, int count, float destroyDelay, float minSize, float maxSize) { //IL_0034: 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_0048: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: 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_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_01bb: 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_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: 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) if ((Object)(object)material == (Object)null || count <= 0) { return; } SanitizeShockwaveRange(ref innerRadius, ref outerRadius, ref minHeight, ref maxHeight); SanitizeSizeRange(ref minSize, ref maxSize, 0.12f, 0.24f); ParticleSystem val = Create("MaceShockwaveParticles", position, Quaternion.identity, 1f, destroyDelay); MainModule main = val.main; ((MainModule)(ref main)).duration = 0.3f; ((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.45f, 0.75f); ((MainModule)(ref main)).startSpeed = new MinMaxCurve(5f, 9f); ((MainModule)(ref main)).startSize = new MinMaxCurve(minSize, maxSize); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white); ((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.15f); ((MainModule)(ref main)).maxParticles = Mathf.Max(1, count); ShapeModule shape = val.shape; ((ShapeModule)(ref shape)).enabled = false; ApplyRenderer(val, material); val.Play(false); float num = innerRadius * innerRadius; float num2 = outerRadius * outerRadius; bool flag = IsFinite(num) && IsFinite(num2); Vector3 val2 = default(Vector3); for (int i = 0; i < count; i++) { float num3 = Random.Range(0f, MathF.PI * 2f); ((Vector3)(ref val2))..ctor(Mathf.Cos(num3), 0f, Mathf.Sin(num3)); float num4 = (flag ? Mathf.Sqrt(Random.Range(num, num2)) : Random.Range(innerRadius, outerRadius)); float num5 = Random.Range(minHeight, maxHeight); if (!IsFinite(num4)) { num4 = 0f; } if (!IsFinite(num5)) { num5 = 0f; } Vector3 velocity = val2 * Random.Range(5f, 9f) + Vector3.up * Random.Range(0.2f, 1.2f); EmitParams val3 = default(EmitParams); ((EmitParams)(ref val3)).position = position + val2 * num4 + Vector3.up * num5; ((EmitParams)(ref val3)).velocity = velocity; val.Emit(val3, 1); } } internal static void SpawnStun(Vector3 position, Material material, int count, float destroyDelay, float minSize, float maxSize) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)material == (Object)null) && count > 0) { SanitizeSizeRange(ref minSize, ref maxSize, 0.12f, 0.2f); ParticleSystem val = Create("MaceStunParticles", position, Quaternion.identity, 1f, destroyDelay); MainModule main = val.main; ((MainModule)(ref main)).duration = 0.2f; ((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(0.3f); ((MainModule)(ref main)).startSpeed = new MinMaxCurve(2f, 3f); ((MainModule)(ref main)).startSize = new MinMaxCurve(minSize, maxSize); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white); ((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.6f); ((MainModule)(ref main)).maxParticles = Mathf.Max(1, count); ShapeModule shape = val.shape; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0; ((ShapeModule)(ref shape)).radius = 0.2f; ApplyRenderer(val, material); PlayAndEmit(val, count); } } private static void SanitizeShockwaveRange(ref float innerRadius, ref float outerRadius, ref float minHeight, ref float maxHeight) { innerRadius = ((IsFinite(innerRadius) && innerRadius > 0f) ? innerRadius : 0f); outerRadius = ((IsFinite(outerRadius) && outerRadius > 0f) ? outerRadius : 0f); minHeight = (IsFinite(minHeight) ? minHeight : 0f); maxHeight = (IsFinite(maxHeight) ? maxHeight : 0f); if (innerRadius > outerRadius) { float num = innerRadius; innerRadius = outerRadius; outerRadius = num; } if (minHeight > maxHeight) { float num2 = minHeight; minHeight = maxHeight; maxHeight = num2; } } private static void SanitizeSizeRange(ref float minSize, ref float maxSize, float defaultMin, float defaultMax) { minSize = (IsFinite(minSize) ? Mathf.Max(0f, minSize) : defaultMin); maxSize = (IsFinite(maxSize) ? Mathf.Max(0f, maxSize) : defaultMax); if (minSize > maxSize) { float num = minSize; minSize = maxSize; maxSize = num; } } private static ParticleSystem Create(string name, Vector3 position, Quaternion rotation, float scale, float destroyDelay) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_000d: 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_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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00b7: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetPositionAndRotation(position, rotation); if (IsFinite(scale) && scale > 0f) { val.transform.localScale = Vector3.one * scale; } ParticleSystem val2 = val.AddComponent<ParticleSystem>(); MainModule main = val2.main; ((MainModule)(ref main)).duration = 0.2f; ((MainModule)(ref main)).loop = false; ((MainModule)(ref main)).playOnAwake = false; ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1; ((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(0.4f); ((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(1f); ((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.2f); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white); ((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f); ((MainModule)(ref main)).maxParticles = 32; EmissionModule emission = val2.emission; ((EmissionModule)(ref emission)).enabled = false; float num = ((IsFinite(destroyDelay) && destroyDelay >= 0.1f) ? destroyDelay : 0.1f); Object.Destroy((Object)(object)val, num); return val2; } private static void ApplyRenderer(ParticleSystem ps, Material material) { ParticleSystemRenderer component = ((Component)ps).GetComponent<ParticleSystemRenderer>(); if (!((Object)(object)component == (Object)null)) { component.renderMode = (ParticleSystemRenderMode)0; ((Renderer)component).sharedMaterial = material; } } private static void PlayAndEmit(ParticleSystem ps, int count) { if (count > 0) { ps.Play(false); ps.Emit(count); } } private static bool IsFinite(float value) { if (!float.IsNaN(value)) { return !float.IsInfinity(value); } return false; } } [CreateAssetMenu(fileName = "MaceSettings", menuName = "Mace/Mace Settings")] public class MaceSettings : ScriptableObject { [Header("伤害与高度曲线")] [Tooltip("高度不超过 deadHeight 时的固定伤害。")] public int baseDamage = 100; [Tooltip("开始按高度增伤的基准高度(米)。默认 2.5m,让普通单跳保持基础伤害。")] public float deadHeight = 2.5f; [Tooltip("拐点前每高出 1 米增加的伤害;默认 75,与基础100、四跳约6.67m=400配套。")] public float damagePerMeter = 75f; [Tooltip("曲线拐点处的伤害。超过拐点后斜率按 postKneeSlopeScale 收窄。")] public int kneeDamage = 350; [Tooltip("拐点后斜率比例。默认 0.8:拐点前75/m、之后60/m,约5.83m=350、6.67m=400。")] [Range(0f, 1f)] public float postKneeSlopeScale = 0.8f; [Header("第二伤害拐点")] [Tooltip("第二拐点处的伤害值(不是高度)。超过该伤害后斜率按 secondKneeSlopeScale 再次收窄。默认 500。旧资产缺少字段(两项均读到 0)时回退代码默认 500/0.5,不会意外禁用第二拐点。")] public float secondKneeDamage = 500f; [Tooltip("第二拐点后斜率相对“第一拐点后斜率”的比例。默认 0.5(57/m × 0.5 = 28.5/m);0 表示 500 伤害后不再增长。")] [Range(0f, 1f)] public float secondKneeSlopeScale = 0.5f; [Header("充能消耗")] [Tooltip("伤害超过该值时按重击计费,否则按普通攻击计费。")] public int heavyCostDamageThreshold = 200; [Tooltip("普通攻击消耗的充能格数。")] public int normalCostBars = 1; [Tooltip("重击消耗的充能格数。")] public int heavyCostBars = 2; [Header("主目标命中")] [Tooltip("主目标被命中的眩晕时长(秒)。")] public float primaryStunTime = 5f; [Tooltip("主目标命中时的击退力度。")] public float primaryHitForce = 30f; [Tooltip("主目标命中时的扭矩。")] public float primaryHitTorque = 15f; [Header("范围冲击")] [Tooltip("范围冲击半径(米)。")] public float aoeRadius = 6f; [Tooltip("范围冲击造成的眩晕时长(秒)。")] public float aoeStunTime = 2f; [Tooltip("范围冲击的水平/径向力度。")] public float aoeHitForce = 25f; [Tooltip("范围冲击的向上力度。")] public float aoeUpwardForce = 8f; [Tooltip("范围冲击的扭矩。")] public float aoeHitTorque = 10f; [Header("高度上报与延迟")] [Tooltip("本地高度上报的最小间隔(秒)。")] public float heightReportInterval = 0.1f; [Tooltip("落地后保留本次落差的宽限时间;挥击快照会在整个本次 Swinging 期间保留。")] public float landingGrace = 0.5f; [Tooltip("远端高度数据的最大有效时长(秒),超过视为过期。")] public float remoteHeightMaxAge = 0.35f; [Tooltip("从玩家位置向下寻找可落脚地面的最大距离(米);找不到时回退到原版 fallDistance。")] public float groundRaycastDistance = 100f; [Tooltip("每次挥击首次命中时在 BepInEx 日志记录有效高度与伤害,用于校准四跳高度。")] public bool debugHeightLogging; [Header("空中目标净空")] [Tooltip("从目标最低实心碰撞体向下寻找可站立支撑面的最大射线距离(米);非法值(<=0 / NaN / Infinity)或旧资产读到 0 时回退 10 米。")] public float targetClearanceRayDistance = 10f; [Tooltip("目标净空大于该值(米)时视为空中命中并改播空中音效;非法值或旧资产读到 0 时回退 0.5 米。")] public float airHitClearanceThreshold = 0.5f; [Header("连续挥动会话")] [Tooltip("离开 Swinging 后在该窗口(秒)内重新进入视为同一次连续挥动;只有超过窗口才重新计费/锁伤。")] public float swingContinuationGrace = 0.3f; } internal static class MaceTargetClearance { internal struct Result { public float Clearance; public float LowestY; public float SupportY; public bool Valid; } private const float DefaultRayDistance = 10f; private const float RayOriginOffset = 0.05f; private const float MinUpDot = 0.35f; private const int HitBufferSize = 32; private static readonly RaycastHit[] Hits = (RaycastHit[])(object)new RaycastHit[32]; private static bool _layersInitialized; private static int _supportLayerMask; private static int _playerOnlyCollisionLayer; private static int _triggersLayer; private static int _playerLayer; internal static bool TryGet(Enemy enemy, MaceSettings settings, PhysGrabObject mace, out Result result) { //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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) result = default(Result); try { EnsureLayers(); if ((Object)(object)enemy == (Object)null) { return false; } EnemyRigidbody val = null; PhysGrabObject val2 = null; if (enemy.HasRigidbody && (Object)(object)enemy.Rigidbody != (Object)null) { val = enemy.Rigidbody; val2 = val.physGrabObject; } Collider[] array = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponentsInChildren<Collider>(true) : ((Component)enemy).GetComponentsInChildren<Collider>(true)); if (array == null || array.Length == 0) { return false; } Collider val3 = null; float num = float.MaxValue; Bounds bounds; foreach (Collider val4 in array) { if (IsEligibleTargetCollider(val4, val)) { bounds = val4.bounds; float y = ((Bounds)(ref bounds)).min.y; if (IsFinite(y) && ((Object)(object)val3 == (Object)null || y < num)) { val3 = val4; num = y; } } } if ((Object)(object)val3 == (Object)null || !IsFinite(num)) { return false; } bounds = val3.bounds; Vector3 center = ((Bounds)(ref bounds)).center; Vector3 val5 = default(Vector3); ((Vector3)(ref val5))..ctor(center.x, num + 0.05f, center.z); float num2 = ResolveRayDistance(settings); int num3 = Physics.RaycastNonAlloc(val5, Vector3.down, Hits, num2, _supportLayerMask, (QueryTriggerInteraction)1); if (num3 <= 0) { return false; } float num4 = float.MaxValue; float num5 = 0f; bool flag = false; for (int j = 0; j < num3; j++) { RaycastHit val6 = Hits[j]; Collider collider = ((RaycastHit)(ref val6)).collider; if (!((Object)(object)collider == (Object)null) && !IsExcludedSupport(collider, mace) && IsFinite(((RaycastHit)(ref val6)).point.y) && !(Vector3.Dot(((RaycastHit)(ref val6)).normal, Vector3.up) < 0.35f) && !(((RaycastHit)(ref val6)).distance >= num4)) { num4 = ((RaycastHit)(ref val6)).distance; num5 = ((RaycastHit)(ref val6)).point.y; flag = true; } } if (!flag || !IsFinite(num5)) { return false; } float num6 = num - num5; if (!IsFinite(num6)) { return false; } if (num6 < 0f) { num6 = 0f; } result.Clearance = num6; result.LowestY = num; result.SupportY = num5; result.Valid = true; return true; } catch (Exception) { result = default(Result); return false; } } private static bool IsEligibleTargetCollider(Collider collider, EnemyRigidbody enemyRigidbody) { if ((Object)(object)collider == (Object)null) { return false; } if (!collider.enabled || !((Component)collider).gameObject.activeInHierarchy || collider.isTrigger) { return false; } if ((Object)(object)enemyRigidbody != (Object)null && (Object)(object)enemyRigidbody.playerCollision == (Object)(object)collider) { return false; } int layer = ((Component)collider).gameObject.layer; if (layer == _playerOnlyCollisionLayer || layer == _triggersLayer || layer == _playerLayer) { return false; } if (HasExcludedName(((Object)((Component)collider).gameObject).name)) { return false; } return true; } private static bool IsExcludedSupport(Collider collider, PhysGrabObject mace) { if ((Object)(object)collider == (Object)null) { return true; } if ((Object)(object)((Component)collider).GetComponentInParent<EnemyRigidbody>() != (Object)null || (Object)(object)((Component)collider).GetComponentInParent<Enemy>() != (Object)null) { return true; } PhysGrabObject componentInParent = ((Component)collider).GetComponentInParent<PhysGrabObject>(); if ((Object)(object)componentInParent != (Object)null && componentInParent.isEnemy) { return true; } int layer = ((Component)collider).gameObject.layer; if (layer == _playerOnlyCollisionLayer || layer == _playerLayer || (Object)(object)((Component)collider).GetComponentInParent<PlayerAvatar>() != (Object)null) { return true; } if ((Object)(object)mace != (Object)null && ((Object)(object)((Component)collider).gameObject == (Object)(object)((Component)mace).gameObject || ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent == (Object)(object)mace))) { return true; } return false; } private static bool HasExcludedName(string objectName) { if (string.IsNullOrEmpty(objectName)) { return false; } if (objectName.IndexOf("debug", StringComparison.OrdinalIgnoreCase) < 0 && objectName.IndexOf("ref plane", StringComparison.OrdinalIgnoreCase) < 0 && objectName.IndexOf("refplane", StringComparison.OrdinalIgnoreCase) < 0) { return objectName.IndexOf("ref_plane", StringComparison.OrdinalIgnoreCase) >= 0; } return true; } private static float ResolveRayDistance(MaceSettings settings) { float num = (((Object)(object)settings != (Object)null) ? settings.targetClearanceRayDistance : 0f); if (!IsFinite(num) || num <= 0f) { return 10f; } return num; } private static void EnsureLayers() { if (!_layersInitialized) { _layersInitialized = true; _supportLayerMask = LayerMask.GetMask(new string[4] { "Default", "PhysGrabObject", "PhysGrabObjectHinge", "PhysGrabObjectCart" }); _playerOnlyCollisionLayer = LayerMask.NameToLayer("PlayerOnlyCollision"); _triggersLayer = LayerMask.NameToLayer("Triggers"); _playerLayer = LayerMask.NameToLayer("Player"); } } private static bool IsFinite(float value) { if (!float.IsNaN(value)) { return !float.IsInfinity(value); } return false; } } [HarmonyPatch(typeof(ItemMelee), "StateSetRPC", new Type[] { typeof(int), typeof(PhotonMessageInfo) })] internal class MeleeStatePatch { private static void Prefix(ItemMelee __instance, out State __state) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected I4, but got Unknown __state = (State)(int)__instance.currentState; } private static void Postfix(ItemMelee __instance, int _newState, State __state) { //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) //IL_0008: 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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) State val = (State)_newState; if (__instance.currentState == val && __state != val && MaceBehaviour.TryGet(__instance, out var behaviour) && (Object)(object)behaviour != (Object)null) { behaviour.OnMeleeStateApplied(__state, val); } } } [BepInPlugin("Luca.Mace", "Mace", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInProcess("REPO.exe")] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "Luca.Mace"; internal static ManualLogSource Log; internal static ConfigEntry<int> BaseDamage; internal static ConfigEntry<bool> EnableHeavyCost; internal static ConfigEntry<bool> DetailedHitLogging; internal const int BaseDamageMin = 50; internal const int BaseDamageMax = 150; private static readonly string[] PatchTypeNames = new string[2] { "Mace.MaceEnemyHurtPatch", "Mace.MeleeStatePatch" }; private Harmony _harmony; internal static bool HeavyCostEnabled { get { if (EnableHeavyCost != null) { return EnableHeavyCost.Value; } return true; } } internal static bool DetailedHitLoggingEnabled { get { if (DetailedHitLogging != null) { return DetailedHitLogging.Value; } return false; } } internal static int ClampBaseDamage(int value) { return Math.Max(50, Math.Min(150, value)); } internal static int ResolveBaseDamage(MaceSettings settings) { if (BaseDamage != null) { return ClampBaseDamage(BaseDamage.Value); } if (!((Object)(object)settings != (Object)null)) { return 0; } return settings.baseDamage; } private void Awake() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; BaseDamage = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BaseDamage", 100, new ConfigDescription("基础伤害(落点高度不超过 deadHeight 时的伤害,也是判定“特殊/重击”的基准),有效范围 50~150,运行时对配置值夹取,越界按边界值生效(默认 100)。只影响运行时有效值,不会改写 prefab 资产里的 MaceSettings.baseDamage。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 150), Array.Empty<object>())); EnableHeavyCost = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableHeavyCost", true, "是否启用高伤害多倍扣电:伤害超过 heavyCostDamageThreshold 时按 heavyCostBars 扣电。关闭后无论伤害多少都只扣 normalCostBars。"); DetailedHitLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "EnableDetailedHitLogging", false, "是否输出 [MaceHit] 结构化详细命中日志(理论伤害、实际扣血、各阈值拐点、扣电前后电量)。默认关闭;开启后每次成功命中额外输出一条详细日志。"); int value = BaseDamage.Value; int num = ClampBaseDamage(value); string text = ((((BaseUnityPlugin)this).Config != null) ? ((BaseUnityPlugin)this).Config.ConfigFilePath : "<unknown>"); Log.LogInfo((object)("[Mace] 配置加载完成:配置文件=" + text + " BaseDamage=" + num + "(生效值,配置原始值=" + value + ") EnableHeavyCost=" + EnableHeavyCost.Value + " EnableDetailedHitLogging=" + DetailedHitLogging.Value)); _harmony = new Harmony("Luca.Mace"); PatchAllIsolated(); Log.LogInfo((object)"Mace plugin loaded."); } private void PatchAllIsolated() { int num = 0; for (int i = 0; i < PatchTypeNames.Length; i++) { string text = PatchTypeNames[i]; Type type; try { type = AccessTools.TypeByName(text); } catch (Exception ex) { num++; Log.LogError((object)("[Mace] 查找补丁类 `" + text + "` 失败(只跳过这一条):" + ex.Message)); continue; } if (type == null) { num++; Log.LogWarning((object)("[Mace] 未找到补丁类 `" + text + "`(对应源文件可能尚未加入工程),已跳过。")); continue; } try { _harmony.CreateClassProcessor(type).Patch(); Log.LogInfo((object)("[Mace] 已注册补丁类 `" + type.FullName + "`。")); } catch (Exception arg) { num++; Log.LogError((object)$"[Mace] 补丁类 `{type.FullName}` 注册失败(只降级这一条):{arg}"); } } if (num > 0)