Skip to content

Commit 0232a7e

Browse files
committed
fix: recompile latest cs# version
optmize: remove .GetPlayers() in OnTick
1 parent c5e19dc commit 0232a7e

12 files changed

Lines changed: 385 additions & 100 deletions

File tree

.editorconfig

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
2+
# top-most EditorConfig file
3+
root = true
4+
###############################
5+
# Core EditorConfig Options #
6+
###############################
7+
# All files
8+
[*]
9+
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 4
12+
trim_trailing_whitespace = true
13+
14+
# Generated code
15+
[*{_AssemblyInfo.cs,.g.cs}]
16+
generated_code = true
17+
18+
# XML project files
19+
[*.{csproj}]
20+
indent_size = 2
21+
22+
# Code files
23+
24+
###############################
25+
# .NET Coding Conventions #
26+
###############################
27+
[*.{cs}]
28+
29+
# Organize usings
30+
dotnet_sort_system_directives_first = false
31+
32+
# this. preferences
33+
dotnet_style_qualification_for_field = false:suggestion
34+
dotnet_style_qualification_for_property = false:suggestion
35+
dotnet_style_qualification_for_method = false:suggestion
36+
dotnet_style_qualification_for_event = false:suggestion
37+
38+
# Language keywords vs BCL types preferences
39+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
40+
dotnet_style_predefined_type_for_member_access = true:suggestion
41+
42+
# Parentheses preferences
43+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
44+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
45+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
46+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
47+
48+
# Modifier preferences
49+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning
50+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
51+
dotnet_style_readonly_field = true:warning
52+
53+
# Expression-level preferences
54+
dotnet_style_object_initializer = true:suggestion
55+
dotnet_style_collection_initializer = true:suggestion
56+
dotnet_style_explicit_tuple_names = true:suggestion
57+
dotnet_style_null_propagation = true:suggestion
58+
dotnet_style_coalesce_expression = true:suggestion
59+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
60+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
61+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
62+
dotnet_style_prefer_auto_properties = true:suggestion
63+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
64+
dotnet_style_prefer_conditional_expression_over_return = true:silent
65+
csharp_prefer_simple_default_expression = true:suggestion
66+
67+
###############################
68+
# Naming Conventions #
69+
###############################
70+
# Style Definitions
71+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
72+
73+
# Use PascalCase for constant fields
74+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
75+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
76+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
77+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
78+
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
79+
dotnet_naming_symbols.constant_fields.required_modifiers = const
80+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
81+
82+
# internal and private fields should be _camelCase
83+
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
84+
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
85+
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
86+
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
87+
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
88+
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
89+
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
90+
91+
###############################
92+
# C# Coding Conventions #
93+
###############################
94+
[*.cs]
95+
# var preferences
96+
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
97+
dotnet_style_predefined_type_for_member_access = true:warning
98+
csharp_style_var_elsewhere = false:warning
99+
csharp_style_var_for_built_in_types = false:warning
100+
csharp_style_var_when_type_is_apparent = false:warning
101+
102+
# Parentheses preferences
103+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
104+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
105+
dotnet_style_parentheses_in_other_operators = always_for_clarity:warning
106+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
107+
108+
csharp_using_directive_placement = outside_namespace:warning
109+
csharp_prefer_braces = true:suggestion
110+
csharp_preserve_single_line_blocks = true:none
111+
csharp_preserve_single_line_statements = false:none
112+
csharp_prefer_static_local_function = true:suggestion
113+
csharp_prefer_simple_using_statement = true:suggestion
114+
csharp_style_prefer_switch_expression = true:suggestion
115+
116+
# Expression-bodied members
117+
csharp_style_expression_bodied_methods = true:suggestion
118+
csharp_style_expression_bodied_constructors = true:suggestion
119+
csharp_style_expression_bodied_operators = true:suggestion
120+
csharp_style_expression_bodied_properties = true:suggestion
121+
csharp_style_expression_bodied_indexers = true:suggestion
122+
csharp_style_expression_bodied_accessors = true:suggestion
123+
csharp_style_expression_bodied_lambdas = true:suggestion
124+
csharp_style_expression_bodied_local_functions = true:suggestion
125+
126+
# Pattern matching preferences
127+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
128+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
129+
csharp_style_inlined_variable_declaration = true:suggestion
130+
131+
# Null-checking preferences
132+
csharp_style_throw_expression = true:suggestion
133+
csharp_style_conditional_delegate_call = true:suggestion
134+
135+
# Other features
136+
csharp_style_prefer_index_operator = true:suggestion
137+
csharp_style_prefer_range_operator = true:suggestion
138+
csharp_style_pattern_local_over_anonymous_function = false:none
139+
140+
###############################
141+
# C# Formatting Rules #
142+
###############################
143+
indent_size = 4
144+
insert_final_newline = true
145+
charset = utf-8
146+
147+
# New line preferences
148+
csharp_new_line_before_open_brace = all
149+
csharp_new_line_before_else = true
150+
csharp_new_line_before_catch = true
151+
csharp_new_line_before_finally = true
152+
csharp_new_line_before_members_in_object_initializers = true
153+
csharp_new_line_before_members_in_anonymous_types = true
154+
csharp_new_line_between_query_expression_clauses = true
155+
156+
# Indentation preferences
157+
csharp_indent_block_contents = true
158+
csharp_indent_braces = false
159+
csharp_indent_case_contents = true
160+
csharp_indent_case_contents_when_block = true
161+
csharp_indent_switch_labels = true
162+
csharp_indent_labels = one_less_than_current
163+
164+
# Space preferences
165+
csharp_space_after_cast = true
166+
csharp_space_after_colon_in_inheritance_clause = true
167+
csharp_space_after_comma = true
168+
csharp_space_after_dot = false
169+
csharp_space_after_keywords_in_control_flow_statements = true
170+
csharp_space_after_semicolon_in_for_statement = true
171+
csharp_space_between_method_call_parameter_list_parentheses = false
172+
csharp_space_between_method_declaration_parameter_list_parentheses = false
173+
csharp_space_between_parentheses = false
174+
csharp_space_before_comma = false
175+
csharp_space_before_dot = false
176+
csharp_space_before_open_square_brackets = false
177+
csharp_space_before_semicolon_in_for_statement = false
178+
csharp_space_between_empty_square_brackets = false
179+
csharp_space_around_declaration_statements = do_not_ignore
180+
csharp_space_before_colon_in_inheritance_clause = true
181+
csharp_space_after_colon_in_inheritance_clause = true
182+
csharp_space_around_binary_operators = before_and_after
183+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
184+
csharp_space_between_method_call_name_and_opening_parenthesis = false
185+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
186+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
187+
csharp_space_between_square_brackets = false
188+
189+
# Wrapping preferences
190+
csharp_preserve_single_line_statements = true
191+
csharp_preserve_single_line_blocks = true
192+
193+
# License header
194+
file_header_template = Copyright 2025 Google LLC\n\nLicensed under the Apache License, Version 2.0 (the "License"):\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an "AS IS" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.
195+
csharp_style_namespace_declarations = file_scoped:suggestion
196+
csharp_style_prefer_null_check_over_type_check = true:suggestion
197+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
198+
csharp_style_prefer_tuple_swap = true:suggestion
199+
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
200+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
201+
csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
202+
csharp_style_prefer_pattern_matching = true:suggestion
203+
csharp_style_prefer_not_pattern = true:suggestion
204+
csharp_style_prefer_extended_property_pattern = true:suggestion
205+
csharp_style_prefer_parameter_null_checking = true:suggestion
206+
csharp_style_prefer_method_group_conversion = true:suggestion

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bin/
22
obj/
3-
.vs/
3+
.vs/
4+
.vscode/

src/Enums/ZoneType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
public enum ZoneType
44
{
55
Green,
6-
Red
7-
}
6+
Red,
7+
}

src/Events.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CounterStrikeSharp.API;
1+
using CounterStrikeSharp.API.Core;
22
using CounterStrikeSharp.API.Modules.Utils;
33
using RetakesPluginShared.Events;
44

@@ -9,17 +9,36 @@ public partial class Zones
99
private void OnRetakesEvent(object? sender, IRetakesPluginEvent @event)
1010
{
1111
if (@event is not AnnounceBombsiteEvent announceBombsiteEvent)
12+
{
1213
return;
14+
}
1315

14-
var zones = _zones.Where(z => z.Bombsite == announceBombsiteEvent.Bombsite).ToList();
15-
16-
foreach (var player in Utilities.GetPlayers().Where(p => p is { IsValid: true, PawnIsAlive: true }))
16+
for (int i = 0; i < MAX_PLAYERS; i++)
1717
{
18-
if (player.PlayerPawn.Value == null || !_playerData.TryGetValue(player, out var playerData))
18+
PlayerData? playerData = _playerData[i];
19+
CCSPlayerController? player = playerData?.Player;
20+
21+
if (
22+
playerData is null
23+
|| player is not { IsValid: true, LifeState: (byte)LifeState_t.LIFE_ALIVE }
24+
|| player.PlayerPawn.Value is not { IsValid: true }
25+
)
26+
{
1927
continue;
28+
}
29+
30+
CsTeam playerTeam = (CsTeam)player.PlayerPawn.Value.TeamNum;
2031

21-
playerData.Zones = zones.Where(z => z.Teams.Contains((CsTeam)player.PlayerPawn.Value.TeamNum)).ToList();
32+
playerData.Zones = [];
2233
playerData.GreenZones = [];
34+
35+
foreach (Zone zone in _zones[(int)announceBombsiteEvent.Bombsite])
36+
{
37+
if (zone.Teams.Contains(playerTeam))
38+
{
39+
playerData.Zones.Add(zone);
40+
}
41+
}
2342
}
2443
}
25-
}
44+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using CounterStrikeSharp.API.Core;
2+
using CounterStrikeSharp.API.Modules.Utils;
3+
4+
namespace Zones.Extensions;
5+
6+
public static class PlayerPawnExtension
7+
{
8+
public static void Bounce(this CCSPlayerPawn playerPawn)
9+
{
10+
Vector vel = new(
11+
playerPawn.AbsVelocity.X,
12+
playerPawn.AbsVelocity.Y,
13+
playerPawn.AbsVelocity.Z
14+
);
15+
16+
double speed = Math.Sqrt((vel.X * vel.X) + (vel.Y * vel.Y));
17+
18+
vel *= -350 / (float)speed;
19+
vel.Z = vel.Z <= 0 ? 150 : Math.Min(vel.Z, 150);
20+
playerPawn.Teleport(playerPawn.AbsOrigin, playerPawn.EyeAngles, vel);
21+
}
22+
}

src/Globals.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
using CounterStrikeSharp.API.Core;
2-
using CounterStrikeSharp.API.Core.Capabilities;
1+
using CounterStrikeSharp.API.Core.Capabilities;
32
using RetakesPluginShared;
3+
using RetakesPluginShared.Enums;
44

55
namespace Zones;
66

77
public partial class Zones
88
{
9+
private const int MAX_PLAYERS = 64;
10+
911
public override string ModuleName => "Retakes-Zones";
10-
public override string ModuleVersion => "1.1.1";
12+
public override string ModuleVersion => "1.2.0";
1113
public override string ModuleAuthor => "https://github.com/oscar-wos/Retakes-Zones";
12-
private static PluginCapability<IRetakesPluginEventSender> RetakesPluginEventSenderCapability { get; } = new("retakes_plugin:event_sender");
1314

14-
private readonly List<Zone> _zones = [];
15-
private readonly Dictionary<CCSPlayerController, PlayerData> _playerData = [];
16-
}
15+
private static readonly PluginCapability<IRetakesPluginEventSender> _retakesEventSenderCapability =
16+
new("retakes_plugin:event_sender");
17+
18+
private static readonly PlayerData?[] _playerData = new PlayerData?[MAX_PLAYERS];
19+
20+
private static readonly List<Zone>[] _zones = new List<Zone>[
21+
Enum.GetValues(typeof(Bombsite)).Length
22+
];
23+
24+
static Zones()
25+
{
26+
for (int i = 0; i < Enum.GetValues(typeof(Bombsite)).Length; i++)
27+
{
28+
_zones[i] = [];
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)