Skip to content

Commit

Permalink
Merge pull request #86 from B3none/retakes-events
Browse files Browse the repository at this point in the history
Retakes events
  • Loading branch information
B3none authored Mar 6, 2024
2 parents 3256ea1 + 35f2022 commit fbc8056
Show file tree
Hide file tree
Showing 53 changed files with 95 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build the plugin
name: Build RetakesPlugin

on:
push:
Expand All @@ -25,15 +25,17 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Build
run: dotnet build
- name: Change directory and build
run: |
cd RetakesPlugin
dotnet build
- name: Create output directory
run: |
mkdir -p output/RetakesPlugin
mv ./bin/Debug/net7.0/RetakesPlugin.dll output/RetakesPlugin/
mv ./bin/Debug/net7.0/RetakesPlugin.pdb output/RetakesPlugin/
mv ./map_config output/RetakesPlugin/
mv ./lang output/RetakesPlugin/
mv ./RetakesPlugin/bin/Debug/net7.0/RetakesPlugin.dll output/RetakesPlugin/
mv ./RetakesPlugin/bin/Debug/net7.0/RetakesPlugin.pdb output/RetakesPlugin/
mv ./RetakesPlugin/map_config output/RetakesPlugin/
mv ./RetakesPlugin/lang output/RetakesPlugin/
- name: Copy output (no map configs)
run: |
cp -r output/ output-no-map-configs/
Expand Down
12 changes: 0 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# Rider IDE
/.idea
*.DotSettings.user

# Ignore obj directories in the root of each project
**/obj/

# Ignore NuGet cache in obj directories
**/obj/**/*.nuget.cache

# Ignore bin directories in the root of each project
**/bin/

# Ignore the SLN
cs2-retakes.sln
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ If you appreciate the project then please take the time to star the repository

## Installation
- Download the zip file from the [latest release](https://github.com/B3none/cs2-retakes/releases), and extract the contents into your `counterstrikesharp/plugins` directory.
- Download the [shared plugin zip file](https://github.com/B3none/cs2-retakes/files/14504528/cs2-retakes-plugin-shared-1.0.0.zip) and put it into your `counterstrikesharp/shared` directory.

## Recommendations
I also recommend installing these plugins for an improved player experience
Expand Down
3 changes: 3 additions & 0 deletions RetakesPlugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/obj/
**/obj/**/*.nuget.cache
**/bin/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private static void AllocateWeapons(CCSPlayerController player)
if (player.Team == CsTeam.Terrorist)
{
player.GiveNamedItem(CsItem.AK47);
// player.GiveNamedItem(CsItem.Glock);
player.GiveNamedItem(CsItem.Deagle);
}

Expand All @@ -51,7 +50,6 @@ private static void AllocateWeapons(CCSPlayerController player)
player.GiveNamedItem(CsItem.M4A1S);
}

// player.GiveNamedItem(CsItem.USPS);
player.GiveNamedItem(CsItem.Deagle);
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions RetakesPlugin/Modules/RetakesPluginEventSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using RetakesPluginShared;
using RetakesPluginShared.Events;

namespace RetakesPlugin.Modules;

public class RetakesPluginEventSender: IRetakesPluginEventSender
{
public event EventHandler<IRetakesPluginEvent>? RetakesPluginEventHandlers;

public void TriggerEvent(IRetakesPluginEvent @event)
{
RetakesPluginEventHandlers?.Invoke(this, @event);
}
}
File renamed without changes.
58 changes: 29 additions & 29 deletions RetakesPlugin.cs → RetakesPlugin/RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities.Constants;
Expand All @@ -10,14 +11,16 @@
using RetakesPlugin.Modules.Enums;
using RetakesPlugin.Modules.Configs;
using RetakesPlugin.Modules.Managers;
using RetakesPluginShared;
using RetakesPluginShared.Events;
using Helpers = RetakesPlugin.Modules.Helpers;

namespace RetakesPlugin;

[MinimumApiVersion(154)]
[MinimumApiVersion(180)]
public class RetakesPlugin : BasePlugin
{
private const string Version = "1.3.30";
private const string Version = "1.4.0";

#region Plugin info
public override string ModuleName => "Retakes Plugin";
Expand All @@ -39,6 +42,8 @@ public class RetakesPlugin : BasePlugin
private GameManager? _gameManager;
private SpawnManager? _spawnManager;
private BreakerManager? _breakerManager;

public static PluginCapability<IRetakesPluginEventSender> RetakesPluginEventSenderCapability { get; } = new("retakes_plugin:event_sender");
#endregion

#region Configs
Expand Down Expand Up @@ -80,6 +85,9 @@ public override void Load(bool hotReload)
RegisterListener<Listeners.OnMapStart>(OnMapStart);

AddCommandListener("jointeam", OnCommandJoinTeam);

var retakesPluginEventSender = new RetakesPluginEventSender();
Capabilities.RegisterPluginCapability(RetakesPluginEventSenderCapability, () => retakesPluginEventSender);

if (hotReload)
{
Expand Down Expand Up @@ -636,7 +644,7 @@ public HookResult OnRoundPostStart(EventRoundPoststart @event, GameEventInfo inf
Helpers.WriteLine($"{LogPrefix}Trying to loop valid active players.");
foreach (var player in _gameManager.QueueManager.ActivePlayers.Where(Helpers.IsValidPlayer))
{
Helpers.WriteLine($"{LogPrefix}[{player.PlayerName}] Adding timer for allocation...");
Helpers.WriteLine($"{LogPrefix}[{player.PlayerName}] Handling allocation...");

if (!Helpers.IsValidPlayer(player))
{
Expand All @@ -646,35 +654,27 @@ public HookResult OnRoundPostStart(EventRoundPoststart @event, GameEventInfo inf
// Strip the player of all of their weapons and the bomb before any spawn / allocation occurs.
Helpers.RemoveHelmetAndHeavyArmour(player);
player.RemoveWeapons();

// Create a timer to do this as it would occasionally fire too early.
AddTimer(0.05f, () =>
if (player == _planter && RetakesConfig.IsLoaded(_retakesConfig) &&
!_retakesConfig!.RetakesConfigData!.IsAutoPlantEnabled)
{
if (!Helpers.IsValidPlayer(player))
{
Helpers.WriteLine($"{LogPrefix}Allocating weapons: Player is not valid.");
return;
}

if (player == _planter && RetakesConfig.IsLoaded(_retakesConfig) &&
!_retakesConfig!.RetakesConfigData!.IsAutoPlantEnabled)
{
Helpers.WriteLine($"{LogPrefix}Player is planter and auto plant is disabled, allocating bomb.");
Helpers.GiveAndSwitchToBomb(player);
}
Helpers.WriteLine($"{LogPrefix}Player is planter and auto plant is disabled, allocating bomb.");
Helpers.GiveAndSwitchToBomb(player);
}

if (!RetakesConfig.IsLoaded(_retakesConfig) ||
_retakesConfig!.RetakesConfigData!.EnableFallbackAllocation)
{
Helpers.WriteLine($"{LogPrefix}Allocating...");
AllocationManager.Allocate(player);
}
else
{
Helpers.WriteLine($"{LogPrefix}Fallback allocation disabled, skipping.");
}
});
if (!RetakesConfig.IsLoaded(_retakesConfig) ||
_retakesConfig!.RetakesConfigData!.EnableFallbackAllocation)
{
Helpers.WriteLine($"{LogPrefix}Allocating...");
AllocationManager.Allocate(player);
}
else
{
Helpers.WriteLine($"{LogPrefix}Fallback allocation disabled, skipping.");
}
}

RetakesPluginEventSenderCapability.Get()?.TriggerEvent(new AllocateEvent());

return HookResult.Continue;
}
Expand Down
5 changes: 3 additions & 2 deletions RetakesPlugin.csproj → RetakesPlugin/RetakesPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.178" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.188" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.2" />
<ProjectReference Include="..\RetakesPluginShared\RetakesPluginShared.csproj" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(CopyPath)' != '' ">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions RetakesPluginShared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/obj/
**/obj/**/*.nuget.cache
**/bin/
3 changes: 3 additions & 0 deletions RetakesPluginShared/Events/AllocateEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace RetakesPluginShared.Events;

public record AllocateEvent() : IRetakesPluginEvent;
3 changes: 3 additions & 0 deletions RetakesPluginShared/Events/IRetakesPluginEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace RetakesPluginShared.Events;

public interface IRetakesPluginEvent { }
9 changes: 9 additions & 0 deletions RetakesPluginShared/IRetakesPluginEventSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using RetakesPluginShared.Events;

namespace RetakesPluginShared;

public interface IRetakesPluginEventSender
{
public event EventHandler<IRetakesPluginEvent> RetakesPluginEventHandlers;
public void TriggerEvent(IRetakesPluginEvent @event);
}
18 changes: 18 additions & 0 deletions RetakesPluginShared/RetakesPluginShared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>RetakesPluginShared</PackageId>
<Title>RetakesPluginShared</Title>
<Description>
This library is made to run alongside https://github.com/b3none/cs2-retakes
</Description>
<Authors>B3none</Authors>

<Version>1.0.0</Version>

<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>RetakesPluginShared</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
</Project>

0 comments on commit fbc8056

Please sign in to comment.