Skip to content

Commit

Permalink
start work on exposing warden api
Browse files Browse the repository at this point in the history
  • Loading branch information
destoer committed Mar 9, 2024
1 parent 46b2328 commit 8761558
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 24 deletions.
22 changes: 22 additions & 0 deletions Cs2Jailbreak.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cs2Jailbreak", "src\Cs2Jailbreak.csproj", "{725B192E-0E77-435E-AA7A-E5F6FD1E3082}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{725B192E-0E77-435E-AA7A-E5F6FD1E3082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{725B192E-0E77-435E-AA7A-E5F6FD1E3082}.Debug|Any CPU.Build.0 = Debug|Any CPU
{725B192E-0E77-435E-AA7A-E5F6FD1E3082}.Release|Any CPU.ActiveCfg = Release|Any CPU
{725B192E-0E77-435E-AA7A-E5F6FD1E3082}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions WardenService/WardenService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities;

public interface IWardenService
{
public bool IsWarden(CCSPlayerController? player);
public CCSPlayerController? GetWarden();
public void SetWarden(CCSPlayerController player);
}
13 changes: 13 additions & 0 deletions WardenService/WardenService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.193" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
yes | cp bin/Debug/net7.0/* "../../plugins/Cs2Jailbreak/"
yes | cp src/bin/Debug/net7.0/* "../../plugins/Cs2Jailbreak/"
yes | cp WardenService/bin/Debug/net7.0/* "../../shared/WardenService/"
cp -r lang "../../plugins/Cs2Jailbreak/"
18 changes: 18 additions & 0 deletions src/Cs2Jailbreak.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>

<PackageReference Include="CounterStrikeSharp.API" Version="1.0.193" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.1" />
<PackageReference Include="MySqlConnector" Version="2.3.1" />

<ProjectReference Include="../WardenService/WardenService.csproj" />
</ItemGroup>

</Project>
31 changes: 28 additions & 3 deletions src/Jail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using CSTimer = CounterStrikeSharp.API.Modules.Timers;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using System.Text.Json.Serialization;
using CounterStrikeSharp.API.Core.Capabilities;

public class JailConfig : BasePluginConfig
{
Expand Down Expand Up @@ -136,9 +137,30 @@ public class JailConfig : BasePluginConfig
public int wsdRound { get; set; } = 50;
}

public class WardenService : IWardenService
{
public bool IsWarden(CCSPlayerController? player)
{
return JailPlugin.IsWarden(player);
}

public void SetWarden(CCSPlayerController player)
{
if(player.IsLegalAlive() && player.IsCt())
{
JailPlugin.warden.SetWarden(player.Slot);
}
}

public CCSPlayerController? GetWarden()
{
return JailPlugin.warden.GetWarden();
}
}

// main plugin file, controls central hooking
// defers to warden, lr and sd
[MinimumApiVersion(163)]
[MinimumApiVersion(193)]
public class JailPlugin : BasePlugin, IPluginConfig<JailConfig>
{
// Global event settings, used to filter plugin activits
Expand All @@ -147,6 +169,8 @@ public class JailPlugin : BasePlugin, IPluginConfig<JailConfig>

public JailConfig Config { get; set; } = new JailConfig();

public static PluginCapability<IWardenService> wardenService {get; } = new ("jailbreak:warden_service");

public static bool IsWarden(CCSPlayerController? player)
{
return warden.IsWarden(player);
Expand Down Expand Up @@ -184,13 +208,15 @@ public static void PurgePlayerStats(CCSPlayerController? player)

public override string ModuleName => "CS2 Jailbreak - destoer";

public override string ModuleVersion => "v0.3.9";
public override string ModuleVersion => "v0.4.1";

public override void Load(bool hotReload)
{
globalCtx = this;
logs = new Logs(this);

Capabilities.RegisterPluginCapability(wardenService,() => new WardenService());

RegisterCommands();

RegisterHooks();
Expand All @@ -204,7 +230,6 @@ public override void Load(bool hotReload)
Console.WriteLine("Sucessfully started JB");

AddTimer(Warden.LASER_TIME,warden.LaserTick,CSTimer.TimerFlags.REPEAT);

}

void LocalizePrefix()
Expand Down
2 changes: 1 addition & 1 deletion src/SpecialDay/SDBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void ResurectPlayer(CCSPlayerController player,float delay)

},CSTimer.TimerFlags.STOP_ON_MAPCHANGE);

JailPlugin.globalCtx.AddTimer(delay + 0.2f,() =>
JailPlugin.globalCtx.AddTimer(delay + 0.5f,() =>
{
CCSPlayerController? target = Utilities.GetPlayerFromSlot(victimSlot);

Expand Down
42 changes: 24 additions & 18 deletions src/SpecialDay/Zombie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void Setup()
{
for(int i = 0; i < 64; i++)
{
firstDeath[i] = false;
deathCount[i] = 0;
}

LocalizeAnnounce("sd.zombie_start");
Expand Down Expand Up @@ -98,14 +98,18 @@ public override void Death(CCSPlayerController? player, CCSPlayerController? att
// save death cordinates
if(pawn != null && pawn.AbsOrigin != null)
{
deathCord[player.Slot] = pawn.AbsOrigin;
firstDeath[player.Slot] = true;
// make sure this is by copy
deathCord[player.Slot].X = pawn.AbsOrigin.X;
deathCord[player.Slot].Y = pawn.AbsOrigin.Y;
deathCord[player.Slot].Z = pawn.AbsOrigin.Z;
deathCount[player.Slot] += 1;
}

// couldn't get the cords just put them at patient zero
else
{
firstDeath[player.Slot] = false;

deathCount[player.Slot] = 2;
}

// First death has a very fast respawn
Expand All @@ -131,19 +135,21 @@ public override void PlayerHurt(CCSPlayerController? player,CCSPlayerController?
return;
}

// only want zombie to ct damage
if(!player.IsT() || !attacker.IsCt())
if(attacker.Slot == bossSlot)
{
return;
// if attacker is patient zero kill them instantly
player.Slay();
}


if(attacker.Slot == bossSlot)
// only want zombie to ct damage knockback
/*
if(!player.IsT() || !attacker.IsCt())
{
// if attacker is patient zero kill them instantly
player.Slay();
return;
}
// add knockback to player, scaled from damage
var playerPawn = player.Pawn();
var attackerPawn = attacker.Pawn();
Expand All @@ -159,13 +165,14 @@ public override void PlayerHurt(CCSPlayerController? player,CCSPlayerController?
// scale it (may need balancing)
Vector push = Vec.Scale(pos, scale);
/*
Server.PrintToChatAll($"damage {damage}");
Server.PrintToChatAll($"pos {pos.X} {pos.Y} {pos.Z}");
Server.PrintToChatAll($"push {push.X} {push.Y} {push.Z}");
*/
//Server.PrintToChatAll($"damage {damage}");
//Server.PrintToChatAll($"pos {pos.X} {pos.Y} {pos.Z}");
//Server.PrintToChatAll($"push {push.X} {push.Y} {push.Z}");
playerPawn.AbsVelocity.Add(push);
}
*/
}

public override void End()
Expand Down Expand Up @@ -211,9 +218,8 @@ public override void SetupPlayer(CCSPlayerController player)
}

// respawn them on their death cordinates
if(firstDeath[player.Slot])
if(deathCount[player.Slot] == 1)
{
firstDeath[player.Slot] = false;
player.Teleport(deathCord[player.Slot],Lib.ANGLE_ZERO,Lib.VEC_ZERO);
}

Expand All @@ -235,6 +241,6 @@ public override void SetupPlayer(CCSPlayerController player)
}
}

bool[] firstDeath = new bool[64];
int[] deathCount = new int[64];
Vector[] deathCord = new Vector[64];
}
2 changes: 1 addition & 1 deletion src/Warden/Laser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Ping(CCSPlayerController? player, float x, float y, float z)
// because this generates alot of ents
RemoveMarker();

//Server.PrintToChatAll($"{Lib.enTCount()}");
//Server.PrintToChatAll($"{Lib.EntCount()}");

marker.colour = jailPlayer.markerColour;
marker.Draw(60.0f,75.0f,x,y,z);
Expand Down
10 changes: 10 additions & 0 deletions src/Warden/Warden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ public void SetupPlayerGuns(CCSPlayerController? player)
return jailPlayers[player.Slot];
}

public CCSPlayerController? GetWarden()
{
if(wardenSlot == INAVLID_SLOT)
{
return null;
}

return Utilities.GetPlayerFromSlot(wardenSlot);
}

Countdown<int> chatCountdown = new Countdown<int>();

const int INAVLID_SLOT = -3;
Expand Down

0 comments on commit 8761558

Please sign in to comment.