Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Add debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Jul 20, 2024
2 parents 9410c67 + 4202c79 commit ba5ab55
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 100 deletions.
7 changes: 7 additions & 0 deletions TTT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Player", "mod\TTT.Playe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Manager", "mod\TTT.Manager\TTT.Manager.csproj", "{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Debug", "mod\TTT.Debug\TTT.Debug.csproj", "{5617C94C-B2F9-429C-B4C1-DDD03380A108}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -84,6 +86,10 @@ Global
{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Release|Any CPU.Build.0 = Release|Any CPU
{5617C94C-B2F9-429C-B4C1-DDD03380A108}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5617C94C-B2F9-429C-B4C1-DDD03380A108}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5617C94C-B2F9-429C-B4C1-DDD03380A108}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5617C94C-B2F9-429C-B4C1-DDD03380A108}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63} = {C7CCF187-9F99-4091-B092-6397C35BE9F1}
Expand All @@ -97,5 +103,6 @@ Global
{E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{D9327D60-67EE-4AF3-BD99-8A95634600B5} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{5617C94C-B2F9-429C-B4C1-DDD03380A108} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
EndGlobalSection
EndGlobal
30 changes: 30 additions & 0 deletions mod/TTT.Debug/Commands/GetRagdoll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using TTT.Public.Behaviors;
using TTT.Public.Extensions;

namespace TTT.Debug.Commands;

public class GetRagdoll : IPluginBehavior {
[ConsoleCommand("css_getragdoll")]
[CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
public void Command_GetRagdoll(CCSPlayerController? executor,
CommandInfo command) {
if (executor == null) return;

var body = executor.GetClientRagdollAimTarget();
if (body == null) {
command.ReplyToCommand("No body found");
return;
}

if (!body.IsValid) {
command.ReplyToCommand("Found body, but is invalid");
return;
}

command.ReplyToCommand("Found " + body.DesignerName + " of "
+ body.PlayerName);
}
}
11 changes: 11 additions & 0 deletions mod/TTT.Debug/DebugServiceExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using TTT.Debug.Commands;
using TTT.Public.Extensions;

namespace TTT.Debug;

public static class DebugServiceExtension {
public static void AddDebugBehavior(this IServiceCollection collection) {
collection.AddPluginBehavior<GetRagdoll>();
}
}
17 changes: 17 additions & 0 deletions mod/TTT.Debug/TTT.Debug.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\TTT.Public\TTT.Public.csproj" />
</ItemGroup>

</Project>
14 changes: 3 additions & 11 deletions mod/TTT.Detective/DetectiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class DetectiveManager(IPlayerService roleService)
public void Start(BasePlugin parent) {
parent.RegisterListener<Listeners.OnTick>(() => {
foreach (var player in Utilities.GetPlayers()
.Where(player => player.IsValid && player.IsReal())
.Where(player => (player.Buttons & PlayerButtons.Use) != 0))
OnPlayerUse(player);
});
Expand Down Expand Up @@ -63,15 +62,11 @@ public HookResult OnZeus(DynamicHook hook) {
private void OnPlayerUse(CCSPlayerController player) { IdentifyBody(player); }

private void IdentifyBody(CCSPlayerController caller) {
//add states

if (roleService.GetPlayer(caller).PlayerRole() != Role.Detective) return;
// if (roleService.GetPlayer(caller).PlayerRole() != Role.Detective) return;

var entity = caller.GetClientRagdollAimTarget();

if (entity == null) return;

if (entity.PawnIsAlive) return;
if (entity == null || !entity.PawnIsAlive) return;

var player = roleService.GetPlayer(entity);

Expand All @@ -95,7 +90,6 @@ private void IdentifyBody(CCSPlayerController caller) {
.PlayerRole()
.FormatStringFullAfter(killerEntity.PlayerName));


player.SetFound(true);

Server.NextFrame(() => { Server.PrintToChatAll(message); });
Expand All @@ -117,9 +111,7 @@ private void IdentifyBody(CCSPlayerController caller) {
if (player_pawn == null || !player_pawn.IsValid) return null;

// controller valid
if (player_pawn.OriginalController == null
|| !player_pawn.OriginalController.IsValid)
return null;
if (player_pawn.OriginalController is not { IsValid: true }) return null;

// any further validity is up to the caller
return player_pawn.OriginalController.Value;
Expand Down
Loading

0 comments on commit ba5ab55

Please sign in to comment.