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 CombatMode v1.0.0
CombatMode.dll
Decompiled 4 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("CombatMode")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("CombatMode")] [assembly: AssemblyTitle("CombatMode")] [assembly: AssemblyVersion("1.0.0.0")] [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 CombatMode { internal static class CombatHit { public const int SurfaceNone = -1; public const int SurfaceEnemy = -2; public const int SurfacePlayer = -3; private const int HitMask = 1084754248; private const int RoomLayer = 8; private const int CollidersLayer = 11; private const int SceneryMask = 2304; private const float Radius = 0.25f; private const float Reach = 1f; private const int Damage = 1; public static void TryHit(PlayerControllerB player, CombatState state) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0104: 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_00fc: 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_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) state.HitChecked = true; Transform transform = ((Component)player.gameplayCamera).transform; Vector3 position = transform.position; Vector3 forward = transform.forward; IHittable hittable = default(IHittable); RaycastHit val = default(RaycastHit); foreach (RaycastHit item in from h in Physics.SphereCastAll(position, 0.25f, forward, 1f, 1084754248, (QueryTriggerInteraction)2) orderby ((RaycastHit)(ref h)).distance select h) { RaycastHit current = item; int layer = ((Component)((RaycastHit)(ref current)).transform).gameObject.layer; if (layer != 8 && layer != 11 && !((Object)(object)((RaycastHit)(ref current)).transform == (Object)(object)((Component)player).transform) && ((Component)((RaycastHit)(ref current)).transform).TryGetComponent<IHittable>(ref hittable) && (!(((RaycastHit)(ref current)).point != Vector3.zero) || !Physics.Linecast(position, ((RaycastHit)(ref current)).point, ref val, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))) { Vector3 point = ((((RaycastHit)(ref current)).point == Vector3.zero) ? (position + forward * 0.5f) : ((RaycastHit)(ref current)).point); if (TryHitTarget(player, state, ((RaycastHit)(ref current)).transform, hittable, forward, point)) { return; } } } RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(position, forward, ref val2, 1f, 2304, (QueryTriggerInteraction)1)) { Plugin.Log.LogDebug((object)("Punch hit scenery: " + ((Object)((RaycastHit)(ref val2)).collider).name)); OnHit(player, state, SurfaceIndex(((RaycastHit)(ref val2)).collider), ((RaycastHit)(ref val2)).point); } } private static bool TryHitTarget(PlayerControllerB player, CombatState state, Transform t, IHittable hittable, Vector3 dir, Vector3 point) { //IL_01b6: 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_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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_0101: Unknown result type (might be due to invalid IL or missing references) EnemyAICollisionDetect component = ((Component)t).GetComponent<EnemyAICollisionDetect>(); if ((Object)(object)component != (Object)null) { EnemyAI mainScript = component.mainScript; if ((Object)(object)mainScript == (Object)null || mainScript.isEnemyDead) { return false; } if (StartOfRound.Instance.hangarDoorsClosed && mainScript.isInsidePlayerShip != player.isInHangarShipRoom) { return false; } int enemyHP = mainScript.enemyHP; if (!hittable.Hit(1, dir, player, true, -1)) { return false; } bool flag = (Object)(object)mainScript.enemyType != (Object)null && mainScript.enemyType.canDie && mainScript.enemyHP < enemyHP; if (flag) { CombatKnockback.Push(((NetworkBehaviour)mainScript).NetworkObject, dir); } Plugin.Log.LogDebug((object)string.Format("Punch hit enemy {0}: HP {1} -> {2}{3}", mainScript.enemyType?.enemyName ?? ((Object)mainScript).name, enemyHP, mainScript.enemyHP, flag ? "" : " (no damage, no knockback)")); OnHit(player, state, -2, point); return true; } PlayerControllerB component2 = ((Component)t).GetComponent<PlayerControllerB>(); if ((Object)(object)component2 != (Object)null) { if ((Object)(object)component2 == (Object)(object)player || component2.isPlayerDead || !component2.isPlayerControlled || (Object)(object)component2.inAnimationWithEnemy != (Object)null) { return false; } bool flag2 = component2.AllowPlayerDeath(); if (flag2) { component2.DamagePlayerFromOtherClientServerRpc(1, dir, (int)player.playerClientId); } CombatKnockback.Push(((NetworkBehaviour)component2).NetworkObject, dir); Plugin.Log.LogDebug((object)$"Punch hit player {component2.playerUsername} (health before: {component2.health}, damage: {(flag2 ? 1 : 0)})"); OnHit(player, state, flag2 ? (-3) : (-2), point); return true; } OnHit(player, state, -1, point); return true; } private static void OnHit(PlayerControllerB player, CombatState state, int surface, Vector3 point) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) state.StartRecoil(); CombatSound.PlayHit(player, surface); CombatNet.SendHit(player, surface); if ((Object)(object)RoundManager.Instance != (Object)null) { RoundManager.Instance.PlayAudibleNoise(point, 10f, 0.6f, 0, player.isInHangarShipRoom && StartOfRound.Instance.hangarDoorsClosed, 0); } } private static int SurfaceIndex(Collider col) { FootstepSurface[] footstepSurfaces = StartOfRound.Instance.footstepSurfaces; for (int i = 0; i < footstepSurfaces.Length; i++) { if (footstepSurfaces[i].surfaceTag == ((Component)col).gameObject.tag) { return i; } } return -1; } } internal static class CombatKnockback { private const float PushDuration = 0.12f; private const float PlayerGravity = 38f; private static readonly FieldRef<PlayerControllerB, bool> forcePositionSync = AccessTools.FieldRefAccess<PlayerControllerB, bool>("updatePositionForNewlyJoinedClient"); public static void Push(NetworkObject target, Vector3 direction) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0046: 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) float value = Plugin.KnockbackDistance.Value; if (!((Object)(object)target == (Object)null) && !(value <= 0f)) { direction = Vector3.ProjectOnPlane(direction, Vector3.up); if (!(((Vector3)(ref direction)).sqrMagnitude < 1E-06f)) { Vector3 push = ((Vector3)(ref direction)).normalized * value; CombatNet.SendKnockback(target, push); } } } public static void ApplyIfOwner(NetworkObject target, Vector3 push) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)target == (Object)null || !target.IsOwner) { return; } PlayerControllerB component = ((Component)target).GetComponent<PlayerControllerB>(); if ((Object)(object)component != (Object)null) { if (!((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController) && !component.isPlayerDead && (Object)(object)CombatInput.Instance != (Object)null) { ((MonoBehaviour)CombatInput.Instance).StartCoroutine(PushPlayer(component, push)); } return; } EnemyAI component2 = ((Component)target).GetComponent<EnemyAI>(); if ((Object)(object)component2 != (Object)null && !component2.isEnemyDead && (Object)(object)CombatInput.Instance != (Object)null) { ((MonoBehaviour)CombatInput.Instance).StartCoroutine(PushEnemy(component2, push)); } } private static float PushCurve(float t) { return 1f - Mathf.Pow(1f - Mathf.Clamp01(t / 0.12f), 3f); } private static IEnumerator PushPlayer(PlayerControllerB player, Vector3 push) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) CharacterController controller = player.thisController; float value = Plugin.KnockbackHop.Value; bool hopped = false; if (value > 0f && controller.isGrounded && !player.isClimbingLadder && !player.inSpecialInteractAnimation) { float num = Mathf.Sqrt(76f * value); player.fallValue = num; player.fallValueUncapped = num; player.isFallingFromJump = true; hopped = true; } Vector3 done = Vector3.zero; float t = 0f; while (t < 0.12f) { t += Time.deltaTime; if ((Object)(object)player == (Object)null || player.isPlayerDead || player.isClimbingLadder) { yield break; } Vector3 val = push * PushCurve(t) - done; done += val; if (((Collider)controller).enabled) { controller.Move(val); } yield return null; } if (!hopped) { forcePositionSync.Invoke(player) = true; yield break; } float timeout = Time.time + 2f; yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)player == (Object)null || !controller.isGrounded || Time.time > timeout)); yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)player == (Object)null || controller.isGrounded || Time.time > timeout)); if (!((Object)(object)player == (Object)null)) { player.isFallingFromJump = false; forcePositionSync.Invoke(player) = true; } } private static IEnumerator PushEnemy(EnemyAI enemy, Vector3 push) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) Vector3 done = Vector3.zero; float t = 0f; while (t < 0.12f) { t += Time.deltaTime; if ((Object)(object)enemy == (Object)null || enemy.isEnemyDead) { break; } Vector3 val = push * PushCurve(t) - done; done += val; if ((Object)(object)enemy.agent != (Object)null && ((Behaviour)enemy.agent).enabled && enemy.agent.isOnNavMesh) { enemy.agent.Move(val); } yield return null; } } } internal static class CombatNet { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__ReceiveKnockback; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static HandleNamedMessageDelegate <>9__5_0; public static HandleNamedMessageDelegate <>9__5_1; public static HandleNamedMessageDelegate <>9__5_2; internal void <EnsureRegistered>b__5_0(ulong sender, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Receive("Borgez.CombatMode.Stance", sender, reader); } internal void <EnsureRegistered>b__5_1(ulong sender, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Receive("Borgez.CombatMode.Punch", sender, reader); } internal void <EnsureRegistered>b__5_2(ulong sender, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Receive("Borgez.CombatMode.Hit", sender, reader); } } private const string StanceMsg = "Borgez.CombatMode.Stance"; private const string PunchMsg = "Borgez.CombatMode.Punch"; private const string HitMsg = "Borgez.CombatMode.Hit"; private const string KnockbackMsg = "Borgez.CombatMode.Knockback"; private static CustomMessagingManager registeredOn; public static void EnsureRegistered() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_0078: 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_0083: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown //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_00d3: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; CustomMessagingManager val = (((Object)(object)singleton != (Object)null && singleton.IsListening) ? singleton.CustomMessagingManager : null); if (val == registeredOn) { return; } registeredOn = val; if (val == null) { return; } object obj = <>c.<>9__5_0; if (obj == null) { HandleNamedMessageDelegate val2 = delegate(ulong sender, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Receive("Borgez.CombatMode.Stance", sender, reader); }; <>c.<>9__5_0 = val2; obj = (object)val2; } val.RegisterNamedMessageHandler("Borgez.CombatMode.Stance", (HandleNamedMessageDelegate)obj); object obj2 = <>c.<>9__5_1; if (obj2 == null) { HandleNamedMessageDelegate val3 = delegate(ulong sender, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Receive("Borgez.CombatMode.Punch", sender, reader); }; <>c.<>9__5_1 = val3; obj2 = (object)val3; } val.RegisterNamedMessageHandler("Borgez.CombatMode.Punch", (HandleNamedMessageDelegate)obj2); object obj3 = <>c.<>9__5_2; if (obj3 == null) { HandleNamedMessageDelegate val4 = delegate(ulong sender, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) Receive("Borgez.CombatMode.Hit", sender, reader); }; <>c.<>9__5_2 = val4; obj3 = (object)val4; } val.RegisterNamedMessageHandler("Borgez.CombatMode.Hit", (HandleNamedMessageDelegate)obj3); object obj4 = <>O.<0>__ReceiveKnockback; if (obj4 == null) { HandleNamedMessageDelegate val5 = ReceiveKnockback; <>O.<0>__ReceiveKnockback = val5; obj4 = (object)val5; } val.RegisterNamedMessageHandler("Borgez.CombatMode.Knockback", (HandleNamedMessageDelegate)obj4); } public static void SendStance(PlayerControllerB player, bool active) { Send("Borgez.CombatMode.Stance", player.playerClientId, active ? 1 : 0, 0uL); } public static void SendPunch(PlayerControllerB player) { Send("Borgez.CombatMode.Punch", player.playerClientId, 0, 0uL); } public static void SendHit(PlayerControllerB player, int surface) { Send("Borgez.CombatMode.Hit", player.playerClientId, surface, 0uL); } private static void Receive(string msg, ulong sender, FastBufferReader reader) { //IL_0006: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) ulong playerId = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref playerId, default(ForPrimitives)); int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); PlayerControllerB val = FindPlayer(playerId); if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)GameNetworkManager.Instance.localPlayerController) { return; } CombatState combatState = CombatState.Get(val); switch (msg) { case "Borgez.CombatMode.Stance": combatState.Active = num != 0; break; case "Borgez.CombatMode.Punch": combatState.StartPunch(); combatState.HitChecked = true; CombatSound.PlayPunch(val); break; case "Borgez.CombatMode.Hit": combatState.StartRecoil(); CombatSound.PlayHit(val, num); break; } NetworkManager singleton = NetworkManager.Singleton; if (!singleton.IsServer) { return; } foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { if (connectedClientsId != sender && connectedClientsId != 0L) { Send(msg, playerId, num, connectedClientsId); } } } private unsafe static void Send(string msg, ulong playerId, int value, ulong target) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening || registeredOn == null) { return; } if (singleton.IsServer && target == 0L) { foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { if (connectedClientsId != 0L) { Send(msg, playerId, value, connectedClientsId); } } return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(12, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref playerId, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref value, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessage(msg, target, val, (NetworkDelivery)2); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } public static void SendKnockback(NetworkObject target, Vector3 push) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.IsListening) { ulong ownerClientId = target.OwnerClientId; if (ownerClientId == singleton.LocalClientId) { CombatKnockback.ApplyIfOwner(target, push); } else if (registeredOn != null) { SendKnockbackTo(singleton.IsServer ? ownerClientId : 0, target.NetworkObjectId, push); } } } private static void ReceiveKnockback(ulong sender, FastBufferReader reader) { //IL_0006: 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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) ulong num = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref num, default(ForPrimitives)); Vector3 push = default(Vector3); ((FastBufferReader)(ref reader)).ReadValueSafe(ref push); NetworkManager singleton = NetworkManager.Singleton; if (singleton.SpawnManager.SpawnedObjects.TryGetValue(num, out var value)) { if (value.OwnerClientId == singleton.LocalClientId) { CombatKnockback.ApplyIfOwner(value, push); } else if (singleton.IsServer) { SendKnockbackTo(value.OwnerClientId, num, push); } } } private unsafe static void SendKnockbackTo(ulong client, ulong objectId, Vector3 push) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(20, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref objectId, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref push); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("Borgez.CombatMode.Knockback", client, val, (NetworkDelivery)2); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } private static PlayerControllerB FindPlayer(ulong playerId) { StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null) { return null; } PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if ((Object)(object)val != (Object)null && val.isPlayerControlled && val.playerClientId == playerId) { return val; } } return null; } } internal static class CombatPose { private class Limb { public Transform Upper; public Transform Lower; public Transform End; public Transform[] Knuckles = (Transform[])(object)new Transform[0]; public Transform[] Fingers = (Transform[])(object)new Transform[0]; public Quaternion[] OpenLocal = (Quaternion[])(object)new Quaternion[0]; public bool Valid { get { if ((Object)(object)Upper != (Object)null && (Object)(object)Lower != (Object)null) { return (Object)(object)End != (Object)null; } return false; } } public float Length => Vector3.Distance(Upper.position, Lower.position) + Vector3.Distance(Lower.position, End.position); } private class Rig { public Transform Hips; public Transform Chest; public Limb ArmL; public Limb ArmR; public Limb LegL; public Limb LegR; public Vector3 LastHipsBase; public Vector3 LastHipsSet; } private class PlayerRigs { public Rig Body; public Rig Arms; } private struct RightArm { public float Punch; public float Recoil; public float Time; public float Yield; public float Shake => Recoil * (1f - 0.6f * Mathf.Clamp01(Time / 1.1f)); public Vector2 ShakeOffset => new Vector2(Mathf.Sin(Time * 22f), Mathf.Sin(Time * 16f + 1f)) * Shake; } private static readonly ConditionalWeakTable<PlayerControllerB, PlayerRigs> cache = new ConditionalWeakTable<PlayerControllerB, PlayerRigs>(); public static void Apply(PlayerControllerB player) { CombatState combatState = CombatState.Get(player); if (!player.isPlayerControlled || player.isPlayerDead) { combatState.Active = false; combatState.Weight = 0f; return; } combatState.Tick(); if (!(combatState.Weight <= 0f)) { PlayerRigs value = cache.GetValue(player, Build); float w = Mathf.SmoothStep(0f, 1f, combatState.Weight); RightArm right = new RightArm { Punch = combatState.PunchAmount, Recoil = combatState.RecoilAmount, Time = combatState.RecoilTime }; if (value.Body != null && (Object)(object)player.thisPlayerModel != (Object)null && ((Renderer)player.thisPlayerModel).enabled) { PoseBody(player, value.Body, w, right); } if (value.Arms != null && (Object)(object)player.thisPlayerModelArms != (Object)null && ((Renderer)player.thisPlayerModelArms).enabled && (Object)(object)player.gameplayCamera != (Object)null) { PoseFirstPersonArms(player, value.Arms, w, right); } } } private static void PoseBody(PlayerControllerB player, Rig rig, float w, RightArm right) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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_00ae: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) Transform thisPlayerBody = player.thisPlayerBody; Vector3 forward = thisPlayerBody.forward; Vector3 up = thisPlayerBody.up; Vector3 right2 = thisPlayerBody.right; if ((Object)(object)rig.Hips != (Object)null && rig.LegL.Valid && rig.LegR.Valid) { Vector3 position = rig.LegL.End.position; Vector3 position2 = rig.LegR.End.position; Quaternion rotation = rig.LegL.End.rotation; Quaternion rotation2 = rig.LegR.End.rotation; Vector3 localPosition = rig.Hips.localPosition; Vector3 val = ((localPosition == rig.LastHipsSet) ? rig.LastHipsBase : localPosition); rig.Hips.localPosition = val; float num = 0.09f * rig.LegL.Length * w; Transform hips = rig.Hips; hips.position -= up * num; rig.LastHipsBase = val; rig.LastHipsSet = rig.Hips.localPosition; SolveLeg(rig.LegL, position, rotation, forward, w); SolveLeg(rig.LegR, position2, rotation2, forward, w); } if ((Object)(object)rig.Chest != (Object)null) { rig.Chest.rotation = Quaternion.AngleAxis(10f * w, right2) * rig.Chest.rotation; } ArmGuard(rig.ArmL, forward, right2, up, -1f, new RightArm { Yield = right.Recoil }, w); ArmGuard(rig.ArmR, forward, right2, up, 1f, right, w); } private static void SolveLeg(Limb leg, Vector3 foot, Quaternion footRot, Vector3 forward, float w) { //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) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) Vector3 pole = leg.Lower.position + forward; TwoBoneIK(leg, foot, pole, 1f); leg.End.rotation = footRot; } private static void ArmGuard(Limb arm, Vector3 f, Vector3 r, Vector3 u, float side, RightArm act, float w) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_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_00f4: 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_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: 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_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018e: 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_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: 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_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) if (arm.Valid) { Vector3 position = arm.Upper.position; float length = arm.Length; float num = ((side < 0f) ? 0.65f : 0.55f); Vector3 val = position + f * (num * length) + u * (0.25f * length) - r * (side * 0.08f * length); val += (-u * 0.12f * length + r * (side * 0.08f * length)) * act.Yield; Vector3 val2 = position + f * (1.05f * length) + u * (0.1f * length) - r * (side * 0.15f * length); Vector3 val3 = position + f * (0.55f * length) + u * (0.3f * length) - r * (side * 0.05f * length); Vector3 val4 = Vector3.Lerp(Vector3.Lerp(val, val2, act.Punch), val3, act.Recoil); Vector2 shakeOffset = act.ShakeOffset; val4 += r * (shakeOffset.x * 0.05f * length) + u * (shakeOffset.y * 0.04f * length); Vector3 pole = position + f * (0.1f * length) - u * length + r * (side * 0.6f * length); TwoBoneIK(arm, val4, pole, w); PoseHand(arm, act, w, u); } } private static void PoseFirstPersonArms(PlayerControllerB player, Rig rig, float w, RightArm right) { Transform transform = ((Component)player.gameplayCamera).transform; FirstPersonArm(rig.ArmL, transform, -1f, new RightArm { Yield = right.Recoil }, w); FirstPersonArm(rig.ArmR, transform, 1f, right, w); } private static void FirstPersonArm(Limb arm, Transform cam, float side, RightArm act, float w) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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_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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //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_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) if (arm.Valid) { Vector3 position = cam.position; Vector3 forward = cam.forward; Vector3 up = cam.up; Vector3 right = cam.right; float num = ((side < 0f) ? 0.42f : 0.38f); Vector3 val = position + forward * num - up * 0.2f + right * (side * 0.19f); val += (-up * 0.06f + right * (side * 0.04f)) * act.Yield; Vector3 val2 = position + forward * 0.95f - up * 0.1f + right * (side * 0.04f); Vector3 val3 = position + forward * 0.48f - up * 0.12f + right * (side * 0.14f); Vector3 val4 = Vector3.Lerp(Vector3.Lerp(val, val2, act.Punch), val3, act.Recoil); Vector2 shakeOffset = act.ShakeOffset; val4 += right * (shakeOffset.x * 0.03f) + up * (shakeOffset.y * 0.02f); Vector3 pole = position + right * (side * 0.7f) - up * 1f - forward * 0.1f; TwoBoneIK(arm, val4, pole, w); PoseHand(arm, act, w, up); } } private static void PoseHand(Limb arm, RightArm act, float w, Vector3 up) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) StraightenWrist(arm, w); LayHandFlat(arm, up, act.Recoil * w); OpenFingers(arm, act.Recoil * w); ShakeWrist(arm, act, w); } private static void LayHandFlat(Limb arm, Vector3 up, float amount) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_0048: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) if (!(amount <= 0f) && arm.Knuckles.Length != 0) { Vector3 val = Vector3.zero; Transform[] knuckles = arm.Knuckles; foreach (Transform val2 in knuckles) { val += val2.position; } Vector3 val3 = val / (float)arm.Knuckles.Length - arm.End.position; Vector3 val4 = Vector3.ProjectOnPlane(val3, up); if (!(((Vector3)(ref val4)).sqrMagnitude < 1E-08f)) { Quaternion val5 = Quaternion.FromToRotation(val3, val4); arm.End.rotation = Quaternion.Slerp(Quaternion.identity, val5, amount) * arm.End.rotation; } } } private static void StraightenWrist(Limb arm, float w) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_0052: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) if (arm.Knuckles.Length != 0) { Vector3 val = Vector3.zero; Transform[] knuckles = arm.Knuckles; foreach (Transform val2 in knuckles) { val += val2.position; } val = val / (float)arm.Knuckles.Length - arm.End.position; Vector3 val3 = arm.End.position - arm.Lower.position; Quaternion val4 = Quaternion.FromToRotation(val, val3); arm.End.rotation = Quaternion.Slerp(Quaternion.identity, val4, w) * arm.End.rotation; } } private static void OpenFingers(Limb arm, float amount) { //IL_001d: 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) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (!(amount <= 0f)) { for (int i = 0; i < arm.Fingers.Length; i++) { arm.Fingers[i].localRotation = Quaternion.Slerp(arm.Fingers[i].localRotation, arm.OpenLocal[i], amount); } } } private static void ShakeWrist(Limb arm, RightArm act, float w) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) if (!(act.Shake <= 0f)) { Vector3 val = arm.End.position - arm.Lower.position; float num = Mathf.Sin(act.Time * 20f) * 45f * act.Shake * w; arm.End.rotation = Quaternion.AngleAxis(num, val) * arm.End.rotation; } } private static void TwoBoneIK(Limb limb, Vector3 target, Vector3 pole, float weight) { //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) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0092: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: 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_018d: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_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_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) Vector3 position = limb.Upper.position; float num = Vector3.Distance(position, limb.Lower.position); float num2 = Vector3.Distance(limb.Lower.position, limb.End.position); if (num < 0.0001f || num2 < 0.0001f) { return; } Vector3 val = target - position; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude < 0.0001f) { return; } Vector3 val2 = val / magnitude; magnitude = Mathf.Clamp(magnitude, Mathf.Abs(num - num2) + 0.001f, num + num2 - 0.001f); Vector3 val3 = Vector3.ProjectOnPlane(pole - position, val2); if (((Vector3)(ref val3)).sqrMagnitude < 1E-08f) { val3 = Vector3.ProjectOnPlane(limb.Lower.position - position, val2); } if (!(((Vector3)(ref val3)).sqrMagnitude < 1E-08f)) { ((Vector3)(ref val3)).Normalize(); float num3 = Mathf.Clamp((num * num + magnitude * magnitude - num2 * num2) / (2f * num * magnitude), -1f, 1f); float num4 = Mathf.Sqrt(1f - num3 * num3); Vector3 val4 = position + val2 * (num3 * num) + val3 * (num4 * num); Vector3 val5 = position + val2 * magnitude; Quaternion rotation = limb.Upper.rotation; Quaternion rotation2 = limb.Lower.rotation; limb.Upper.rotation = Quaternion.FromToRotation(limb.Lower.position - position, val4 - position) * rotation; Vector3 position2 = limb.Lower.position; limb.Lower.rotation = Quaternion.FromToRotation(limb.End.position - position2, val5 - position2) * limb.Lower.rotation; if (weight < 1f) { Quaternion rotation3 = limb.Upper.rotation; Quaternion rotation4 = limb.Lower.rotation; limb.Upper.rotation = Quaternion.Slerp(rotation, rotation3, weight); limb.Lower.rotation = Quaternion.Slerp(rotation2, rotation4, weight); } } } private static PlayerRigs Build(PlayerControllerB player) { PlayerRigs playerRigs = new PlayerRigs { Body = BuildRig(player.thisPlayerModel, legs: true), Arms = BuildRig(player.thisPlayerModelArms, legs: false) }; Plugin.Log.LogDebug((object)$"Rig for {player.playerUsername}: body={playerRigs.Body != null}, arms={playerRigs.Arms != null}"); return playerRigs; } private static Rig BuildRig(SkinnedMeshRenderer smr, bool legs) { if ((Object)(object)smr == (Object)null || smr.bones == null) { return null; } Rig rig = new Rig { ArmL = MakeArm(smr, "L"), ArmR = MakeArm(smr, "R"), LegL = (legs ? MakeLimb("thigh.L", "shin.L", "foot.L") : new Limb()), LegR = (legs ? MakeLimb("thigh.R", "shin.R", "foot.R") : new Limb()), Hips = (legs ? Find("spine") : null), Chest = (legs ? Find("spine.002") : null) }; if (!rig.ArmL.Valid || !rig.ArmR.Valid) { Plugin.Log.LogWarning((object)("Arm bones not found on " + ((Object)smr).name + " (custom model?): " + string.Join(", ", from b in smr.bones where (Object)(object)b != (Object)null select ((Object)b).name))); return null; } return rig; Transform Find(string name) { return ((IEnumerable<Transform>)smr.bones).FirstOrDefault((Func<Transform, bool>)((Transform b) => (Object)(object)b != (Object)null && ((Object)b).name == name)); } Limb MakeLimb(string up, string low, string end) { return new Limb { Upper = Find(up), Lower = Find(low), End = Find(end) }; } } private static Limb MakeArm(SkinnedMeshRenderer smr, string side) { //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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_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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) Transform[] bones = smr.bones; Limb limb = new Limb { Upper = Find("arm." + side + "_upper"), Lower = Find("arm." + side + "_lower"), End = Find("hand." + side) }; limb.Knuckles = (from n in new int[3] { 2, 3, 4 } select Find($"finger{n}.{side}") into t where (Object)(object)t != (Object)null select t).ToArray(); Matrix4x4[] array = (((Object)(object)smr.sharedMesh != (Object)null) ? smr.sharedMesh.bindposes : null); if (array == null || array.Length != bones.Length) { return limb; } List<Transform> list = new List<Transform>(); List<Quaternion> list2 = new List<Quaternion>(); for (int num = 1; num <= 5; num++) { string[] array2 = new string[2] { $"finger{num}.{side}", $"finger{num}.{side}.001" }; foreach (string name in array2) { int num3 = Index(name); if (num3 >= 0 && !((Object)(object)bones[num3].parent == (Object)null)) { int num4 = Array.IndexOf(bones, bones[num3].parent); if (num4 >= 0) { Matrix4x4 inverse = ((Matrix4x4)(ref array[num3])).inverse; Quaternion rotation = ((Matrix4x4)(ref inverse)).rotation; inverse = ((Matrix4x4)(ref array[num4])).inverse; Quaternion rotation2 = ((Matrix4x4)(ref inverse)).rotation; list.Add(bones[num3]); list2.Add(Quaternion.Inverse(rotation2) * rotation); } } } } limb.Fingers = list.ToArray(); limb.OpenLocal = list2.ToArray(); return limb; Transform Find(string name2) { int num5 = Index(name2); if (num5 < 0) { return null; } return bones[num5]; } int Index(string text) { return Array.FindIndex(bones, (Transform b) => (Object)(object)b != (Object)null && ((Object)b).name == text); } } } internal static class CombatSound { private static AudioClip swing; private static bool warned; private static readonly ConditionalWeakTable<PlayerControllerB, AudioSource> swingSources = new ConditionalWeakTable<PlayerControllerB, AudioSource>(); private static readonly ConditionalWeakTable<PlayerControllerB, AudioSource> hitSources = new ConditionalWeakTable<PlayerControllerB, AudioSource>(); public static void PlayPunch(PlayerControllerB player) { AudioClip val = GetSwing(); if (!((Object)(object)val == (Object)null)) { AudioSource value = swingSources.GetValue(player, CreateSource); if (!((Object)(object)value == (Object)null)) { value.pitch = Random.Range(1.15f, 1.3f); value.PlayOneShot(val, 0.9f); } } } public static void PlayHit(PlayerControllerB player, int surface) { StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null || surface == -3) { return; } AudioSource value = hitSources.GetValue(player, CreateSource); if ((Object)(object)value == (Object)null) { return; } value.pitch = Random.Range(0.95f, 1.1f); if ((Object)(object)instance.hitPlayerSFX != (Object)null) { value.PlayOneShot(instance.hitPlayerSFX, 1f); WalkieTalkie.TransmitOneShotAudio(value, instance.hitPlayerSFX, 1f); } if (surface >= 0 && surface < instance.footstepSurfaces.Length) { AudioClip hitSurfaceSFX = instance.footstepSurfaces[surface].hitSurfaceSFX; if ((Object)(object)hitSurfaceSFX != (Object)null) { value.PlayOneShot(hitSurfaceSFX, 0.6f); WalkieTalkie.TransmitOneShotAudio(value, hitSurfaceSFX, 0.6f); } } } private static AudioSource CreateSource(PlayerControllerB player) { //IL_003f: 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_0073: Invalid comparison between Unknown and I4 AudioSource itemAudio = player.itemAudio; if ((Object)(object)itemAudio == (Object)null) { return null; } AudioSource val = ((Component)itemAudio).gameObject.AddComponent<AudioSource>(); val.playOnAwake = false; val.outputAudioMixerGroup = itemAudio.outputAudioMixerGroup; val.spatialBlend = itemAudio.spatialBlend; val.rolloffMode = itemAudio.rolloffMode; val.minDistance = itemAudio.minDistance; val.maxDistance = itemAudio.maxDistance; val.dopplerLevel = 0f; if ((int)itemAudio.rolloffMode == 2) { val.SetCustomCurve((AudioSourceCurveType)0, itemAudio.GetCustomCurve((AudioSourceCurveType)0)); } return val; } private static AudioClip GetSwing() { if ((Object)(object)swing != (Object)null) { return swing; } StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.allItemsList != (Object)null) { foreach (Item items in instance.allItemsList.itemsList) { Shovel val = (((Object)(object)items != (Object)null && (Object)(object)items.spawnPrefab != (Object)null) ? items.spawnPrefab.GetComponent<Shovel>() : null); if ((Object)(object)val != (Object)null && (Object)(object)val.swing != (Object)null) { return swing = val.swing; } } } if (!warned) { warned = true; Plugin.Log.LogWarning((object)"Shovel swing sound not found; punches will be silent."); } return null; } } internal class CombatState { private static readonly ConditionalWeakTable<PlayerControllerB, CombatState> states = new ConditionalWeakTable<PlayerControllerB, CombatState>(); public const float PunchOut = 0.09f; public const float PunchHold = 0.06f; public const float PunchBack = 0.22f; public const float RecoilRetract = 0.12f; public const float RecoilDuration = 1.1f; public bool Active; public float Weight; public bool HitChecked = true; private float punchStart = -10f; private float hitTime = -10f; private float PunchTime => Time.time - punchStart; public float RecoilTime => Time.time - hitTime; public bool InRecoil => RecoilTime < 1.1f; public bool Busy { get { if (!InRecoil) { return PunchTime < 0.37f; } return true; } } public bool ReadyToCheckHit { get { if (!HitChecked) { return PunchTime >= 0.09f; } return false; } } public float PunchAmount { get { if (InRecoil) { if (!(RecoilTime < 0.12f)) { return 0f; } return Mathf.SmoothStep(1f, 0f, RecoilTime / 0.12f); } float punchTime = PunchTime; if (punchTime < 0f || punchTime > 0.37f) { return 0f; } if (punchTime < 0.09f) { return Mathf.SmoothStep(0f, 1f, punchTime / 0.09f); } if (punchTime < 0.15f) { return 1f; } return Mathf.SmoothStep(1f, 0f, (punchTime - 0.09f - 0.06f) / 0.22f); } } public float RecoilAmount { get { if (!InRecoil) { return 0f; } float recoilTime = RecoilTime; float num = Mathf.Clamp01(recoilTime / 0.1f); float num2 = Mathf.Clamp01((1.1f - recoilTime) / 0.3f); return Mathf.SmoothStep(0f, 1f, Mathf.Min(num, num2)); } } public static CombatState Get(PlayerControllerB player) { return states.GetOrCreateValue(player); } public void StartPunch() { punchStart = Time.time; hitTime = -10f; HitChecked = false; } public void StartRecoil() { hitTime = Time.time; HitChecked = true; } public void Tick() { Weight = Mathf.MoveTowards(Weight, (Active || Busy) ? 1f : 0f, Time.deltaTime * 6f); } } [BepInPlugin("Borgez.CombatMode", "CombatMode", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string Guid = "Borgez.CombatMode"; public const string Name = "CombatMode"; public const string Version = "1.0.0"; internal static ManualLogSource Log; internal static ConfigEntry<Key> StanceKey; internal static ConfigEntry<float> PunchCooldown; internal static ConfigEntry<float> KnockbackDistance; internal static ConfigEntry<float> KnockbackHop; private void Awake() { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; StanceKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "Stance key", (Key)53, "Hold this key to enter the combat stance. Punch with the left mouse button while holding it."); PunchCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "Punch cooldown", 0.45f, new ConfigDescription("Minimum time (seconds) between two punches.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>())); KnockbackDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Punch", "Knockback distance", 1.5f, new ConfigDescription("How far (in meters, roughly) enemies and players you hit are pushed back. 0 disables knockback.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>())); KnockbackHop = ((BaseUnityPlugin)this).Config.Bind<float>("Punch", "Knockback hop height", 0.2f, new ConfigDescription("Height (in meters) of the little hop a player does when knocked back. 0 disables the hop.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); new Harmony("Borgez.CombatMode").PatchAll(typeof(Plugin).Assembly); GameObject val = new GameObject("CombatMode.Runner") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)val); val.AddComponent<CombatInput>(); Log.LogInfo((object)"CombatMode 1.0.0 loaded."); } } internal class CombatInput : MonoBehaviour { private float lastPunch = -10f; public static CombatInput Instance { get; private set; } private void Awake() { Instance = this; } private void Update() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) CombatNet.EnsureRegistered(); PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if ((Object)(object)val == (Object)null) { return; } CombatState combatState = CombatState.Get(val); bool flag = CanFight(val) && Keyboard.current != null && ((ButtonControl)Keyboard.current[Plugin.StanceKey.Value]).isPressed && (combatState.Active || val.thisController.isGrounded); if (flag != combatState.Active) { combatState.Active = flag; CombatNet.SendStance(val, flag); Plugin.Log.LogDebug((object)(flag ? "Combat stance on." : "Combat stance off.")); } if (combatState.ReadyToCheckHit) { if (val.isPlayerControlled && !val.isPlayerDead) { CombatHit.TryHit(val, combatState); } else { combatState.HitChecked = true; } } if (combatState.Active && !combatState.InRecoil && Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame && Time.time - lastPunch >= Plugin.PunchCooldown.Value) { lastPunch = Time.time; combatState.StartPunch(); CombatSound.PlayPunch(val); CombatNet.SendPunch(val); } } private static bool CanFight(PlayerControllerB p) { if (p.isPlayerControlled && !p.isPlayerDead && !p.inTerminalMenu && !p.isTypingChat && !p.quickMenuManager.isMenuOpen && !p.inSpecialInteractAnimation && !p.isClimbingLadder && !p.inSpecialMenu && (Object)(object)p.currentlyHeldObjectServer == (Object)null) { return !p.performingEmote; } return false; } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] internal static class PlayerUpdatePatch { private static void Postfix(PlayerControllerB __instance) { CombatState combatState = CombatState.Get(__instance); Animator playerBodyAnimator = __instance.playerBodyAnimator; if (!(combatState.Weight <= 0f) && !((Object)(object)playerBodyAnimator == (Object)null)) { int layerIndex = playerBodyAnimator.GetLayerIndex("UpperBodyEmotes"); if (layerIndex >= 0) { playerBodyAnimator.SetLayerWeight(layerIndex, playerBodyAnimator.GetLayerWeight(layerIndex) * (1f - combatState.Weight)); } } } } [HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")] internal static class PlayerDamageLogPatch { private static void Postfix(PlayerControllerB __instance, int damageNumber) { if ((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance?.localPlayerController) { Plugin.Log.LogDebug((object)$"You took {damageNumber} damage. Health: {__instance.health}"); } } } [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] internal static class PlayerLateUpdatePatch { private static void Postfix(PlayerControllerB __instance) { CombatPose.Apply(__instance); } } }