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

Commit

Permalink
Refactored codebase
Browse files Browse the repository at this point in the history
Refactored the code base and made it easier to maintain.

New features:

    Colored bodies
    Better logs system
    Added /roles command for admins
    Start working on configuration
    Started rebuilding the Shop
  • Loading branch information
ntm5 authored Jul 10, 2024
2 parents 572b17a + a1af31e commit 3c4b654
Show file tree
Hide file tree
Showing 110 changed files with 3,759 additions and 3,104 deletions.
1,348 changes: 674 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

120 changes: 60 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
## cs2TTT

## Contributing
TTT is in heavy development and I want you to know that contributions are always welcome. Please follow Microsoft's dependency injection system.

> [!TIP]
> Microsoft has some good documentation on dependency injection here:
> [Overview](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection),
> [Using Dependency Injection](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-usage),
> [Dependency Injection Guidelines](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines).
## Creating items

Creating new items or modifying existing ones is easy. Create a new class in the correct directory, mod/TTT.Shop/Items/{group}. Then create it to your liking. Afterwards, compile the plugin and it's all set. The plugin handles loading all the items.

> [!TIP]
> Available groups are [All, Detective, Traitor]. <br>
> SimpleName is used for /buy {name}
#### Example Item
```c#
namespace TTT.Shop.Items.Traitor;

public class AwpItem : IShopItem
{
public string Name()
{
return "AWP";
}

public string SimpleName()
{
return "awp";
}

public int Price()
{
return 2000;
}

public BuyResult OnBuy(GamePlayer player)
{
if (player.Credits() < Price()) return BuyResult.NotEnoughCredits;
if (player.PlayerRole() != Role.Traitor) return BuyResult.IncorrectRole;
player.RemoveCredits(Price());
player.Player().GiveNamedItem(CsItem.AWP);
return BuyResult.Successful;
}
}
```

## Road Map
- [] Role assignment
- [] DNA Scanner
- [] Tazer
- [ ] Configuration
- [ ] Karma system
- [ ] Shop
- [ ] RDM Manager
- [ ] Add database support for logs and stats
## cs2TTT

## Contributing
TTT is in heavy development and I want you to know that contributions are always welcome. Please follow Microsoft's dependency injection system.

> [!TIP]
> Microsoft has some good documentation on dependency injection here:
> [Overview](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection),
> [Using Dependency Injection](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-usage),
> [Dependency Injection Guidelines](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines).
## Creating items

Creating new items or modifying existing ones is easy. Create a new class in the correct directory, mod/TTT.Shop/Items/{group}. Then create it to your liking. Afterwards, compile the plugin and it's all set. The plugin handles loading all the items.

> [!TIP]
> Available groups are [All, Detective, Traitor]. <br>
> SimpleName is used for /buy {name}
#### Example Item
```c#
namespace TTT.Shop.Items.Traitor;

public class AwpItem : IShopItem
{
public string Name()
{
return "AWP";
}

public string SimpleName()
{
return "awp";
}

public int Price()
{
return 2000;
}

public BuyResult OnBuy(GamePlayer player)
{
if (player.Credits() < Price()) return BuyResult.NotEnoughCredits;
if (player.PlayerRole() != Role.Traitor) return BuyResult.IncorrectRole;
player.RemoveCredits(Price());
player.Player().GiveNamedItem(CsItem.AWP);
return BuyResult.Successful;
}
}
```

## Road Map
- [] Role assignment
- [] DNA Scanner
- [] Tazer
- [ ] Configuration
- [ ] Karma system
- [ ] Shop
- [ ] RDM Manager
- [ ] Add database support for logs and stats
28 changes: 28 additions & 0 deletions TTT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TTT.Round", "mod\TTT.Round\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Shop", "mod\TTT.Shop\TTT.Shop.csproj", "{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Formatting", "public\TTT.Formatting\TTT.Formatting.csproj", "{C6EE882B-E597-45DB-85FF-A521DC7A0AAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Logs", "mod\TTT.Logs\TTT.Logs.csproj", "{E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Player", "mod\TTT.Player\TTT.Player.csproj", "{D9327D60-67EE-4AF3-BD99-8A95634600B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Manager", "mod\TTT.Manager\TTT.Manager.csproj", "{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -60,6 +68,22 @@ Global
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}.Release|Any CPU.Build.0 = Release|Any CPU
{C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Release|Any CPU.Build.0 = Release|Any CPU
{E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Release|Any CPU.Build.0 = Release|Any CPU
{D9327D60-67EE-4AF3-BD99-8A95634600B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9327D60-67EE-4AF3-BD99-8A95634600B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9327D60-67EE-4AF3-BD99-8A95634600B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9327D60-67EE-4AF3-BD99-8A95634600B5}.Release|Any CPU.Build.0 = Release|Any CPU
{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63} = {C7CCF187-9F99-4091-B092-6397C35BE9F1}
Expand All @@ -69,5 +93,9 @@ Global
{0E7A451E-D56F-4D96-9B5C-5F1B0A6B0656} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{511E712D-31D5-4EFC-9F0F-D9D4A83ED202} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{C6EE882B-E597-45DB-85FF-A521DC7A0AAE} = {C84CEB1F-0132-43EF-9A5F-12C7AA08B8E7}
{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}
EndGlobalSection
EndGlobal
24 changes: 12 additions & 12 deletions gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

# Repository build files
build/
bin/
obj/

Debug/
Release/

# IDE files
.idea/
.vs/

# Repository build files
build/
bin/
obj/
Debug/
Release/
# IDE files
.idea/
.vs/
12 changes: 6 additions & 6 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": false
}
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": false
}
}
7 changes: 7 additions & 0 deletions mod/TTT.Detective/DetectiveConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TTT.Detective;

public class DetectiveConfig
{
public bool DNAScannerEnabled { get; } = true;

}
98 changes: 75 additions & 23 deletions mod/TTT.Detective/DetectiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using TTT.Player;
using TTT.Public.Behaviors;
using TTT.Public.Extensions;
using TTT.Public.Formatting;
using TTT.Public.Mod.Detective;
using TTT.Public.Mod.Role;
using TTT.Public.Player;

namespace TTT.Detective;

public class DetectiveManager : IDetectiveService, IPluginBehavior
public class DetectiveManager(IPlayerService roleService) : IDetectiveService, IPluginBehavior
{
private const int TaserAmmoType = 18;
private readonly IRoleService _roleService;

public DetectiveManager(IRoleService roleService)
{
_roleService = roleService;
}

public void Start(BasePlugin parent)
{
Expand All @@ -30,24 +26,45 @@ public void Start(BasePlugin parent)
});


/**
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(hook =>
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(OnZeus, HookMode.Pre);

}

public HookResult OnZeus(DynamicHook hook)
{
var ent = hook.GetParam<CBaseEntity>(0);

var playerWhoWasDamaged = player(ent);

if (playerWhoWasDamaged == null) return HookResult.Continue;

var info = hook.GetParam<CTakeDamageInfo>(1);

CCSPlayerController? attacker = null;

if (info.Attacker.Value != null)
{
var info = hook.GetParam<CTakeDamageInfo>(1);
if (info.Attacker.Value == null || !info.Attacker.Value.IsValid) return HookResult.Continue;
var attacker = info.Attacker.Value.As<CCSPlayerController>();
if (attacker == hook.GetParam<CBaseEntity>(0)) return HookResult.Continue;
if (info.AmmoType is not TaserAmmoType) return HookResult.Continue;
var playerWhoAttacked = info.Attacker.Value.As<CCSPlayerPawn>();

info.Damage = 1f;
attacker = playerWhoAttacked.Controller.Value.As<CCSPlayerController>();

Check warning on line 49 in mod/TTT.Detective/DetectiveManager.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 49 in mod/TTT.Detective/DetectiveManager.cs

View workflow job for this annotation

GitHub Actions / publish

Dereference of a possibly null reference.

if (!attacker.IsReal()) return HookResult.Continue;
}

var ammoType = info.AmmoType;
if (info.BitsDamageType is not 256) return HookResult.Continue;
if (attacker == null) return HookResult.Continue;

return HookResult.Changed;
}, HookMode.Pre);
*/
info.Damage = 0;

var targetRole = roleService.GetPlayer(playerWhoWasDamaged);

Server.NextFrame(() =>
{
attacker.PrintToChat(
StringUtils.FormatTTT(
$"You tased player {playerWhoWasDamaged.PlayerName} they are a {targetRole.PlayerRole().FormatRoleFull()}"));
});

return HookResult.Stop;
}


Expand All @@ -60,15 +77,15 @@ private void IdentifyBody(CCSPlayerController caller)
{
//add states

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

var entity = caller.GetClientRagdollAimTarget();

if (entity == null) return;

if (entity.PawnIsAlive) return;

var player = _roleService.GetPlayer(entity);
var player = roleService.GetPlayer(entity);

if (player.IsFound()) return;

Expand All @@ -85,11 +102,46 @@ private void IdentifyBody(CCSPlayerController caller)
else
message = StringUtils.FormatTTT(
player.PlayerRole().FormatStringFullAfter($"{plr.PlayerName} was killed by ") +
_roleService.GetRole(killerEntity).FormatStringFullAfter(killerEntity.PlayerName));
roleService.GetPlayer(killerEntity).PlayerRole().FormatStringFullAfter(killerEntity.PlayerName));


player.SetFound(true);

Server.NextFrame(() => { Server.PrintToChatAll(message); });
}

//to be moved to a utility class
public static CCSPlayerController? player(CEntityInstance? instance)
{
if (instance == null)
{
return null;
}

if (instance.DesignerName != "player")
{
return null;
}

// grab the pawn index
int player_index = (int)instance.Index;

// grab player controller from pawn
CCSPlayerPawn player_pawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>(player_index);

Check warning on line 130 in mod/TTT.Detective/DetectiveManager.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

// pawn valid
if (player_pawn == null || !player_pawn.IsValid)
{
return null;
}

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

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

0 comments on commit 3c4b654

Please sign in to comment.