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

Develop 5.1.9 #1324

Merged
merged 37 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a2c1bb6
SendAllStreamedObjectsのパケットを分割
kou-hetare Jul 22, 2024
f4ecd48
パッチの位置を変更
kou-hetare Jul 22, 2024
8146a1a
SendAllStreamedObjectsパッチのMessageWriterを整理
kou-hetare Jul 29, 2024
b5b7238
WriteSpawnMessageのパケットサイズ削減
kou-hetare Jul 29, 2024
0644569
SendInitialDataPatchのGameManager周り標準実装に近づけた
kou-hetare Jul 29, 2024
947a7b5
clientId送信をPackedに修正
kou-hetare Jul 30, 2024
2d3d8fa
対策コード実行前にMessageバッファを送信しておく
kou-hetare Jul 30, 2024
0a26e5b
デバッグモードでパケットサイズをログに出すようにした
kou-hetare Jul 30, 2024
717d410
Merge branch 'develop' into fix/ReducePacketSize
kou-hetare Aug 14, 2024
c438165
送受信ログの整備
kou-hetare Aug 22, 2024
fd58711
パケットをある程度のサイズにまとめる形に変更
kou-hetare Aug 22, 2024
a0aa1bf
対策コードのオプション化
kou-hetare Sep 4, 2024
778e949
一部ログをデバッグモードのみに抑制
kou-hetare Sep 4, 2024
f070403
表示の変更
kou-hetare Sep 4, 2024
9a7bdec
SpawnPatchでもパケットの途中送信を実行
kou-hetare Sep 11, 2024
c82680d
Merge pull request #499 from tukasa0001/fix/ReducePacketSize
kou-hetare Sep 22, 2024
ba9316f
ログフォルダに保存するメソッド作成
kou-hetare Sep 27, 2024
aa35503
アプリ終了時にログを保存する設定の追加
kou-hetare Sep 27, 2024
a109f78
TOH設定にログフォルダを開くボタンを追加
kou-hetare Sep 28, 2024
aaf62c1
ログ出力時に出力ファイルを選択できるように変更
kou-hetare Sep 28, 2024
da28811
コピーしたログファイル名を返すように変更
kou-hetare Sep 28, 2024
8cfac5d
ログ出力もログフォルダに出力するよう変更
kou-hetare Sep 28, 2024
9e08765
オートログのフォルダを変更
kou-hetare Sep 28, 2024
0957bf0
OpenDirectoryの簡略化
kou-hetare Sep 28, 2024
ffa2c66
バージョンを5.1.9に変更
yurinakira Sep 29, 2024
aab5dcf
Merge pull request #506 from tukasa0001/feature/AutoSaveLogs
kou-hetare Sep 30, 2024
abef1ea
ログ出力時のメッセージの翻訳対応(英語,日本語)
yurinakira Oct 1, 2024
79b0b3f
9人以上で切断される問題のREADMEにアナウンス追加
yurinakira Oct 1, 2024
6a61635
ログフォルダを移動
kou-hetare Oct 1, 2024
e32fd06
ログフォルダを環境変数に登録
kou-hetare Oct 1, 2024
daa1c5f
保存先をAmongUsのデータフォルダに変更
kou-hetare Oct 1, 2024
87210e4
切断者が発生した時のみと強調した表現に変更
kou-hetare Oct 1, 2024
2f1bc61
ログ機能の変更について記載
kou-hetare Oct 1, 2024
2d0e156
Merge pull request #509 from tukasa0001/feature/log_message
yurinakira Oct 3, 2024
e8b4929
Merge pull request #511 from tukasa0001/fix/MoveLogFolder
kou-hetare Oct 3, 2024
00c1775
Merge pull request #510 from tukasa0001/doc/Readme5.1.9
yurinakira Oct 4, 2024
4d66e6c
Merge pull request #508 from tukasa0001/verUp/5.1.9
yurinakira Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Modules/OptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ public static CustomGameMode CurrentGameMode
public static OptionItem KickPlayerFriendCodeNotExist;
public static OptionItem ApplyBanList;

public static OptionItem FixSpawnPacketSize;

public static readonly string[] suffixModes =
{
"SuffixMode.None",
Expand Down Expand Up @@ -366,7 +368,10 @@ public static void Load()
{
if (IsLoaded) return;
OptionSaver.Initialize();

//9人以上部屋で落ちる現象の対策
FixSpawnPacketSize = BooleanOptionItem.Create(1_000_200, "FixSpawnPacketSize", false, TabGroup.MainSettings, true)
.SetColor(new Color32(255, 255, 0, 255))
.SetGameMode(CustomGameMode.All);
// プリセット
_ = PresetOptionItem.Create(0, TabGroup.MainSettings)
.SetColor(new Color32(204, 204, 0, 255))
Expand Down
2 changes: 2 additions & 0 deletions Modules/SystemEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public static void SetEnvironmentVariables()
{
// ユーザ環境変数に最近開かれたTOHアモアスフォルダのパスを設定
Environment.SetEnvironmentVariable("TOWN_OF_HOST_DIR_ROOT", Environment.CurrentDirectory, EnvironmentVariableTarget.User);
// ユーザ環境変数にログフォルダのパスを設定
Environment.SetEnvironmentVariable("TOWN_OF_HOST_DIR_LOGS", Utils.GetLogFolder().FullName, EnvironmentVariableTarget.User);
}
}
43 changes: 33 additions & 10 deletions Modules/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,23 +1044,46 @@ public static string PadRightV2(this object text, int num)
foreach (char c in t) bc += Encoding.GetEncoding("UTF-8").GetByteCount(c.ToString()) == 1 ? 1 : 2;
return t?.PadRight(Mathf.Max(num - (bc - t.Length), 0));
}
public static DirectoryInfo GetLogFolder(bool auto = false)
{
var folder = Directory.CreateDirectory($"{Application.persistentDataPath}/TownOfHost/Logs");
if (auto)
{
folder = Directory.CreateDirectory($"{folder.FullName}/AutoLogs");
}
return folder;
}
public static void DumpLog()
{
var logs = GetLogFolder();
var filename = CopyLog(logs.FullName);
OpenDirectory(filename);
if (PlayerControl.LocalPlayer != null)
HudManager.Instance?.Chat?.AddChat(PlayerControl.LocalPlayer, Translator.GetString("Message.LogsSavedInLogsFolder"));
}
public static void SaveNowLog()
{
var logs = GetLogFolder(true);
// 7日以上前のログを削除
logs.EnumerateFiles().Where(f => f.CreationTime < DateTime.Now.AddDays(-7)).ToList().ForEach(f => f.Delete());
CopyLog(logs.FullName);
}
public static string CopyLog(string path)
{
string t = DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss");
string fileName = $"{Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)}/TownOfHost-v{Main.PluginVersion}-{t}.log";
string fileName = $"{path}/TownOfHost-v{Main.PluginVersion}-{t}.log";
FileInfo file = new(@$"{Environment.CurrentDirectory}/BepInEx/LogOutput.log");
file.CopyTo(fileName);
OpenDirectory(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
if (PlayerControl.LocalPlayer != null)
HudManager.Instance?.Chat?.AddChat(PlayerControl.LocalPlayer, "デスクトップにログを保存しました。バグ報告チケットを作成してこのファイルを添付してください。");
var logFile = file.CopyTo(fileName);
return logFile.FullName;
}
public static void OpenLogFolder()
{
var logs = GetLogFolder(true);
OpenDirectory(logs.FullName);
}
public static void OpenDirectory(string path)
{
var startInfo = new ProcessStartInfo(path)
{
UseShellExecute = true,
};
Process.Start(startInfo);
Process.Start("Explorer.exe", $"/select,{path}");
}
public static string SummaryTexts(byte id, bool isForChat)
{
Expand Down
5 changes: 5 additions & 0 deletions Patches/ClientOptionsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class OptionsMenuBehaviourStartPatch
private static ClientActionItem JapaneseRoleName;
private static ClientActionItem UnloadMod;
private static ClientActionItem DumpLog;
private static ClientActionItem OpenLogFolder;

public static void Postfix(OptionsMenuBehaviour __instance)
{
Expand All @@ -35,6 +36,10 @@ public static void Postfix(OptionsMenuBehaviour __instance)
{
DumpLog = ClientActionItem.Create("DumpLog", Utils.DumpLog, __instance);
}
if (OpenLogFolder == null || OpenLogFolder.ToggleButton == null)
{
OpenLogFolder = ClientActionItem.Create("OpenLogFolder", Utils.OpenLogFolder, __instance);
}

if (ModUnloaderScreen.Popup == null)
{
Expand Down
181 changes: 179 additions & 2 deletions Patches/ClientPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEngine;
using TownOfHost.Modules;
using static TownOfHost.Translator;
using Hazel;

namespace TownOfHost
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public static void Postfix(MMOnlineManager __instance)
{
message = GetString("UnsupportedVersion");
}
else if(!Main.IsPublicAvailableOnThisVersion)
else if (!Main.IsPublicAvailableOnThisVersion)
{
message = GetString("PublicNotAvailableOnThisVersion");
}
Expand Down Expand Up @@ -126,10 +127,186 @@ public static void Prefix(InnerNet.InnerNetClient __instance, int clientId, bool
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SendAllStreamedObjects))]
class InnerNetObjectSerializePatch
{
public static void Prefix()
public static bool Prefix(InnerNetClient __instance, ref bool __result)
{
if (AmongUsClient.Instance.AmHost)
GameOptionsSender.SendAllGameOptions();

//9人以上部屋で落ちる現象の対策コード
if (!Options.FixSpawnPacketSize.GetBool()) return true;

var sended = false;
__result = false;
var obj = __instance.allObjects;
lock (obj)
{
for (int i = 0; i < __instance.allObjects.Count; i++)
{
InnerNetObject innerNetObject = __instance.allObjects[i];
if (innerNetObject && innerNetObject.IsDirty && (innerNetObject.AmOwner ||
(innerNetObject.OwnerId == -2 && __instance.AmHost)))
{
var messageWriter = __instance.Streams[(byte)innerNetObject.sendMode];
if (messageWriter.Length > 500)
{
if (!sended)
{
if (DebugModeManager.IsDebugMode)
{
Logger.Info($"SendAllStreamedObjects: Start", "InnerNetClient");
}
sended = true;
}
messageWriter.EndMessage();
__instance.SendOrDisconnect(messageWriter);
messageWriter.Clear(innerNetObject.sendMode);
messageWriter.StartMessage(5);
messageWriter.Write(__instance.GameId);
}
messageWriter.StartMessage(1);
messageWriter.WritePacked(innerNetObject.NetId);
try
{
if (innerNetObject.Serialize(messageWriter, false))
{
messageWriter.EndMessage();
}
else
{
messageWriter.CancelMessage();
}
if (innerNetObject.Chunked && innerNetObject.IsDirty)
{
Logger.Info($"SendAllStreamedObjects: Chunked", "InnerNetClient");
__result = true;
}
}
catch (System.Exception ex)
{
Logger.Info($"Exception:{ex.Message}", "InnerNetClient");
messageWriter.CancelMessage();
}
}
}
}
for (int j = 0; j < __instance.Streams.Length; j++)
{
MessageWriter messageWriter2 = __instance.Streams[j];
if (messageWriter2.HasBytes(7))
{
if (!sended)
{
if (DebugModeManager.IsDebugMode)
{
Logger.Info($"SendAllStreamedObjects: Start", "InnerNetClient");
}
sended = true;
}
messageWriter2.EndMessage();
__instance.SendOrDisconnect(messageWriter2);
messageWriter2.Clear((SendOption)j);
messageWriter2.StartMessage(5);
messageWriter2.Write(__instance.GameId);
}
}
if (DebugModeManager.IsDebugMode && sended) Logger.Info($"SendAllStreamedObjects: End", "InnerNetClient");
return false;
}
}
[HarmonyPatch]
class InnerNetClientPatch
{
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.HandleMessage)), HarmonyPrefix]
public static bool HandleMessagePatch(InnerNetClient __instance, MessageReader reader, SendOption sendOption)
{
if (DebugModeManager.IsDebugMode)
{
Logger.Info($"HandleMessagePatch:Packet({reader.Length}) ,SendOption:{sendOption}", "InnerNetClient");
}
else if (reader.Length > 1000)
{
Logger.Info($"HandleMessagePatch:Large Packet({reader.Length})", "InnerNetClient");
}
return true;
}
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SendOrDisconnect)), HarmonyPrefix]
public static void SendOrDisconnectPatch(InnerNetClient __instance, MessageWriter msg)
{
if (DebugModeManager.IsDebugMode)
{
Logger.Info($"SendOrDisconnectPatch:Packet({msg.Length}) ,SendOption:{msg.SendOption}", "InnerNetClient");
}
else if (msg.Length > 1000)
{
Logger.Info($"SendOrDisconnectPatch:Large Packet({msg.Length})", "InnerNetClient");
}
}
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SendInitialData)), HarmonyPrefix]
public static bool SendInitialDataPatch(InnerNetClient __instance, int clientId)
{
if (!Options.FixSpawnPacketSize.GetBool()) return true;
if (DebugModeManager.IsDebugMode)
{
Logger.Info($"SendInitialData: Start", "InnerNetClient");
}
MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable);
messageWriter.StartMessage(6);
messageWriter.Write(__instance.GameId);
messageWriter.WritePacked(clientId);

var obj = __instance.allObjects;
lock (obj)
{
var hashSet = new System.Collections.Generic.HashSet<GameObject>();
//まずはGameManagerを送信
GameManager gameManager = GameManager.Instance;
__instance.SendGameManager(clientId, gameManager);
hashSet.Add(gameManager.gameObject);

for (int i = 0; i < __instance.allObjects.Count; i++)
{
InnerNetObject innerNetObject = __instance.allObjects[i];
if (innerNetObject && (innerNetObject.OwnerId != -4 || __instance.AmModdedHost) && hashSet.Add(innerNetObject.gameObject))
{
if (messageWriter.Length > 500)
{
messageWriter.EndMessage();
__instance.SendOrDisconnect(messageWriter);
messageWriter.Clear(SendOption.Reliable);
messageWriter.StartMessage(6);
messageWriter.Write(__instance.GameId);
messageWriter.WritePacked(clientId);

}
__instance.WriteSpawnMessage(innerNetObject, innerNetObject.OwnerId, innerNetObject.SpawnFlags, messageWriter);
}
}
}
messageWriter.EndMessage();
__instance.SendOrDisconnect(messageWriter);
messageWriter.Recycle();
if (DebugModeManager.IsDebugMode)
{
Logger.Info($"SendInitialData: End", "InnerNetClient");
}
return false;
}
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.Spawn)), HarmonyPostfix]
public static void SpawnPatch(InnerNetClient __instance, InnerNetObject netObjParent, int ownerId, SpawnFlags flags)
{
if (DebugModeManager.IsDebugMode)
{
Logger.Info($"SpawnPatch", "InnerNetClient");
}
var messageWriter = __instance.Streams[(byte)SendOption.Reliable];
if (messageWriter.Length > 500)
{
messageWriter.EndMessage();
__instance.SendOrDisconnect(messageWriter);
messageWriter.Clear(SendOption.Reliable);
messageWriter.StartMessage(5);
messageWriter.Write(__instance.GameId);
}
}
}
}
5 changes: 4 additions & 1 deletion README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Note that if a player other than the host plays with this mod installed, the fol
- Sheriff, Arsonist, Jackal, and other roles can close doors, but please don't use it because the system can't limit it.
- The dead player chat can be seen when exile screen by anti blackout, but this is not a bug.
- The "Confirm Ejects" option will not work if any of the following roles are enabled: Sheriff, Arsonist, Jackal, PlagueDoctor.
- When more than about 9 players join a lobby, sometimes particular players may get disconnected.To address this issue, we have added an optional countermeasure function on a trial basis. <b>Please Turn ON only when disconnections occurs. </b>
- The folder for log output has been changed. To see where they are saved, select Open Log Folder from the TOH settings screen.
- Successful completion is now automatically saved in the log folder.

## Features
### Hotkeys
Expand All @@ -61,7 +64,7 @@ Note that if a player other than the host plays with this mod installed, the fol
| HotKey | Function | Usable Scene |
| ----------- | ---------------------------------------------------------------------------------- | ------------- |
| `Tab` | Option list page feed | Lobby |
| `Ctrl`+`F1` | Output log to desktop | Anywhere |
| `Ctrl`+`F1` | Output log to Log Folder | Anywhere |
| `F10` | Open AmongUs folder | Anywhere |
| `F11` | Change resolution<br>480x270 → 640x360 → 800x450 → 1280x720 → 1600x900 → 1920x1080 | Anywhere |
| `T`+`F5` | Reload custom translation file | Anywhere |
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ AmongUsバージョン : **2024.8.13**
- シェリフ、アーソニスト、ジャッカル等の役職がドア閉めを行えますが、システムで制限することができないため使わないようお願いします。
- 暗転対策関係で追放画面で死人がチャットをすると見えますが、バグではありません。
- シェリフ、アーソニスト、ジャッカル、ペスト医師のいずれかが有効な場合、バニラの「追放を確認」オプションが正常に動作しません。
- 参加人数が9人程度を上回った場合に特定の人が切断される問題の対策として、試験的に対策機能のオプションを追加しています。 <B>切断者が発生する場合のみONにしてください。</b>
- ログ出力するフォルダを変更しました。保存先を確認するにはTOHの設定画面からログフォルダを開くを選択してください。
- 正常に終了した場合、ログフォルダに自動保存されるようになりました。

## 機能
### ホットキー
Expand All @@ -61,7 +64,7 @@ AmongUsバージョン : **2024.8.13**
| キー | 機能 | 使えるシーン |
| ----------- | ----------------------------------------------------------------------------- | --------------- |
| `Tab` | オプション一覧のページ送り | ロビー |
| `Ctrl`+`F1` | ログをデスクトップに出力 | どこでも |
| `Ctrl`+`F1` | ログをログフォルダに出力 | どこでも |
| `F10` | AmongUsのフォルダを開く | どこでも |
| `F11` | 解像度を変更<br>480x270 → 640x360 → 800x450 → 1280x720 → 1600x900 → 1920x1080 | どこでも |
| `T`+`F5` | カスタム翻訳ファイルのリロード | どこでも |
Expand Down
Loading