Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: B3none/cs2-retakes
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.2.8
Choose a base ref
...
head repository: B3none/cs2-retakes
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.3.0
Choose a head ref

Commits on Jan 8, 2024

  1. Copy the full SHA
    0db6bd8 View commit details
  2. latest

    B3none committed Jan 8, 2024
    Copy the full SHA
    0609c3e View commit details

Commits on Jan 9, 2024

  1. latest

    B3none committed Jan 9, 2024
    Copy the full SHA
    f4c52ec View commit details
  2. still nothing :/

    B3none committed Jan 9, 2024
    Copy the full SHA
    7069cb1 View commit details
  3. continued updates

    B3none committed Jan 9, 2024
    Copy the full SHA
    2819103 View commit details
  4. latest

    B3none committed Jan 9, 2024
    Copy the full SHA
    73600ec View commit details
  5. meh

    B3none committed Jan 9, 2024
    Copy the full SHA
    8cc28a5 View commit details
  6. latest

    B3none committed Jan 9, 2024
    Copy the full SHA
    b7316a9 View commit details
  7. Copy the full SHA
    10765ac View commit details
  8. almost working workaround

    B3none committed Jan 9, 2024
    Copy the full SHA
    39189fd View commit details
  9. latest checks

    B3none committed Jan 9, 2024
    Copy the full SHA
    1b96df8 View commit details
  10. switch player to weapon after

    B3none committed Jan 9, 2024
    Copy the full SHA
    b312a98 View commit details

Commits on Jan 13, 2024

  1. Merge branch 'master' into zwolof-autoplant-v2

    # Conflicts:
    #	Modules/Helpers.cs
    #	RetakesPlugin.cs
    B3none committed Jan 13, 2024
    Copy the full SHA
    8e629ae View commit details
  2. Fix GetGameRules

    B3none committed Jan 13, 2024
    Copy the full SHA
    ff0cbed View commit details
  3. Added initial BombFunctions

    B3none committed Jan 13, 2024
    Copy the full SHA
    7621eca View commit details
  4. Copy the full SHA
    c05ae77 View commit details
  5. Comment ontick listener

    B3none committed Jan 13, 2024
    Copy the full SHA
    2116cc6 View commit details
  6. Updated BombFunctions

    B3none committed Jan 13, 2024
    Copy the full SHA
    f03c578 View commit details
  7. Working solution :o

    B3none committed Jan 13, 2024
    Copy the full SHA
    1a729c7 View commit details

Commits on Jan 14, 2024

  1. Removed redundant debugging code / failed solutions and updated how w…

    …e handle the autoplant
    B3none committed Jan 14, 2024
    Copy the full SHA
    f4cc825 View commit details
  2. Fixed auto planting

    B3none committed Jan 14, 2024
    Copy the full SHA
    e68760f View commit details
  3. Remove redundant using lines

    B3none committed Jan 14, 2024
    Copy the full SHA
    10cee34 View commit details
  4. Copy the full SHA
    c480a8a View commit details
  5. Updated linux sig

    B3none committed Jan 14, 2024
    Copy the full SHA
    dd49294 View commit details
  6. Copy the full SHA
    d5cb9af View commit details
  7. Removed failed to plant translations, also removed state to check whe…

    …ther the bomb was planted
    B3none committed Jan 14, 2024
    Copy the full SHA
    d64e7cc View commit details
  8. Added bandaid solution for linux because we can't find the sig :(

    B3none committed Jan 14, 2024
    Copy the full SHA
    f87acf3 View commit details
  9. latest test

    B3none committed Jan 14, 2024
    Copy the full SHA
    02282bc View commit details
  10. Works for linux now

    B3none committed Jan 14, 2024
    Copy the full SHA
    ab2d5eb View commit details
  11. Latest version

    B3none committed Jan 14, 2024
    Copy the full SHA
    0a92f35 View commit details
  12. Renamed BombVirtualFunction to SpawnBomb

    B3none committed Jan 14, 2024
    Copy the full SHA
    5ecf9ec View commit details
  13. Fixed linux implementation

    B3none committed Jan 14, 2024
    Copy the full SHA
    3420f5d View commit details
  14. Switched for a completely cssharp solution (no signatures required)

    B3none committed Jan 14, 2024
    Copy the full SHA
    d81faf6 View commit details
  15. Merge pull request #16 from B3none/zwolof-autoplant-v2

    Added autoplant functionality
    B3none authored Jan 14, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a787674 View commit details
Showing with 152 additions and 119 deletions.
  1. +112 −8 Modules/Helpers.cs
  2. +1 −6 Modules/Managers/GameManager.cs
  3. +27 −69 RetakesPlugin.cs
  4. +1 −3 lang/da.json
  5. +1 −3 lang/de.json
  6. +1 −3 lang/en.json
  7. +1 −3 lang/es.json
  8. +1 −3 lang/fr.json
  9. +1 −3 lang/hu.json
  10. +1 −3 lang/no.json
  11. +1 −3 lang/pl.json
  12. +1 −3 lang/pt.json
  13. +1 −3 lang/ru.json
  14. +1 −3 lang/sv.json
  15. +1 −3 lang/tr.json
120 changes: 112 additions & 8 deletions Modules/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
using RetakesPlugin.Modules.Enums;

namespace RetakesPlugin.Modules;

@@ -215,15 +216,118 @@ public static void CheckRoundDone()

if (tHumanCount == 0 || ctHumanCount == 0)
{
// TODO: once this stops crashing on windows use it there too
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
GetGameRules().TerminateRound(0.1f, RoundEndReason.TerroristsWin);
}
else
TerminateRound(RoundEndReason.TerroristsWin);
}
}

public static void TerminateRound(RoundEndReason roundEndReason)
{
// TODO: once this stops crashing on windows use it there too
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
GetGameRules().TerminateRound(0.1f, roundEndReason);
}
else
{
Console.WriteLine($"{RetakesPlugin.LogPrefix}Windows server detected (Can't use TerminateRound) trying to kill all alive players instead.");
var alivePlayers = Utilities.GetPlayers()
.Where(IsValidPlayer)
.Where(player => player.PawnIsAlive)
.ToList();

foreach (var player in alivePlayers)
{
Console.WriteLine($"{RetakesPlugin.LogPrefix}Windows server detected (Can't use TerminateRound)");
player.CommitSuicide(false, true);
}
}
}

public static CPlantedC4? GetPlantedC4()
{
return Utilities.FindAllEntitiesByDesignerName<CPlantedC4>("planted_c4").FirstOrDefault();
}

public static bool IsInRange(float range, Vector v1, Vector v2)
{
var dx = v1.X - v2.X;
var dy = v1.Y - v2.Y;

return Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)) <= range;
}

public static bool IsOnGround(CCSPlayerController player)
{
return (player.PlayerPawn.Value!.Flags & (int)PlayerFlags.FL_ONGROUND) != 0;
}

public static void PlantTickingBomb(CCSPlayerController? player, Bombsite bombsite)
{
if (player == null || !player.IsValid)
{
throw new Exception("Player controller is not valid");
}

var playerPawn = player.PlayerPawn.Value;

if (playerPawn == null || !playerPawn.IsValid)
{
throw new Exception("Player pawn is not valid");
}

if (playerPawn.AbsOrigin == null)
{
throw new Exception("Player pawn abs origin is null");
}

if (playerPawn.AbsRotation == null)
{
throw new Exception("Player pawn abs rotation is null");
}

var plantedC4 = Utilities.CreateEntityByName<CPlantedC4>("planted_c4");

if (plantedC4 == null)
{
throw new Exception("c4 is null");
}

if (plantedC4.AbsOrigin == null)
{
throw new Exception("c4.AbsOrigin is null");
}

plantedC4.AbsOrigin.X = playerPawn.AbsOrigin.X;
plantedC4.AbsOrigin.Y = playerPawn.AbsOrigin.Y;
plantedC4.AbsOrigin.Z = playerPawn.AbsOrigin.Z;
plantedC4.HasExploded = false;

plantedC4.OwnerEntity.Raw = playerPawn.EntityHandle.Raw;

plantedC4.BombSite = 0;
plantedC4.BombTicking = true;
plantedC4.CannotBeDefused = false;

plantedC4.DispatchSpawn();

var gameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules!;
gameRules.BombPlanted = true;
gameRules.BombDefused = false;

SendBombPlantedEvent(player, bombsite);
}

public static void SendBombPlantedEvent(CCSPlayerController bombCarrier, Bombsite bombsite)
{
if (!bombCarrier.IsValid || bombCarrier.PlayerPawn.Value == null)
{
return;
}

var eventPtr = NativeAPI.CreateEvent("bomb_planted", true);
NativeAPI.SetEventPlayerController(eventPtr, "userid", bombCarrier.Handle);
NativeAPI.SetEventInt(eventPtr, "userid", (int)bombCarrier.PlayerPawn.Value.Index);
NativeAPI.SetEventInt(eventPtr, "site", (int)bombsite);

NativeAPI.FireEvent(eventPtr, false);
}
}
7 changes: 1 addition & 6 deletions Modules/Managers/GameManager.cs
Original file line number Diff line number Diff line change
@@ -81,13 +81,8 @@ public void TerroristRoundWin()
}
}

public void CounterTerroristRoundWin(CCSPlayerController? planter, bool wasBombPlanted)
public void CounterTerroristRoundWin()
{
if (planter != null && !wasBombPlanted)
{
Server.PrintToChatAll($"{RetakesPlugin.MessagePrefix}{_translator["bombsite.failed_to_plant", planter.PlayerName]}");
}

if (_consecutiveRoundsWon >= 3)
{
Server.PrintToChatAll($"{RetakesPlugin.MessagePrefix}{_translator["teams.win_streak_over", _consecutiveRoundsWon]}");
96 changes: 27 additions & 69 deletions RetakesPlugin.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
using RetakesPlugin.Modules;
using RetakesPlugin.Modules.Enums;
@@ -18,7 +19,7 @@ namespace RetakesPlugin;
[MinimumApiVersion(131)]
public class RetakesPlugin : BasePlugin
{
private const string Version = "1.2.8";
private const string Version = "1.3.0";

#region Plugin info
public override string ModuleName => "Retakes Plugin";
@@ -45,7 +46,6 @@ public class RetakesPlugin : BasePlugin
#region State
private Bombsite _currentBombsite = Bombsite.A;
private CCSPlayerController? _planter;
private bool _isBombPlanted;
private CsTeam _lastRoundWinner;
#endregion

@@ -56,7 +56,6 @@ public RetakesPlugin()

public override void Load(bool hotReload)
{
// Reset this on load
_translator = new Translator(Localizer);

Console.WriteLine($"{LogPrefix}Plugin loaded!");
@@ -354,7 +353,7 @@ public HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
{
case CsTeam.CounterTerrorist:
Console.WriteLine($"{LogPrefix}Calling CounterTerroristRoundWin()");
_gameManager.CounterTerroristRoundWin(_planter, _isBombPlanted);
_gameManager.CounterTerroristRoundWin();
Console.WriteLine($"{LogPrefix}CounterTerroristRoundWin call complete");
break;

@@ -467,7 +466,7 @@ public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
playerPawn.Teleport(spawn.Vector, spawn.QAngle, new Vector());
}
Console.WriteLine($"{LogPrefix}Moving players to spawns COMPLETE.");

AnnounceBombsite(_currentBombsite);

return HookResult.Continue;
@@ -523,27 +522,19 @@ public HookResult OnRoundPostStart(EventRoundPoststart @event, GameEventInfo inf
{
Console.WriteLine($"{LogPrefix}Fallback allocation disabled, skipping.");
}

Console.WriteLine($"{LogPrefix}[{player.PlayerName}] Handling bomb allocation:");
if ((CsTeam)player.TeamNum == CsTeam.Terrorist)
{
Console.WriteLine($"{LogPrefix}[{player.PlayerName}] is terrorist");
Console.WriteLine($"{LogPrefix}[{player.PlayerName}] Removing bomb");
// Remove the bomb from the player.
player.RemoveItemByDesignerName("weapon_c4", true);

if (player == _planter)
{
Console.WriteLine($"{LogPrefix}[{player.PlayerName}] Player IS planter, giving bomb (player.givenameditem)");
Helpers.GiveAndSwitchToBomb(player);
}
}
});
}

return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnRoundFreezeEnd(EventRoundFreezeEnd @event, GameEventInfo info)
{
HandleAutoPlant();
return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
@@ -589,58 +580,10 @@ public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnWeaponFire(EventWeaponFire @event, GameEventInfo info)
{
var player = @event.Userid;

if (!Helpers.IsValidPlayer(player))
{
return HookResult.Continue;
}

if (Helpers.HasBomb(player))
{
Console.WriteLine($"{LogPrefix}Player has bomb, swap to bomb userid({(int)player.UserId!}).");

// TODO: Investigate this because sometimes it doesn't work.
// Change to their knife to prevent planting.
NativeAPI.IssueClientCommand((int)player.UserId!, "slot5");
}

return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnBombDropped(EventBombDropped @event, GameEventInfo info)
{
var player = @event.Userid;

if (!Helpers.IsValidPlayer(player))
{
return HookResult.Continue;
}

// Remove the bomb entity and give the player that dropped it the bomb
var bombEntities = Utilities.FindAllEntitiesByDesignerName<CBaseEntity>("weapon_c4").ToList();

if (bombEntities.Count > 0)
{
foreach (var bomb in bombEntities)
{
bomb.Remove();
}
}

Helpers.GiveAndSwitchToBomb(player);

return HookResult.Continue;
}

[GameEventHandler(HookMode.Pre)]
public HookResult OnBombPlanted(EventBombPlanted @event, GameEventInfo info)
{
_isBombPlanted = true;
Console.WriteLine($"{LogPrefix}OnBombPlanted event fired");

AddTimer(4.1f, () => AnnounceBombsite(_currentBombsite, true));

@@ -819,4 +762,19 @@ private void AnnounceBombsite(Bombsite bombsite, bool onlyCenter = false)
}
}
}

private void HandleAutoPlant()
{
// Ensure the round time for defuse is always set to 1.92
Server.ExecuteCommand("mp_roundtime_defuse 1.92");

if (_planter != null && Helpers.IsValidPlayer(_planter))
{
Helpers.PlantTickingBomb(_planter, _currentBombsite);
}
else
{
Helpers.TerminateRound(RoundEndReason.RoundDraw);
}
}
}
4 changes: 1 addition & 3 deletions lang/da.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Terroristerne har vundet [GREEN]{0}[NORMAL] runder i træk - hvis de vinder [GREEN]{1} mere, [PURPLE]bliver holdende blandet.",
"teams.win_streak": "Terroristerne har vundet [GREEN]{0}[NORMAL] runder i træk!",
"teams.win_streak_over": "CT'erne har afsluttet en [GREEN]{0}[NORMAL]-runde lang win streak!",
"teams.admin_scramble": "{0} har sat holdende til at blive blandet.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] glemte at plante..."
"teams.admin_scramble": "{0} har sat holdende til at blive blandet."
}
4 changes: 1 addition & 3 deletions lang/de.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Die Terroristen haben [GREEN]{0}[NORMAL] Runden in Folge gewonnen - wenn sie noch [GREEN]{1} gewinnen, [PURPLE]werden die Teams gemischt.",
"teams.win_streak": "Die Terroristen haben [GREEN]{0}[NORMAL] Runden in Folge gewonnen!",
"teams.win_streak_over": "Die CTs haben die Sieges-Serie von [GREEN]{0}[NORMAL] Runden beendet!",
"teams.admin_scramble": "{0} lässt die Teams in der nächsten Runde mischen.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] schaffte es nicht, die Bombe zu legen..."
"teams.admin_scramble": "{0} lässt die Teams in der nächsten Runde mischen."
}
4 changes: 1 addition & 3 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "The terrorists have won [GREEN]{0}[NORMAL] rounds in a row - if they win [GREEN]{1} more, [PURPLE]teams will be scrambled.",
"teams.win_streak": "The terrorists have won [GREEN]{0}[NORMAL] rounds in a row!",
"teams.win_streak_over": "The CTs have ended a [GREEN]{0}[NORMAL]-round long win streak!",
"teams.admin_scramble": "{0} has set the teams to be scrambled next round.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] failed to plant..."
"teams.admin_scramble": "{0} has set the teams to be scrambled next round."
}
4 changes: 1 addition & 3 deletions lang/es.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Los terroristas van ganando [GREEN]{0}[NORMAL] rondas seguidas - Si ganan [GREEN]{1} más, [PURPLE]los equipos serán a mezclados.",
"teams.win_streak": "Los terroristas ganaron [GREEN]{0}[NORMAL] rondas seguidas!",
"teams.win_streak_over": "Los CTs habían perdido [GREEN]{0}[NORMAL] rondas, pero al fin ganaron 1.",
"teams.admin_scramble": "{0} Los equipos serán a mezclados en la siguiente ronda.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] Fallaron al plantar..."
"teams.admin_scramble": "{0} Los equipos serán a mezclados en la siguiente ronda."
}
4 changes: 1 addition & 3 deletions lang/fr.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Les terroristes ont gagné [GREEN]{0}[NORMAL] tours d'affilée - s'ils en gagnent encore [GREEN]{1}, [PURPLE]les équipes seront mélangées.",
"teams.win_streak": "Les terroristes ont gagné [GREEN]{0}[NORMAL] tours d'affilée !",
"teams.win_streak_over": "Les CTs ont mis fin à [GREEN]{0}[NORMAL] tours gagnés d'affilée !",
"teams.admin_scramble": "{0} a imposé le mélange des équipes au prochain tour.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] n'a pas réussi à poser la bombe…"
"teams.admin_scramble": "{0} a imposé le mélange des équipes au prochain tour."
}
4 changes: 1 addition & 3 deletions lang/hu.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Terroristák [GREEN]{0}[NORMAL] kört nyertek egymás után - ha még nyernek [GREEN]{1} kört, [PURPLE]a csapatok össze lesznek keverve.",
"teams.win_streak": "Terroristák [GREEN]{0}[NORMAL] kört nyertek egymás után!",
"teams.win_streak_over": "TE-k megállították a [GREEN]{0}[NORMAL] kör hosszú győzelem sorozatot!",
"teams.admin_scramble": "{0} beállította, hogy a csapatok össze legyenek keverve a következő körben.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] nem rakta le a bombát..."
"teams.admin_scramble": "{0} beállította, hogy a csapatok össze legyenek keverve a következő körben."
}
4 changes: 1 addition & 3 deletions lang/no.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Terroristene har vunnet [GREEN]{0}[NORMAL] runder på rad - hvis de vinner [GREEN]{1} mer, [PURPLE]vil lagene bli endret.",
"teams.win_streak": "Terroristene har vunnet [GREEN]{0}[NORMAL] runder på rad!",
"teams.win_streak_over": "CT har sluttet en [GREEN]{0}[NORMAL]-runders lang seiersrekke!",
"teams.admin_scramble": "{0} har satt lagene til å bli samlet neste runde.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] klarte ikke å plante bomben..."
"teams.admin_scramble": "{0} har satt lagene til å bli samlet neste runde."
}
4 changes: 1 addition & 3 deletions lang/pl.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Terroryści wygrali [GREEN]{0}[NORMAL] rund pod rząd - jeśli wygrają [GREEN]{1} raz(y), [PURPLE]drużyny zostaną wymieszane.",
"teams.win_streak": "Terroryści wygrali [GREEN]{0}[NORMAL] rund pod rząd!",
"teams.win_streak_over": "CT zakończyli [GREEN]{0}[NORMAL] zwycięską serie rund!",
"teams.admin_scramble": "{0} ustawił wymieszanie drużyn na następną rundę.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] nie udało się podłożyć bomby..."
"teams.admin_scramble": "{0} ustawił wymieszanie drużyn na następną rundę."
}
4 changes: 1 addition & 3 deletions lang/pt.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"teams.almost_scramble": "Terroristas venceram [GREEN]{0}[NORMAL] rondas consecutivas - se ganharem mais [GREEN]{1} ronda, [PURPLE]as equipas serão embaralhadas.",
"teams.win_streak": "Terroristas venceram [GREEN]{0}[NORMAL] rondas consecutivas!",
"teams.win_streak_over": "Contra-Terroristas terminaram uma sequência de rondas consecutivas [GREEN]{0}[NORMAL]!",
"teams.admin_scramble": "{0} definiu para as equipas serem embaralhadas na próxima ronda.",

"bombsite.failed_to_plant": "[PURPLE]{0}[NORMAL] falhou ao plantar C4..."
"teams.admin_scramble": "{0} definiu para as equipas serem embaralhadas na próxima ronda."
}
Loading