// System
using System;
using System.Reflection;
// Unity
using UnityEngine;
// GUPS - AntiCheat - Core
using GUPS.AntiCheat.Core.Punisher;
namespace GUPS.AntiCheat.Punisher
{
///
/// The flip camera punisher flips the camera view horizontally or vertically. Can be very annoying for cheaters in first person shooters.
///
[Serializable]
[Obfuscation(Exclude = true)]
public class FlipCameraPunisher : MonoBehaviour, IPunisher
{
// Name
#region Name
///
/// The name of the punisher.
///
public String Name => "Flip Camera Punisher";
#endregion
// Platform
#region Platform
///
/// Is supported on all platforms.
///
public bool IsSupported => true;
///
/// Gets or sets whether the punisher is active and can administer punitive actions (Default: true).
///
[SerializeField]
[Header("Punisher - Settings")]
[Tooltip("Gets or sets whether the punisher is active and can administer punitive actions (Default: true).")]
private bool isActive = true;
///
/// Gets or sets whether the punisher is active and can administer punitive actions (Default: true).
///
public bool IsActive { get => this.isActive; set => this.isActive = value; }
#endregion
// Threat Rating
#region Threat Rating
///
/// Is a funny punishment, and can in first persion shooters be very annoying for cheaters (Default: 450).
///
[SerializeField]
[Tooltip("Is a funny punishment, and can in first persion shooters be very annoying for cheaters (Default: 450).")]
private uint threatRating = 450;
///
/// Is a funny punishment, and can in first persion shooters be very annoying for cheaters (Default: 450).
///
public uint ThreatRating => this.threatRating;
#endregion
// Punishment
#region Punishment
///
/// Stores if the camera has been flipped.
///
private bool isFlipped = false;
///
/// Flip / mirror the camera view horizontally or vertically.
///
[SerializeField]
[Tooltip("Flip / mirror the camera view horizontally or vertically.")]
private bool flipHorizontal = true;
///
/// Returns if the punisher should only administer punitive actions once or any time the threat level exceeds the threat rating.
///
public bool PunishOnce => true;
///
/// Returns if the punisher has administered punitive actions.
///
public bool HasPunished => this.isFlipped;
///
/// Flip / mirror the camera view horizontally or vertically.
///
public void Punish()
{
// If already flipped, return.
if(this.isFlipped)
{
return;
}
// Get the main camera.
var targetCamera = Camera.main;
// Flip the camera.
if (this.flipHorizontal)
{
// Horizontal flip.
Matrix4x4 proj = targetCamera.projectionMatrix;
proj.m11 = -proj.m11;
proj.m13 = -proj.m13;
targetCamera.projectionMatrix = proj;
GL.invertCulling = true;
}
else
{
// Vertical flip.
Matrix4x4 proj = targetCamera.projectionMatrix;
proj.m00 = -proj.m00;
proj.m01 = -proj.m01;
targetCamera.projectionMatrix = proj;
GL.invertCulling = true;
}
// Set the flag to true.
this.isFlipped = true;
}
#endregion
}
}