Skip to content

Commit

Permalink
v0.1 - Open-beta
Browse files Browse the repository at this point in the history
v0.1 - Open-beta
  • Loading branch information
LDami authored Jul 15, 2022
2 parents 360cafb + 4a17e58 commit 4972ab4
Show file tree
Hide file tree
Showing 76 changed files with 10,449 additions and 1,834 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@ ASALocalRun/

# BeatPulse healthcheck temp database
healthchecksdb
/SampSharpGameMode1/App.config
/SampSharpGameMode1/App.debug.config
/SampSharpGameMode1/App.release.config
12 changes: 9 additions & 3 deletions SampSharpGameMode1.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
# Visual Studio Version 17
VisualStudioVersion = 17.2.32602.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampSharpGameMode1", "SampSharpGameMode1\SampSharpGameMode1.csproj", "{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampSharpGameMode1", "SampSharpGameMode1\SampSharpGameMode1.csproj", "{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Debug|x86.ActiveCfg = Debug|x86
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Debug|x86.Build.0 = Debug|x86
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Release|Any CPU.Build.0 = Release|Any CPU
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Release|x86.ActiveCfg = Release|x86
{F395F23B-F63C-4F3F-BA26-FF9BA370B25C}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
33 changes: 33 additions & 0 deletions SampSharpGameMode1/AdminPermissionChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using SampSharp.GameMode.SAMP.Commands.PermissionCheckers;
using SampSharp.GameMode.World;
using System;
using System.Collections.Generic;
using System.Text;

namespace SampSharpGameMode1
{
public class AdminPermissionChecker : IPermissionChecker
{
#region Implementation of IPermissionChecker

/// <summary>
/// Gets the message displayed when the player is denied permission.
/// </summary>
public string Message
{
get { return "You need to be admin to run this command."; }
}

/// <summary>
/// Checks the permission for the specified player.
/// </summary>
/// <param name="player">The player.</param>
/// <returns>true if allowed; false if denied.</returns>
public bool Check(BasePlayer player)
{
Player p = (Player)player;
return p.Adminlevel >= 1;
}
#endregion
}
}
58 changes: 58 additions & 0 deletions SampSharpGameMode1/AntiCheat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using SampSharp.GameMode.Definitions;
using SampSharp.GameMode.SAMP;
using System;
using System.Collections.Generic;
using System.Text;

namespace SampSharpGameMode1
{
public class AntiCheat
{
public enum SuspiciousBehavior
{
UnauthorizedWeaponInEvent = 0
}

private Player player;
private Timer routineTimer;
public AntiCheat(Player _player)
{
this.player = _player;
routineTimer = new Timer(5000, true);
routineTimer.Tick += Routine;
}

private void Routine(object sender, EventArgs e)
{
if (this.player.IsDisposed)
{
this.routineTimer.IsRepeating = false;
this.routineTimer.IsRunning = false;
this.routineTimer.Dispose();
}
else
{
if (this.player.IsInEvent)
{
if (this.player.Weapon != Weapon.None && this.player.pEvent.Status == Events.EventStatus.Running)
{
// BasePlayer.Weapon returns only the weapon held by the player before he enter in a vehicle
// So the AntiCheat system will only detect the weapon if player leave the vehicle
// See: https://open.mp/fr/docs/scripting/functions/GetPlayerWeapon
OnSuspiciousBehavior(SuspiciousBehavior.UnauthorizedWeaponInEvent);
}
}
}
}

private void OnSuspiciousBehavior(SuspiciousBehavior behavior)
{
switch(behavior)
{
case SuspiciousBehavior.UnauthorizedWeaponInEvent:
this.player.Kick("[AntiCheat] You have been kicked for unauthorized used of weapon in event") ;
break;
}
}
}
}
11 changes: 11 additions & 0 deletions SampSharpGameMode1/App.template.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="gta_basefolder" value="gta_basefolder"/>
<add key="mysql_host" value="database_host"/>
<add key="mysql_port" value="database_port"/>
<add key="mysql_db" value="database_name"/>
<add key="mysql_user" value="database_user"/>
<add key="mysql_pass" value="database_password"/>
</appSettings>
</configuration>
196 changes: 196 additions & 0 deletions SampSharpGameMode1/CameraController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
using SampSharp.GameMode;
using SampSharp.GameMode.Events;
using SampSharp.GameMode.World;
using System;
using System.Collections.Generic;
using System.Text;

namespace SampSharpGameMode1
{
public class CameraController
{
public Player player;
private BaseVehicle playerVehicle; // Store the player's vehicle before set spectating
public bool Enabled { get; set; }
public bool LockTarget { get; set; }
public Vector3 LockedTarget { get; set; }
public float LockDistance { get; set; }
private Vector3 lastLookAtPos;
public CameraController(Player player)
{
this.player = player;
this.player.KeyStateChanged += OnPlayerKeyStateChanged;
this.Enabled = false;
this.LockTarget = false;
this.LockedTarget = Vector3.Zero;
this.LockDistance = 200.0f;
this.lastLookAtPos = Vector3.Zero;
}

public void Dispose()
{
if(this.player != null)
{
this.player.KeyStateChanged -= OnPlayerKeyStateChanged;
this.player = null;
}
}

public void SetFree()
{
if(this.Enabled)
{
if (player.InAnyVehicle)
playerVehicle = player.Vehicle;
player.ToggleSpectating(true);
System.Threading.Thread.Sleep(100);
player.CameraPosition = player.Position + new Vector3(0.0, 0.0, 5.0);
}
else
Logger.WriteLineAndClose($"CameraController.cs - CameraController.SetFree:I: CameraController is not enabled");
}

public void SetBehindPlayer()
{
if (this.Enabled)
{
player.ToggleSpectating(false);
player.PutCameraBehindPlayer();
if(playerVehicle != null)
player.PutInVehicle(playerVehicle);
}
else
Logger.WriteLineAndClose($"CameraController.cs - CameraController.SetBehindPlayer:I: CameraController is not enabled");
}

public void SetPosition(Vector3 position)
{
if (this.Enabled)
{
player.CameraPosition = position;
Logger.WriteLineAndClose($"CameraController.cs - CameraController.SetPosition:I: New position = " + position.ToString());
}
else
Logger.WriteLineAndClose($"CameraController.cs - CameraController.SetPosition:I: CameraController is not enabled");
}

public void MoveTo(Vector3 position)
{
if (this.Enabled)
{
player.InterpolateCameraPosition(player.CameraPosition, position, 100, SampSharp.GameMode.Definitions.CameraCut.Move);
Logger.WriteLineAndClose($"CameraController.cs - CameraController.MoveTo:I: Moving to = " + position.ToString());
}
else
Logger.WriteLineAndClose($"CameraController.cs - CameraController.MoveTo:I: CameraController is not enabled");
}

public void SetTarget(Vector3 target, bool locked = false)
{
if (this.Enabled)
{
player.SetCameraLookAt(target, SampSharp.GameMode.Definitions.CameraCut.Cut);
lastLookAtPos = target;
if (locked)
{
LockTarget = true;
LockedTarget = target;
}
Logger.WriteLineAndClose($"CameraController.cs - CameraController.SetTarget:I: Look at position = " + target.ToString());
}
else
Logger.WriteLineAndClose($"CameraController.cs - CameraController.SetTarget:I: CameraController is not enabled");
}

public void MoveToTarget(Vector3 target)
{
if (this.Enabled)
{
player.InterpolateCameraLookAt(lastLookAtPos, target, 100, SampSharp.GameMode.Definitions.CameraCut.Move);
lastLookAtPos = target;
}
else
Logger.WriteLineAndClose($"CameraController.cs - CameraController.MoveToTarget:I: CameraController is not enabled");
}

private double GetAngle(Vector3 target, double distance)
{
Vector3 cameraPos = player.CameraPosition;
double xDiff = Math.Abs(cameraPos.X - target.X);
double yDiff = Math.Abs(cameraPos.Y - target.Y);
Logger.WriteLineAndClose($"CameraController.cs - CameraController.GetSinCos:I: xDiff = " + xDiff.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.GetSinCos:I: yDiff = " + yDiff.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.GetSinCos:I: dist = " + distance.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.GetSinCos:I: Math.Acos(xDiff / dist) = " + Math.Acos(xDiff / distance));
return Math.Acos(xDiff / distance);
}

private void OnPlayerKeyStateChanged(object sender, KeyStateChangedEventArgs e)
{
if(player.CameraMode == SampSharp.GameMode.Definitions.CameraMode.Fixed && player.State == SampSharp.GameMode.Definitions.PlayerState.Spawned)
{
Vector3 cameraPos = player.CameraPosition;
double angle;
switch (e.NewKeys)
{
case SampSharp.GameMode.Definitions.Keys.AnalogLeft:
if(LockTarget)
{
angle = GetAngle(LockedTarget, LockDistance);
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: LockedTarget = " + LockedTarget.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: dist = " + LockDistance.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: cameraPos = " + cameraPos.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: LockedTarget = " + LockedTarget.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: previous angle = " + angle.ToString());
angle -= Math.PI/4;
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: next angle = " + angle.ToString());
double cos = Math.Cos(angle);
double sin = Math.Sin(angle);
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: cos = " + cos.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: sin = " + sin.ToString());
MoveTo(new Vector3(
(cos * LockDistance) + LockedTarget.X,
(sin * LockDistance) + LockedTarget.Y,
cameraPos.Z
));
MoveToTarget(LockedTarget);
}
else
MoveTo(cameraPos + new Vector3(10.0, 0.0, 0.0));
break;
case SampSharp.GameMode.Definitions.Keys.AnalogRight:
if (LockTarget)
{
angle = GetAngle(LockedTarget, LockDistance);
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: LockedTarget = " + LockedTarget.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: dist = " + LockDistance.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: cameraPos = " + cameraPos.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: LockedTarget = " + LockedTarget.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: previous angle = " + angle.ToString());
angle += Math.PI / 4;
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: next angle = " + angle.ToString());
double cos = Math.Cos(angle);
double sin = Math.Sin(angle);
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: cos = " + cos.ToString());
Logger.WriteLineAndClose($"CameraController.cs - CameraController.OnPlayerKeyStateChanged:I: sin = " + sin.ToString());
MoveTo(new Vector3(
(cos * LockDistance) + LockedTarget.X,
(sin * LockDistance) + LockedTarget.Y,
cameraPos.Z
));
MoveToTarget(LockedTarget);
}
else
MoveTo(player.CameraPosition + new Vector3(-10.0, 0.0, 0.0));
break;
case SampSharp.GameMode.Definitions.Keys.AnalogUp:
MoveTo(player.CameraPosition + new Vector3(0.0, 10.0, 0.0));
break;
case SampSharp.GameMode.Definitions.Keys.AnalogDown:
MoveTo(player.CameraPosition + new Vector3(0.0, -10.0, 0.0));
break;
}
}
}
}
}
Loading

0 comments on commit 4972ab4

Please sign in to comment.