diff --git a/.idea/.idea.MegaAPI/.idea/encodings.xml b/.idea/.idea.MegaAPI/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.MegaAPI/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.MegaAPI/.idea/indexLayout.xml b/.idea/.idea.MegaAPI/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.MegaAPI/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.MegaAPI/.idea/vcs.xml b/.idea/.idea.MegaAPI/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.MegaAPI/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MegaAPI.sln.DotSettings.user b/MegaAPI.sln.DotSettings.user new file mode 100644 index 0000000..1386bfa --- /dev/null +++ b/MegaAPI.sln.DotSettings.user @@ -0,0 +1,7 @@ + + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + \ No newline at end of file diff --git a/MegaAPI/API/Player.cs b/MegaAPI/API/Player.cs new file mode 100644 index 0000000..df05e26 --- /dev/null +++ b/MegaAPI/API/Player.cs @@ -0,0 +1,346 @@ +namespace MegaAPI.API; + +using Il2Cpp; +using Il2CppPlayer.SoundManager; +using UnityEngine; + +/// +/// The wrapper representing the in-game players. +/// +public static class Player +{ + /// + /// Gets the of the player. + /// + public static PlayerExtraMovement PlayerExtraMovement { get; internal set; } + + /// + /// Gets the of the player. + /// + public static PlayerMovement PlayerMovement { get; internal set; } + + /// + /// Gets the of the player. + /// + public static PlayerMenu PlayerMenu { get; internal set; } + + /// + /// Gets the of the player. + /// + public static SoundManager SoundManager { get; internal set; } + + /// + /// Gets the encapsulated . + /// + public static GameObject GameObject { get; internal set; } + + /// + /// Gets the 's . + /// + public static Transform Transform => PlayerMovement.transform; + + /// + /// Gets or sets the player's FOV. + /// + public static float FOV + { + get => PlayerMovement.FOV; + set => PlayerMovement.FOV = value; + } + + /// + /// Gets or sets the player's Sensitivity. + /// + public static float Sensitivity + { + get => PlayerMovement.Sensitivity; + set => PlayerMovement.SetSensitivity(value); + } + + /// + /// Gets or sets a value indicating whether the player has noclip. + /// + public static bool Noclip + { + get => PlayerMovement.noClip; + set => PlayerMovement.SetNoClip(value); + } + + /// + /// Gets or sets a value indicating whether the player has cinematic camera. + /// + public static bool CinematicCamera + { + get => PlayerMovement.cinematicCamera; + set => PlayerMovement.SetCinematicCamera(value); + } + + /// + /// Gets or sets the max speed possible to reach before it gets countered. + /// + // TODO: This makes the game in cheating mode + public static float MaxSpeedGround + { + get => PlayerMovement.maxSpeedNormal; + set => PlayerMovement.maxSpeedNormal = value; + } + + /// + /// Gets or sets the max speed possible to reach before it gets countered. + /// + // TODO: This makes the game in cheating mode + public static float MaxSpeedAir + { + get => PlayerMovement.maxSpeedAir; + set => PlayerMovement.maxSpeedAir = value; + } + + /// + /// Gets or sets the current speed. + /// + /// Try to not set the speed because you could encounter problems with the . + // TODO: This makes the game in cheating mode + public static float Speed + { + get => PlayerMovement.speed; + set => PlayerMovement.speed = value; + } + + /// + /// Gets or sets the current jump force. + /// + /// Try to not set the speed because you could encounter problems with the . + // TODO: This makes the game in cheating mode + public static float JumpForce + { + get => PlayerMovement.jumpForce; + set => PlayerMovement.jumpForce = value; + } + + /// + /// Gets or sets the current wall run tilt. + /// + /// a value less or equal to 0 will make the tilt disable. + public static float Tilt + { + get => PlayerExtraMovement.Tilt; + set + { + if (value <= 0) + { + PlayerExtraMovement.SetWallRunTiltEnabled(false); + return; + } + + PlayerExtraMovement.SetWallRunTiltEnabled(true); + PlayerExtraMovement.Tilt = value; + } + } + + /// + /// Gets a value indicating whether the player is dead. + /// + public static float CurrentCheckpoint => PlayerMovement.checkpoint; + + /// + /// Gets a value indicating whether the player is dead. + /// + public static float CurrentLevel => PlayerMovement.level; + + /// + /// Gets a value indicating whether the player is crouching. + /// + public static bool IsCrouching => PlayerMovement.crouching; + + /// + /// Gets a value indicating whether the player is grounded. + /// + public static bool IsGrounded => PlayerMovement.grounded; + + /// + /// Gets a value indicating whether the player is grounded. + /// + public static bool IsJumping => !PlayerMovement.grounded; + + /// + /// Gets a value indicating whether the player is on a slope. + /// + public static bool IsOnSlope => PlayerMovement.onSlope; + + /// + /// Gets a value indicating whether the player is wall running. + /// + public static bool IsWallRunning => PlayerExtraMovement.isWallRunning; + + /// + /// Gets a value indicating whether the player is wall jumping. + /// + public static bool IsWallJumping => PlayerExtraMovement.isWallJumping; + + /// + /// Gets a value indicating whether the player is wall running tilt enabled. + /// + public static bool IsTiltEnabled => PlayerExtraMovement.IsWallRunTiltEnabled; + + /// + /// Gets a value indicating whether the player is dead. + /// + public static bool IsDead => PlayerMovement.dead; + + /// + /// Gets a value indicating whether the game is paused. + /// + public static bool IsPaused => PlayerMenu.GameIsPaused; + + /// + /// Gets a value indicating whether the game is restarting. + /// + public static bool IsRestarting => PlayerMenu.isRestarting; + + /// + /// Gets a value indicating whether the player has open settings menu. + /// + public static bool IsSettingOpen => PlayerMenu.settingsMenuOn; + + /// + /// Sets the player gravity. + /// + /// the gravity the player can get added. + public static void SetGravity(float gravity) + { + if (gravity <= 1) + { + PlayerMovement.extraGravity = false; + } + + PlayerMovement.extraGravity = true; + PlayerMovement.extraGravityStrength = gravity; + } + + /// + /// Trigger a Fade In animation for the player. + /// + /// the duration of the fade in animation. + public static void FadeIn(float duration) => PlayerMovement.FadeIn(duration); + + /// + /// Forces the player to crouch. + /// + /// Keeps the movement of the player. + public static void ForceCrouch(bool KeepMovement = true) => PlayerMovement.StartCrouch(KeepMovement); + + /// + /// Forces the player to Jump. + /// + public static void ForceJump() => PlayerMovement.Jump(); + + /// + /// Forces the player to die. + /// + /// if the player should die with the message or not. + public static void Kill(bool withMessage = true) => PlayerMenu.Die(withMessage); + + /// + /// Opens the setting menu for the player. + /// + /// if the menu should be open or closed. + public static void OpenSettings(bool mode) + { + if (mode) + PlayerMenu.SetSettingsMenu(true); + else + PlayerMenu.ToggleSettingsMenu(); + } + + /// + /// Pauses the player. + /// + public static void Pause() => PlayerMenu.Pause(); + + /// + /// Resume the player. + /// + public static void Resume() => PlayerMenu.Resume(); + + /// + /// makes the player go to the menu. + /// + public static void BackToMenu() => PlayerMenu.backToMenu(); + + /// + /// Makes the player retry the current level and checkpoint. + /// + public static void Retry() => PlayerMenu.retry(); + + /// + /// Makes the player restart the level. + /// + public static void RestartLevel() => PlayerMenu.restartLevel(); + + /// + /// Makes the player stop all audio sources. + /// + public static void StopAllAudio() => PlayerMenu.StopAllAudio(); + + /// + /// Makes the player able to hear all audio sources. + /// + public static void ResumeAllAudio() => PlayerMenu.ResumeAllAudio(); + + /// + /// Disables the crosshair. + /// + public static void DisableCrosshair() => PlayerMenu.ForceDisableCrosshair(); + + /// + /// Enables the crosshair. + /// + public static void EnableCrosshair() => PlayerMenu.ForceEnableCrosshair(); + + /// + /// Shake the player's camera. + /// + /// the velocity the camera should shake for. + public static void ShakeCamera(float velocity) => SoundManager.HandleCameraShake(velocity); + + /// + /// Plays the death sound for the player. + /// + /// if the sound played should be the one for water. + public static void DeathSound(bool water = false) => SoundManager.DeathSound(water); + + /// + /// Plays the jump sound for the player. + /// + public static void PlayJumpSound() => SoundManager.PlayJumpSound(); + + /// + /// Plays the jump sound for the player. + /// + public static void PlayVaultSound() => SoundManager.PlayVaultSound(); + + /// + /// Plays the sneak sound for the player. + /// + public static void PlaySneakSound() => SoundManager.PlaySneakSound(); + + /// + /// Plays the dash sound for the player. + /// + public static void PlayDashSound() => SoundManager.PlayDashSound(); + + /// + /// Plays the double jump sound for the player. + /// + public static void PlayDoubleJumpSound() => SoundManager.PlayDoubleJumpSound(); + + /// + /// Plays the zoom in sound for the player. + /// + public static void PlayZoomInSound() => SoundManager.PlayZoomInSound(); + + /// + /// Plays the zoom out sound for the player. + /// + public static void PlayZoomOutSound() => SoundManager.PlayZoomOutSound(); +} diff --git a/MegaAPI/Patches/PlayerInitializer.cs b/MegaAPI/Patches/PlayerInitializer.cs new file mode 100644 index 0000000..f07529f --- /dev/null +++ b/MegaAPI/Patches/PlayerInitializer.cs @@ -0,0 +1,21 @@ +namespace MegaAPI.Patches; + +using HarmonyLib; +using Il2Cpp; +using MegaAPI.API; + +/// +/// Loads the custom commands. +/// +[HarmonyPatch(typeof(PlayerMovement), nameof(PlayerMovement.Init))] +public class PlayerInitializer +{ + [HarmonyPostfix] + private static void Postfix(PlayerMovement __instance) + { + Player.PlayerMovement = __instance; + Player.PlayerExtraMovement = __instance.extraMovement; + Player.PlayerMenu = __instance.playerMenu.GetComponent(); + Player.GameObject = __instance.gameObject; + } +}