Skip to content

Commit

Permalink
Merge pull request #1324 from tukasa0001/develop-5.1.9
Browse files Browse the repository at this point in the history
Develop 5.1.9
  • Loading branch information
yurinakira authored Oct 5, 2024
2 parents 4a2b76a + 4d66e6c commit 5a3f869
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 16 deletions.
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

0 comments on commit 5a3f869

Please sign in to comment.