Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

randomizer (works this time i think) #1349

Closed
wants to merge 17 commits into from
Closed
  •  
  •  
  •  
186 changes: 1 addition & 185 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,188 +1,4 @@
[*.cs]
[*.cs]

# CA2211: Non-constant fields should not be visible
dotnet_diagnostic.CA2211.severity = none

[*.cs]
#### 命名样式 ####

# 命名规则

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# 符号规范

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# 命名样式

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
csharp_space_around_binary_operators = before_and_after
csharp_using_directive_placement = outside_namespace:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = false:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_static_local_function = true:suggestion
csharp_prefer_static_anonymous_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion
csharp_indent_labels = one_less_than_current
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:silent
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
csharp_style_prefer_switch_expression = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_prefer_utf8_string_literals = true:silent
csharp_style_throw_expression = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent

[*.vb]
#### 命名样式 ####

# 命名规则

dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion
dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface
dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始

dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion
dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型
dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法

dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion
dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员
dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法

# 符号规范

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.类型.required_modifiers =

dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method
dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.非字段成员.required_modifiers =

# 命名样式

dotnet_naming_style.以_i_开始.required_prefix = I
dotnet_naming_style.以_i_开始.required_suffix =
dotnet_naming_style.以_i_开始.word_separator =
dotnet_naming_style.以_i_开始.capitalization = pascal_case

dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case

dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case

[*.{cs,vb}]
end_of_line = crlf
tab_width = 4
indent_size = 4
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_code_quality_unused_parameters = all:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
insert_final_newline = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line
indent_style = space
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ FodyWeavers.xsd
TOHE.sln
.vscode/settings.json
/token.env
token.env
2 changes: 1 addition & 1 deletion GameModes/FFAManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static void Init()
public static void SetData()
{
if (Options.CurrentGameMode != CustomGameMode.FFA) return;

RoundTime = FFA_GameTime.GetInt() + 8;
var now = Utils.GetTimeStamp() + 8;
foreach (PlayerControl pc in Main.AllAlivePlayerControls)
Expand Down
3 changes: 1 addition & 2 deletions GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
// it is recommended to add only those that are used most often

global using HarmonyLib;
global using System.Collections.Generic;
global using System.Linq;
global using System.Reflection;
global using System.Collections.Generic;
34 changes: 5 additions & 29 deletions Modules/AntiBlackout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static bool CheckBlackOut()
if (lastExiled != null && pc.PlayerId == lastExiled.PlayerId) continue;

// Impostors
if (pc.Is(Custom_Team.Impostor))
if (pc.Is(Custom_Team.Impostor) && !Main.PlayerStates[pc.PlayerId].IsRandomizer)
Impostors.Add(pc.PlayerId);

// Only Neutral killers
else if (pc.IsNeutralKiller() || pc.IsNeutralApocalypse())
else if (pc.IsNeutralKiller() || pc.IsNeutralApocalypse() && !Main.PlayerStates[pc.PlayerId].IsRandomizer)
NeutralKillers.Add(pc.PlayerId);

// Crewmate
Expand Down Expand Up @@ -100,13 +100,7 @@ private static void RevivePlayersAndSetDummyImp()
if (CustomWinnerHolder.WinnerTeam != CustomWinner.Default) return;

PlayerControl dummyImp = Main.AllAlivePlayerControls.FirstOrDefault(x => x.PlayerId != ExilePlayerId);

if (dummyImp == null)
{
Logger.Warn("Cant find a alive dummy Imp, AntiBlackout may break?", "AntiBlackout.RevivePlayersAndSetDummyImp");
Logger.SendInGame("Cant find a alive dummy Imp, AntiBlackout may break?");
return;
}
if (dummyImp == null) return;

foreach (var seer in Main.AllPlayerControls)
{
Expand All @@ -133,25 +127,7 @@ public static void RestoreIsDead(bool doSend = true, [CallerMemberName] string c
}
isDeadCache.Clear();
IsCached = false;
if (doSend)
{
SendGameData();
_ = new LateTask(() => RestoreIsDeadByExile(), 0.3f, "AntiBlackOut_RestoreIsDeadByExile");
}
}

private static void RestoreIsDeadByExile()
{
var sender = CustomRpcSender.Create("AntiBlackout RestoreIsDeadByExile", SendOption.Reliable);
foreach (var player in Main.AllPlayerControls)
{
if (player.Data.IsDead && !player.Data.Disconnected)
{
sender.AutoStartRpc(player.NetId, (byte)RpcCalls.Exiled);
sender.EndRpc();
}
}
sender.SendMessage();
if (doSend) SendGameData();
}

public static void SendGameData([CallerMemberName] string callerMethodName = "")
Expand Down Expand Up @@ -250,7 +226,7 @@ public static void SetRealPlayerRoles()
{
// skip host
if (seerId == 0) continue;

var seer = seerId.GetPlayer();
var target = targetId.GetPlayer();

Expand Down
14 changes: 5 additions & 9 deletions Modules/BanManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using InnerNet;
using System;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -79,20 +80,15 @@ public static string GetHashedPuid(this ClientData player)
{
if (player == null) return "";
string puid = player.ProductUserId;
return GetHashedPuid(puid);
}
public static string GetHashedPuid(string puid)
{
using SHA256 sha256 = SHA256.Create();

// get sha-256 hash
byte[] sha256Bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(puid));
string sha256Hash = BitConverter.ToString(sha256Bytes).Replace("-", "").ToLower();

// pick front 5 and last 4
return string.Concat(sha256Hash.AsSpan(0, 5), sha256Hash.AsSpan(sha256Hash.Length - 4));
}

public static void AddBanPlayer(ClientData player)
{
if (!AmongUsClient.Instance.AmHost || player == null) return;
Expand All @@ -108,7 +104,7 @@ public static void AddBanPlayer(ClientData player)
else Logger.Info($"Failed to add player {player?.PlayerName.RemoveHtmlTags()}/{player?.FriendCode}/{player?.GetHashedPuid()} to ban list!", "AddBanPlayer");
}
}

public static bool CheckDenyNamePlayer(PlayerControl player, string name)
{
if (!AmongUsClient.Instance.AmHost || !Options.ApplyDenyNameList.GetBool()) return false;
Expand Down Expand Up @@ -229,9 +225,9 @@ public static bool CheckEACList(string code, string hashedPuid)
var splitUser = user["friendcode"].ToString().Split('#')[0].ToLower().Trim();

if ((!string.IsNullOrEmpty(splitCode) && (splitCode == splitUser))
|| !hashedPuid.IsNullOrWhiteSpace() && (user["hashPUID"].ToString().ToLower().Trim() == hashedPuid.ToLower().Trim()))
|| (user["hashPUID"].ToString().ToLower().Trim() == hashedPuid.ToLower().Trim()))
{
Logger.Warn($"friendcode : {code}, hashedPUID : {hashedPuid} banned by EAC reason : {user["friendcode"]} {user["reason"]}", "CheckEACList");
Logger.Warn($"friendcode : {code}, hashedPUID : {hashedPuid} banned by EAC reason : {user["reason"]}", "CheckEACList");
return true;
}
}
Expand Down
17 changes: 13 additions & 4 deletions Modules/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Security.Cryptography;
using System.Text;
using TOHE.Roles.Impostor;
using TOHE.Roles.Neutral;
using static TOHE.Translator;

namespace TOHE.Modules.ChatManager
Expand Down Expand Up @@ -93,6 +94,10 @@ public static void AddToHostMessage(string text)
}
public static void SendMessage(PlayerControl player, string message)
{
if (player == null || string.IsNullOrWhiteSpace(message)) return;



int operate = 0; // 1:ID 2:猜测
string msg = message;
string playername = player.GetNameWithRole();
Expand All @@ -103,6 +108,9 @@ public static void SendMessage(PlayerControl player, string message)
else if (CheckCommond(ref msg, "shoot|guess|bet|st|gs|bt|猜|赌|賭|sp|jj|tl|trial|审判|判|审|審判|審|compare|cmp|比较|比較|duel|sw|swap|st|换票|换|換票|換|finish|结束|结束会议|結束|結束會議|reveal|展示", false)) operate = 2;
else if (ChatSentBySystem.Contains(GetTextHash(msg))) operate = 5;



// Handle Blackmailer blocking
if ((operate == 1 || Blackmailer.CheckBlackmaile(player)) && player.IsAlive())
{
Logger.Info($"包含特殊信息,不记录", "ChatManager");
Expand Down Expand Up @@ -139,12 +147,12 @@ public static void SendMessage(PlayerControl player, string message)
return;
}
if (!player.IsAlive()) return;

message = msg;
//Logger.Warn($"Logging msg : {message}","Checking Exile");
Dictionary<byte, string> newChatEntry = new()
{
{ player.PlayerId, message }
};
{
{ player.PlayerId, message }
};
chatHistory.Add(newChatEntry);

if (chatHistory.Count > maxHistorySize)
Expand All @@ -155,6 +163,7 @@ public static void SendMessage(PlayerControl player, string message)
}
}


public static void SendPreviousMessagesToAll()
{
if (!AmongUsClient.Instance.AmHost || !GameStates.IsModHost) return;
Expand Down
1 change: 1 addition & 0 deletions Modules/Cloud.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net.Sockets;
using System.Reflection;
using System.Text;

namespace TOHE;
Expand Down
Loading
Loading