Fix some bugs & Try fixing guessing issue

This commit is contained in:
Gurge44 committed 2024-04-22 19:50:17 +02:00
1 parent d83dc11476
commit 4c8557400f
11 files changed
+93 -90

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@
<Description>EHR</Description>
<Authors>Gurge44</Authors>
<langVersion>preview</langVersion>
<AmongUs>E:\Program Files\AmongUs</AmongUs>
<AmongUs>D:\Epic Games\AmongUs</AmongUs>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>True</Optimize>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
+6 -1
View File
@@ -132,7 +132,12 @@ public class PlayerState(byte playerId)
if (role == CustomRoles.Cleansed)
AllReplace = true;
if (AllReplace)
SubRoles.Do(item => SubRoles.Remove(item));
{
foreach (var item in SubRoles.ToArray())
{
SubRoles.Remove(item);
}
}
if (!SubRoles.Contains(role))
SubRoles.Add(role);
+1 -1
View File
@@ -99,7 +99,7 @@ public static class GuessManager
var originMsg = msg;
if (!AmongUsClient.Instance.AmHost) return false;
if (!GameStates.IsVoting || pc == null) return false;
if (!GameStates.IsMeeting || pc == null) return false;
if (!pc.Is(CustomRoles.NiceGuesser) && !pc.Is(CustomRoles.EvilGuesser) && !pc.Is(CustomRoles.Doomsayer) && !pc.Is(CustomRoles.Judge) && !pc.Is(CustomRoles.NiceSwapper) && !pc.Is(CustomRoles.Councillor) && !pc.Is(CustomRoles.Guesser) && !Options.GuesserMode.GetBool()) return false;
int operate; // 1: ID, 2: Guess
+21 -16
View File
@@ -5,32 +5,37 @@ using System.Linq;
using System.Linq.Expressions;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using StringComparison = Il2CppSystem.StringComparison;
namespace EHR;
public static class ServerAddManager
{
private static readonly ServerManager serverManager = DestroyableSingleton<ServerManager>.Instance;
private static readonly ServerManager ServerManager = DestroyableSingleton<ServerManager>.Instance;
public static void Init()
{
if (CultureInfo.CurrentCulture.Name.StartsWith("zh") && serverManager.AvailableRegions.Count == 10) return;
if (!CultureInfo.CurrentCulture.Name.StartsWith("zh") && serverManager.AvailableRegions.Count == 7) return;
if (CultureInfo.CurrentCulture.Name.StartsWith("zh") && ServerManager.AvailableRegions.Count == 10) return;
if (!CultureInfo.CurrentCulture.Name.StartsWith("zh") && ServerManager.AvailableRegions.Count == 7) return;
serverManager.AvailableRegions = ServerManager.DefaultRegions;
List<IRegionInfo> regionInfos =
[
//.. CultureInfo.CurrentCulture.Name.StartsWith("zh") ? [CreateHttp("au-sh.pafyx.top", "梦服上海 (新)", 22000, false)] : [], // VS is dumb
CreateHttp("au-as.duikbo.at", "Modded Asia (MAS)", 443, true),
CreateHttp("www.aumods.xyz", "Modded NA (MNA)", 443, true),
CreateHttp("au-eu.duikbo.at", "Modded EU (MEU)", 443, true),
CreateHttp("35.247.251.253", "Modded SA (MSA)", 22023, false),
];
regionInfos.Where(x => !serverManager.AvailableRegions.Contains(x)).Do(serverManager.AddOrUpdateRegion);
ServerManager.AvailableRegions = ServerManager.DefaultRegions;
List<IRegionInfo> regionInfos = [];
if (CultureInfo.CurrentCulture.Name.StartsWith("zh"))
{
regionInfos.Add((CreateHttp("45yun.cn", "小猫[北京]", 22000, false)));
regionInfos.Add((CreateHttp("45yun.cn", "小猫[成都]", 2267, false)));
regionInfos.Add((CreateHttp("mau.kaifuxia.top", "新梦初[上海]", 25000, false)));
}
regionInfos.Add(CreateHttp("au-as.duikbo.at", "Modded Asia (MAS)", 443, true));
regionInfos.Add(CreateHttp("www.aumods.us", "Modded NA (MNA)", 443, true));
regionInfos.Add(CreateHttp("au-eu.duikbo.at", "Modded EU (MEU)", 443, true));
regionInfos.Add(CreateHttp("35.247.251.253", "Modded SA (MSA)", 22023, false));
regionInfos.Where(x => !ServerManager.AvailableRegions.Contains(x)).Do(ServerManager.AddOrUpdateRegion);
ServerManager.CurrentRegion = ServerManager.AvailableRegions.FirstOrDefault(x => x.Name.Contains("Europe", StringComparison.OrdinalIgnoreCase)) ?? ServerManager.AvailableRegions.FirstOrDefault() ?? regionInfos.First();
}
public static IRegionInfo CreateHttp(string ip, string name, ushort port, bool ishttps)
private static IRegionInfo CreateHttp(string ip, string name, ushort port, bool ishttps)
{
string serverIp = (ishttps ? "https://" : "http://") + ip;
ServerInfo serverInfo = new(name, serverIp, port, false);
@@ -40,7 +45,7 @@ public static class ServerAddManager
private static class CastHelper<T> where T : Il2CppObjectBase
{
public static Func<IntPtr, T> Cast;
public static readonly Func<IntPtr, T> Cast;
static CastHelper()
{
+6 -23
View File
@@ -715,7 +715,6 @@ internal class ChatCommands
if (Silencer.ForSilencer.Contains(PlayerControl.LocalPlayer.PlayerId) && PlayerControl.LocalPlayer.IsAlive())
{
ChatManager.SendPreviousMessagesToAll();
ChatManager.cancel = false;
goto Canceled;
}
@@ -1061,10 +1060,9 @@ internal class ChatCommands
_ = sb.Append("\n\n" + GetString($"{subRole}") + Utils.GetRoleMode(subRole) + GetString($"{subRole}InfoLong"));
}
ChatManager.DontBlock = true;
Utils.SendMessage("\n", player.PlayerId, settings.ToString());
Utils.SendMessage(sb.ToString(), player.PlayerId, string.Empty);
_ = new LateTask(() => ChatManager.DontBlock = false, 0.5f, log: false);
_ = new LateTask(() => { }, 0.5f, log: false);
}
else
Utils.SendMessage(GetString("Message.CanNotUseInLobby"), player.PlayerId);
@@ -1321,7 +1319,6 @@ internal class ChatCommands
if (Silencer.ForSilencer.Contains(player.PlayerId) && player.IsAlive() && player.PlayerId != 0)
{
ChatManager.SendPreviousMessagesToAll();
ChatManager.cancel = false;
canceled = true;
LastSentCommand[player.PlayerId] = now;
return;
@@ -1367,37 +1364,23 @@ internal class ChatUpdatePatch
}
var writer = CustomRpcSender.Create("MessagesToSend");
_ = writer.StartMessage(clientId);
_ = writer.StartRpc(player.NetId, (byte)RpcCalls.SetName)
writer.StartMessage(clientId);
writer.StartRpc(player.NetId, (byte)RpcCalls.SetName)
.Write(title)
.EndRpc();
_ = writer.StartRpc(player.NetId, (byte)RpcCalls.SendChat)
writer.StartRpc(player.NetId, (byte)RpcCalls.SendChat)
.Write(msg)
.EndRpc();
_ = writer.StartRpc(player.NetId, (byte)RpcCalls.SetName)
writer.StartRpc(player.NetId, (byte)RpcCalls.SetName)
.Write(player.Data.PlayerName)
.EndRpc();
_ = writer.EndMessage();
writer.EndMessage();
writer.SendMessage();
__instance.timeSinceLastMessage = 0f;
}
}
//[HarmonyPatch(typeof(ChatController), nameof(ChatController.AddChat))]
//internal class AddChatPatch
//{
// public static void Postfix(string chatText)
// {
// switch (chatText)
// {
// default:
// break;
// }
// if (!AmongUsClient.Instance.AmHost) return;
// }
//}
[HarmonyPatch(typeof(FreeChatInputField), nameof(FreeChatInputField.UpdateCharCount))]
internal class UpdateCharCountPatch
{
+11 -9
View File
@@ -75,7 +75,6 @@ class ChatControllerUpdatePatch
public static class ChatManager
{
public static bool cancel;
private static readonly List<string> ChatHistory = [];
private const int MaxHistorySize = 20;
@@ -84,7 +83,7 @@ public static class ChatManager
ChatHistory.Clear();
}
public static bool CheckCommand(ref string msg, string command, bool exact = true)
private static bool CheckCommand(ref string msg, string command, bool exact = true)
{
var comList = command.Split('|');
foreach (string str in comList)
@@ -106,7 +105,7 @@ public static class ChatManager
return false;
}
public static bool CheckName(ref string msg, string command, bool exact = true)
private static bool CheckName(ref string msg, string command, bool exact = true)
{
var comList = command.Split('|');
foreach (string com in comList)
@@ -141,7 +140,6 @@ public static class ChatManager
if (Silencer.ForSilencer.Contains(player.PlayerId) && player.IsAlive())
{
cancel = true;
return;
}
@@ -157,17 +155,23 @@ public static class ChatManager
{
case 1 when player.IsAlive(): // Guessing Command & Such
Logger.Info("Special Command", "ChatManager");
cancel = true;
_ = new LateTask(() =>
{
if (!ChatCommands.LastSentCommand.ContainsKey(player.PlayerId))
{
GuessManager.GuesserMsg(player, message);
Logger.Info("Delayed Guess", "ChatManager");
}
else Logger.Info("Delayed Guess was not necessary", "ChatManager");
}, 0.3f, "Trying Delayed Guess");
break;
case 2: // /up
Logger.Info($"Command: {message}", "ChatManager");
cancel = false;
break;
case 3: // In Lobby & Evertything Else
string chatEntry = $"{player.PlayerId}: {message}";
ChatHistory.Add(chatEntry);
if (ChatHistory.Count > MaxHistorySize) ChatHistory.RemoveAt(0);
cancel = false;
break;
case 4: // /r, /n, /m
Logger.Info($"Command: {message}", "ChatManager");
@@ -181,8 +185,6 @@ public static class ChatManager
}
}
public static bool DontBlock;
public static void SendPreviousMessagesToAll(bool realMessagesOnly = false)
{
if (!AmongUsClient.Instance.AmHost || !GameStates.IsModHost) return;
+11 -4
View File
@@ -190,18 +190,20 @@ class ExileControllerWrapUpPatch
static void WrapUpFinalizer(GameData.PlayerInfo exiled)
{
//WrapUpPostfixで例外が発生しても、この部分だけは確実に実行されます。
// Even if an exception occurs in WrapUpPostfix, this part will be executed reliably.
bool overrideExiledPlayer = false;
if (AmongUsClient.Instance.AmHost)
{
_ = new LateTask(() =>
{
exiled = AntiBlackout_LastExiled;
AntiBlackout.SendGameData();
if (AntiBlackout.OverrideExiledPlayer && // 追放対象が上書きされる状態 (上書きされない状態なら実行不要)
exiled != null && //exiledがnullでない
exiled.Object != null) //exiled.Objectがnullでない
if (AntiBlackout.OverrideExiledPlayer && // State where the exile target is overwritten (no need to execute if it is not overwritten)
exiled != null &&
exiled.Object != null)
{
exiled.Object.RpcExileV2();
overrideExiledPlayer = true;
}
}, 0.8f, "Restore IsDead Task");
_ = new LateTask(() =>
@@ -244,6 +246,11 @@ class ExileControllerWrapUpPatch
finalText = $"\n{notify.TEXT}\n{finalText}";
}
if (overrideExiledPlayer && CheckForEndVotingPatch.EjectionText != string.Empty)
{
finalText = $"\n{CheckForEndVotingPatch.EjectionText}\n{finalText}";
}
pc.Notify(finalText, r.Next(7, 13));
}
}, 0.5f, log: false);
+13 -8
View File
@@ -16,6 +16,8 @@ namespace EHR.Patches;
[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.CheckForEndVoting))]
class CheckForEndVotingPatch
{
public static string EjectionText = string.Empty;
public static bool Prefix(MeetingHud __instance)
{
if (!AmongUsClient.Instance.AmHost) return true;
@@ -128,6 +130,7 @@ class CheckForEndVotingPatch
GameData.PlayerInfo exiledPlayer = PlayerControl.LocalPlayer.Data;
bool tie = false;
EjectionText = string.Empty;
foreach (var ps in __instance.playerStates)
{
@@ -399,14 +402,14 @@ class CheckForEndVotingPatch
{
name += " (";
var team = CustomTeamManager.GetCustomTeam(player.PlayerId);
if (team != null)
name += Utils.ColorString(team.RoleRevealScreenBackgroundColor == "*" || !ColorUtility.TryParseHtmlString(team.RoleRevealScreenBackgroundColor, out var color) ? Color.yellow : color, team.RoleRevealScreenTitle == "*" ? team.TeamName : team.RoleRevealScreenTitle);
else if (player.GetCustomRole().IsImpostor() || player.Is(CustomRoles.Madmate))
name += Utils.ColorString(new(255, 25, 25, byte.MaxValue), GetString("TeamImpostor"));
else if (player.GetCustomRole().IsNeutral() || player.Is(CustomRoles.Charmed))
name += Utils.ColorString(new(255, 171, 27, byte.MaxValue), GetString("TeamNeutral"));
else if (player.IsCrewmate())
name += Utils.ColorString(new(140, 255, 255, byte.MaxValue), GetString("TeamCrewmate"));
if (team != null) name += Utils.ColorString(team.RoleRevealScreenBackgroundColor == "*" || !ColorUtility.TryParseHtmlString(team.RoleRevealScreenBackgroundColor, out var color) ? Color.yellow : color, team.RoleRevealScreenTitle == "*" ? team.TeamName : team.RoleRevealScreenTitle);
else name += player.GetTeam() switch
{
Team.Impostor => Utils.ColorString(new(255, 25, 25, byte.MaxValue), GetString("TeamImpostor")),
Team.Neutral => Utils.ColorString(new(255, 171, 27, byte.MaxValue), GetString("TeamNeutral")),
Team.Crewmate => Utils.ColorString(new(140, 255, 255, byte.MaxValue), GetString("TeamCrewmate")),
_ => "----"
};
name += ")";
}
@@ -505,6 +508,8 @@ class CheckForEndVotingPatch
player.RpcSetName(realName);
Main.DoBlockNameChange = false;
}
EjectionText = name.Split('\n')[0];
}, 11.5f, "Change Exiled Player Name Back");
}
+1 -1
View File
@@ -2714,7 +2714,7 @@
"Bargainer.Suffix.InShop": "<size=80%>[<#00ffa5>Shop</color>] Selected: {0} ({1})</size>",
"Chemist": "Chemist",
"ChemistInfo": "Mix Chemicals",
"ChemistInfoLong": "(Neutrals):\\nAs the Chemist, mix all sorts of chemicals to make overpowered gasses and items. Each room on the ship functions as a type of factory. In each factory, you can do some processes that take ingredients and get the results. Work your way to get these end products, which do the following:\\n- Sulfuric Acid: Mark someone with the kill button, and that player will spread the acid to all players they go nearby. After some time, all the acid players die.\\n- Methylamine Gas: Vent to blind everyone except you.\\n- Explosive: Gets put onto the next dead body you make. Everyone who tries to report it dies.\\n- Grenade: Put this onto someone via the kill button. They now carry the grenade. It blows up in seconds, killing that player and everyone nearby.",
"ChemistInfoLong": "(Neutrals):\\nAs the Chemist, mix all sorts of chemicals to make overpowered gasses and items. Each room on the ship functions as a type of factory. In each factory, you can do some processes that take ingredients and get the results. (You can vent to get some basic ingredients.) Work your way to get these end products, which do the following:\\n- Sulfuric Acid: Mark someone with the kill button, and that player will spread the acid to all players they go nearby. After some time, all the acid players die.\\n- Methylamine Gas: Vent to blind everyone except you.\\n- Explosive: Gets put onto the next dead body you make. Everyone who tries to report it dies.\\n- Grenade: Put this onto someone via the kill button. They now carry the grenade. It blows up in seconds, killing that player and everyone nearby.\\n\\nIf you have an end product ready to use through the kill button, single click to use it, double click to kill normally.",
"Chemist.Item.Air": "Air",
"Chemist.Item.BaseMineralOil": "Base Mineral Oil",
"Chemist.Item.Coal": "Coal",
+21 -25
View File
@@ -30,8 +30,6 @@ namespace EHR.Roles.Neutral
private static OptionItem GrenadeExplodeDelay;
private static OptionItem GrenadeExplodeRadius;
private static OverrideTasksData Tasks;
private static readonly Dictionary<Factory, Dictionary<string, (List<(int Count, Item Item)> Ingredients, List<(int Count, Item Item)> Results)>> Processes = new()
{
[Factory.None] = [],
@@ -157,7 +155,7 @@ namespace EHR.Roles.Neutral
.SetParent(CustomRoleSpawnChances[CustomRoles.Chemist])
.SetValueFormat(OptionFormat.Multiplier);
Tasks = OverrideTasksData.Create(++id, tab, CustomRoles.Chemist);
OverrideTasksData.Create(++id, tab, CustomRoles.Chemist);
return;
static int GetDefaultValue(Item item) => item switch
@@ -203,12 +201,7 @@ namespace EHR.Roles.Neutral
BombedBodies = [];
Grenades = [];
foreach (var item in EnumHelper.GetAllValues<Item>())
{
ItemCounts[item] = 0;
}
ItemCounts[Item.SulfuricAcid] = 30;
ItemCounts = EnumHelper.GetAllValues<Item>().ToDictionary(x => x, _ => 0);
if (!AmongUsClient.Instance.AmHost) return;
if (!Main.ResetCamPlayerList.Contains(playerId))
@@ -289,24 +282,27 @@ namespace EHR.Roles.Neutral
if (!base.OnCheckMurder(killer, target)) return false;
int need = FinalProductUsageAmounts[Item.SulfuricAcid].GetInt();
if (ItemCounts[Item.SulfuricAcid] >= need && !AcidPlayers.ContainsKey(target.PlayerId) && !AcidPlayers.Any(x => x.Value.OtherAcidPlayers.Contains(target.PlayerId)))
{
AcidPlayers[target.PlayerId] = ([], Utils.TimeStamp);
ItemCounts[Item.SulfuricAcid] -= need;
Utils.NotifyRoles(SpecifySeer: killer, SpecifyTarget: target);
return false;
}
int need2 = FinalProductUsageAmounts[Item.Grenade].GetInt();
if (ItemCounts[Item.Grenade] >= need2)
bool canUseAcid = ItemCounts[Item.SulfuricAcid] >= need && !AcidPlayers.ContainsKey(target.PlayerId) && !AcidPlayers.Any(x => x.Value.OtherAcidPlayers.Contains(target.PlayerId));
bool canUseGrenade = ItemCounts[Item.Grenade] >= need2;
if (!canUseAcid && !canUseGrenade) return true;
return killer.CheckDoubleTrigger(target, () =>
{
ItemCounts[Item.Grenade] -= need2;
Grenades[target.PlayerId] = Utils.TimeStamp;
Utils.NotifyRoles(SpecifySeer: killer, SpecifyTarget: target);
return false;
}
return true;
if (canUseAcid)
{
AcidPlayers[target.PlayerId] = ([], Utils.TimeStamp);
ItemCounts[Item.SulfuricAcid] -= need;
Utils.NotifyRoles(SpecifySeer: killer, SpecifyTarget: target);
}
else if (canUseGrenade)
{
ItemCounts[Item.Grenade] -= need2;
Grenades[target.PlayerId] = Utils.TimeStamp;
Utils.NotifyRoles(SpecifySeer: killer, SpecifyTarget: target);
}
});
}
public override void OnMurder(PlayerControl killer, PlayerControl target)
+1 -1
View File
@@ -43,8 +43,8 @@ namespace EHR.Roles.Neutral
];
public static ((Color32 Color, string String, PlayerControl Player) LastReportedPlayer, string LastPlayerPressedButtonName, SystemTypes LastSabotage, string LastReporterName, int NumPlayersVotedLastMeeting, string FirstReportedBodyPlayerName, int NumEmergencyMeetings, int NumPlayersDeadThisRound, int NumPlayersDeadFirstRound, int NumSabotages, int NumMeetings) Data = ((new(), string.Empty, null), string.Empty, default, string.Empty, 0, string.Empty, 0, 0, 0, 0, 0);
private Question CurrentQuestion;
public byte QuizMasterId;
public byte Target;