using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SlidingCompany")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Lethal Company mod that allows the player to crouch-slide.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SlidingCompany")]
[assembly: AssemblyTitle("SlidingCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 SlidingCompany
{
public class PlayerSlideController : MonoBehaviour
{
public PlayerControllerB playerController;
public float slideSpeed;
public float initialSlideSpeedBoost = 15f;
public float slideFriction = 0.1f;
public float friction = 0.97f;
public float airFriction = 0.99f;
public float maxSlideAngleChange = 30f;
private const float gravity = 50f;
private const float initialSlideStaminaCost = 0.08f;
private const float carriedItemWeightMultiplier = 2f;
private const float slideStaminaDrain = 0f;
private const float stopSlideSpeed = 0.5f;
private bool isSliding;
private bool isCrouching;
private PhysicMaterial originalMaterial;
private PhysicMaterial slideMaterial;
private Vector3 lastSlideDirection = Vector3.zero;
private AudioSource slidingAudio;
private static async Task<AudioClip> GetAudioClip(string filePath, AudioType fileType)
{
//IL_0016: 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)
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(filePath, fileType);
try
{
UnityWebRequestAsyncOperation result = www.SendWebRequest();
while (!((AsyncOperation)result).isDone)
{
await Task.Delay(100);
}
if ((int)www.result == 2)
{
Debug.Log((object)www.error);
return null;
}
return DownloadHandlerAudioClip.GetContent(www);
}
finally
{
((IDisposable)www)?.Dispose();
}
}
private async void Start()
{
originalMaterial = ((Collider)playerController.thisController).material;
slideMaterial = new PhysicMaterial("PlayerSlideMaterial");
slideMaterial.staticFriction = slideFriction;
slideMaterial.dynamicFriction = slideFriction;
string text = Path.Combine(Paths.PluginPath, "undefined-SlidingCompany", "SlidingCompany", "concrete.wav");
Debug.Log((object)("Attempting to load concrete audio source at: " + text));
AudioClip val = await GetAudioClip(text, (AudioType)20);
if ((Object)(object)val != (Object)null)
{
Debug.Log((object)"Loaded concrete audio clip.");
Debug.Log((object)("Loaded concrete audio data status: " + val.LoadAudioData()));
slidingAudio = ((Component)playerController.thisController).gameObject.AddComponent<AudioSource>();
if ((Object)(object)slidingAudio != (Object)null)
{
Debug.Log((object)"Successfully attached an AudioSource to player gameobject");
slidingAudio.clip = val;
slidingAudio.playOnAwake = false;
slidingAudio.loop = true;
}
else
{
Debug.Log((object)"Failed to attach an AudioSource to player gameobject");
}
}
else
{
Debug.Log((object)"Failed to load concrete audio clip");
}
}
private void OnSlideStart()
{
isSliding = true;
playerController.playerBodyAnimator.SetBool("Walking", false);
playerController.playerBodyAnimator.SetBool("Sprinting", false);
playerController.playerBodyAnimator.SetBool("Jumping", false);
playerController.playerBodyAnimator.SetBool("crouching", true);
}
private void SlideUpdate(Vector3 slideDirection)
{
//IL_0098: 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_00a9: 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)
playerController.playerBodyAnimator.SetBool("Walking", false);
playerController.playerBodyAnimator.SetBool("Sprinting", false);
playerController.playerBodyAnimator.SetBool("Jumping", false);
playerController.playerBodyAnimator.SetBool("crouching", true);
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Sprint", false).Disable();
((Collider)playerController.thisController).material = slideMaterial;
playerController.thisController.Move(slideDirection * slideSpeed * Time.fixedDeltaTime);
playerController.sprintMeter = Mathf.Clamp(playerController.sprintMeter - 0f, 0f, 1f);
}
private void UpdateSlideAudio()
{
if (!((Object)(object)slidingAudio != (Object)null))
{
return;
}
if (isSliding)
{
if (!slidingAudio.isPlaying)
{
slidingAudio.Play();
}
}
else if (slidingAudio.isPlaying)
{
slidingAudio.Stop();
}
}
private void OnSlideEnd()
{
isSliding = false;
if ((Object)(object)slidingAudio != (Object)null && slidingAudio.isPlaying)
{
slidingAudio.Stop();
}
((Collider)playerController.thisController).material = originalMaterial;
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Sprint", false).Enable();
FixAnimations();
}
private void FixAnimations()
{
if (!isSliding)
{
bool flag = (bool)typeof(PlayerControllerB).GetField("isJumping", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(playerController);
bool flag2 = (bool)typeof(PlayerControllerB).GetField("isWalking", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(playerController);
playerController.playerBodyAnimator.SetBool("Jumping", flag);
playerController.playerBodyAnimator.SetBool("Walking", flag2);
playerController.playerBodyAnimator.SetBool("Sprinting", playerController.isSprinting);
playerController.playerBodyAnimator.SetBool("crouching", playerController.isCrouching);
}
else
{
playerController.playerBodyAnimator.SetBool("Walking", false);
playerController.playerBodyAnimator.SetBool("Sprinting", false);
playerController.playerBodyAnimator.SetBool("Jumping", false);
playerController.playerBodyAnimator.SetBool("crouching", true);
}
}
private bool ShouldUpdate()
{
if ((!((NetworkBehaviour)playerController).IsOwner || !playerController.isPlayerControlled || (((NetworkBehaviour)playerController).IsServer && !playerController.isHostPlayerObject)) && !playerController.isTestingPlayer)
{
return false;
}
return true;
}
private void Update()
{
if (playerController.isPlayerDead)
{
isSliding = false;
isCrouching = false;
}
UpdateSlideAudio();
if (ShouldUpdate())
{
FixAnimations();
}
}
private float getWeightMultiplier()
{
float num = playerController.carryWeight - 1f;
return 1f + num * 2f;
}
private float getFriction()
{
if (playerController.thisController.isGrounded)
{
return friction;
}
return airFriction;
}
private void FixedUpdate()
{
//IL_00dd: 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_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
//IL_02db: Unknown result type (might be due to invalid IL or missing references)
//IL_02df: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0374: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0348: Unknown result type (might be due to invalid IL or missing references)
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
//IL_0354: Unknown result type (might be due to invalid IL or missing references)
if (!ShouldUpdate())
{
return;
}
bool flag = (bool)typeof(PlayerControllerB).GetField("isJumping", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(playerController);
bool flag2 = isSliding;
Vector3 val;
if (!isCrouching)
{
isCrouching = playerController.isCrouching;
int num;
if (!playerController.isExhausted && !playerController.isPlayerDead && playerController.sprintMeter >= 0.08f * getWeightMultiplier() && isCrouching)
{
val = playerController.thisController.velocity;
num = ((((Vector3)(ref val)).magnitude > 0f) ? 1 : 0);
}
else
{
num = 0;
}
isSliding = (byte)num != 0;
if (isSliding && playerController.thisController.isGrounded)
{
val = playerController.thisController.velocity;
slideSpeed = ((Vector3)(ref val)).magnitude + initialSlideSpeedBoost / getWeightMultiplier();
playerController.sprintMeter = Mathf.Clamp(playerController.sprintMeter - 0.08f * getWeightMultiplier(), 0f, 1f);
lastSlideDirection = Vector3.zero;
}
else if (isSliding)
{
isCrouching = false;
}
}
else if (!playerController.isCrouching)
{
isCrouching = false;
isSliding = false;
}
if (playerController.isPlayerDead || playerController.isClimbingLadder)
{
isSliding = false;
isCrouching = false;
slideSpeed = 0f;
}
if (flag2 && !isSliding)
{
OnSlideEnd();
return;
}
if (!flag2 && isSliding)
{
OnSlideStart();
}
slideSpeed *= getFriction();
if (Mathf.Abs(slideSpeed) <= 0.5f)
{
slideSpeed = 0f;
}
if (flag || !playerController.thisController.isGrounded)
{
playerController.thisController.Move(lastSlideDirection * slideSpeed * Time.fixedDeltaTime);
}
if (!isSliding && !isCrouching)
{
OnSlideEnd();
return;
}
UpdateSlideAudio();
Ray val2 = default(Ray);
((Ray)(ref val2))..ctor(((Component)playerController.gameplayCamera).transform.position, Vector3.down);
val = ((Component)playerController.gameplayCamera).transform.forward;
Vector3 normalized = ((Vector3)(ref val)).normalized;
if (playerController.thisController.isGrounded && isSliding)
{
RaycastHit val3 = default(RaycastHit);
Physics.Raycast(val2, ref val3, 20f, playerController.playersManager.allPlayersCollideWithMask, (QueryTriggerInteraction)1);
val = Vector3.ProjectOnPlane(normalized, ((RaycastHit)(ref val3)).normal);
normalized = ((Vector3)(ref val)).normalized;
float num2 = 0f - Vector3.Dot(normalized, Vector3.up);
slideSpeed += num2 * 50f * playerController.carryWeight * Time.fixedDeltaTime;
if (Mathf.Abs(slideSpeed) <= 0.5f)
{
slideSpeed = 0f;
}
lastSlideDirection = new Vector3(normalized.x, normalized.y, normalized.z);
}
if (isSliding && Mathf.Abs(slideSpeed) >= 0.5f)
{
SlideUpdate(normalized);
}
else
{
OnSlideEnd();
}
}
}
[BepInPlugin("SlidingCompany", "SlidingCompany", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SlidingCompany is loaded!");
Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
}
[HarmonyPatch(typeof(PlayerControllerB), "Start")]
[HarmonyPostfix]
private static void AttachPlayerSlideScript(PlayerControllerB __instance)
{
((Component)__instance.thisPlayerBody).gameObject.AddComponent<PlayerSlideController>().playerController = __instance;
}
[HarmonyPatch(typeof(PlayerControllerB), "Crouch_performed")]
[HarmonyPrefix]
private static bool AllowCrouchWhileJumping(PlayerControllerB __instance, CallbackContext context)
{
if (!((CallbackContext)(ref context)).performed)
{
return false;
}
if (__instance.quickMenuManager.isMenuOpen)
{
return false;
}
if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
{
return false;
}
if (__instance.inSpecialInteractAnimation || __instance.isTypingChat)
{
return false;
}
__instance.Crouch(!__instance.isCrouching);
__instance.playerBodyAnimator.SetBool("Jumping", false);
if (__instance.isCrouching)
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Sprint", false).Disable();
}
return false;
}
[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
[HarmonyPrefix]
private static bool AllowJumpWhileCrouching(PlayerControllerB __instance, CallbackContext context, ref bool ___isJumping, ref float ___playerSlidingTimer, ref Coroutine ___jumpCoroutine)
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: 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)
if (__instance.quickMenuManager.isMenuOpen)
{
return false;
}
if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
{
return false;
}
if (__instance.inSpecialInteractAnimation)
{
return false;
}
if (__instance.isTypingChat)
{
return false;
}
if (__instance.isMovementHindered > 0 && !__instance.isUnderwater)
{
return false;
}
if (__instance.isExhausted)
{
return false;
}
bool flag = Physics.Raycast(new Ray(((Component)__instance).transform.position, Vector3.down), 0.15f, StartOfRound.Instance.allPlayersCollideWithMask, (QueryTriggerInteraction)1);
if ((__instance.thisController.isGrounded || (!___isJumping && flag)) && !___isJumping && (!__instance.isPlayerSliding || ___playerSlidingTimer > 2.5f))
{
___playerSlidingTimer = 0f;
___isJumping = true;
__instance.isCrouching = false;
__instance.playerBodyAnimator.SetBool("Crouching", false);
__instance.sprintMeter = Mathf.Clamp(__instance.sprintMeter - 0.08f, 0f, 1f);
__instance.movementAudio.PlayOneShot(StartOfRound.Instance.playerJumpSFX);
if (___jumpCoroutine != null)
{
((MonoBehaviour)__instance).StopCoroutine(___jumpCoroutine);
}
MethodInfo method = typeof(PlayerControllerB).GetMethod("PlayerJump", BindingFlags.Instance | BindingFlags.NonPublic);
___jumpCoroutine = ((MonoBehaviour)__instance).StartCoroutine((IEnumerator)method.Invoke(__instance, new object[0]));
}
return false;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "SlidingCompany";
public const string PLUGIN_NAME = "SlidingCompany";
public const string PLUGIN_VERSION = "1.0.0";
}
}