fix(plugin): restore battle recovery, costume setup and friend presence

Preserve supporter state and 64-bit costume indices; recover battle preparation and replay pending introductions.
Show localized green online indicators in friend lists and route virtual-square realtime traffic.
Handle capture-thread shutdown and retain actionable client error diagnostics.
This commit is contained in:
Flechazo committed 2026-10-24 01:22:50 +08:00
1 parent 91a5e1fb26
commit 238609bdb2
18 files changed
+360 -10

No files matched your search

@@ -157,6 +157,14 @@ internal static class CaptureWriter
}
}
}
catch (ThreadAbortException ex)
{
// Mono aborts background threads when the domain unloads at exit;
// every written record is already flushed, so only queued ones are lost.
int pending = WriteQueue.Count;
if (pending != 0)
MarkIncomplete("capture writer was aborted with " + pending + " queued records", ex);
}
catch (Exception ex)
{
MarkIncomplete("capture writer failed to initialize or finalize", ex);
+2 -1
View File
@@ -56,5 +56,6 @@
"fchat.help.target": "Describe the target language in natural language, for example “Simplified Chinese”, “British English” or “Japanese”. Leave this field empty to use your current game UI language. The AI interprets your description when translating.",
"fchat.help.blacklist": "Enter language names or descriptions in natural language, separated by commas, for example “English, Japanese”. Leave empty to allow all languages. The AI must identify the actual language of each message. This cannot be reliably determined locally, so message content may still be sent to your configured AI API even when translation is skipped. Language identification may consume additional tokens and incur charges. Set your API budget accordingly.",
"fchat.error.target_invalid": "Target language must be a single line of at most 200 characters.",
"fchat.error.blacklist_invalid": "Language blacklist must be a single line of at most 2,000 characters."
"fchat.error.blacklist_invalid": "Language blacklist must be a single line of at most 2,000 characters.",
"fchat.friend.online": "Online"
}
+2 -1
View File
@@ -56,5 +56,6 @@
"fchat.help.target": "「簡体字中国語」「イギリス英語」「日本語」など、翻訳先の言語を自然な言葉で指定してください。空欄の場合は現在のゲームの表示言語を使います。AI が入力した説明を解釈して翻訳します。",
"fchat.help.blacklist": "翻訳しない言語の名前や説明を自然な言葉で入力し、複数ある場合は「英語, 日本語」のようにカンマで区切ってください。空欄の場合はすべての言語を許可します。各メッセージの実際の言語を AI が識別する必要があります。端末だけでは確実に判定できないため、翻訳を省略する場合もメッセージが設定した AI API に送信されることがあります。言語の識別で追加のトークンや料金が発生する場合があります。API の予算を適切に設定してください。",
"fchat.error.target_invalid": "翻訳先の言語は 200 文字以内の 1 行で入力してください。",
"fchat.error.blacklist_invalid": "翻訳しない言語は 2000 文字以内の 1 行で入力してください。"
"fchat.error.blacklist_invalid": "翻訳しない言語は 2000 文字以内の 1 行で入力してください。",
"fchat.friend.online": "オンライン"
}
+2 -1
View File
@@ -56,5 +56,6 @@
"fchat.help.target": "“간체 중국어”, “영국 영어”, “일본어”처럼 번역할 대상 언어를 자연어로 입력하세요. 비워 두면 현재 게임 표시 언어를 사용합니다. AI가 입력한 설명을 해석하여 번역합니다.",
"fchat.help.blacklist": "번역하지 않을 언어의 이름이나 설명을 자연어로 입력하세요. 여러 언어는 “영어, 일본어”처럼 쉼표로 구분하세요. 비워 두면 모든 언어를 허용합니다. AI가 각 메시지의 실제 언어를 식별해야 합니다. 기기에서만 이를 정확하게 판단할 수 없으므로 번역을 건너뛰더라도 메시지 내용이 설정한 AI API로 전송될 수 있습니다. 언어 식별에 추가 토큰이 소모되고 요금이 발생할 수 있으니 API 예산을 적절히 설정하세요.",
"fchat.error.target_invalid": "번역 대상 언어는 200자 이내의 한 줄로 입력하세요.",
"fchat.error.blacklist_invalid": "번역 제외 언어는 2000자 이내의 한 줄로 입력하세요."
"fchat.error.blacklist_invalid": "번역 제외 언어는 2000자 이내의 한 줄로 입력하세요.",
"fchat.friend.online": "온라인"
}
+2 -1
View File
@@ -56,5 +56,6 @@
"fchat.help.target": "用自然语言描述希望翻译成的语言,例如“简体中文”“英式英语”或“日语”。留空时使用你当前的游戏界面语言。AI 会根据你的描述理解目标语言并翻译。",
"fchat.help.blacklist": "用自然语言填写不需要翻译的语言名称或描述,多个语言用逗号分隔,例如“英语, 日语”。留空表示不限制语言。AI 需要识别每条消息的实际语言,本地无法可靠判断,因此即使最终跳过翻译,消息内容仍可能发送至你配置的 AI 接口。语言识别可能额外消耗 Token 并产生费用,请合理设置 API 预算。",
"fchat.error.target_invalid": "目标语言需为单行文本,最多 200 个字符。",
"fchat.error.blacklist_invalid": "语言黑名单需为单行文本,最多 2000 个字符。"
"fchat.error.blacklist_invalid": "语言黑名单需为单行文本,最多 2000 个字符。",
"fchat.friend.online": "在线"
}
+2 -1
View File
@@ -56,5 +56,6 @@
"fchat.help.target": "用自然語言描述希望翻譯成的語言,例如「繁體中文」「英式英語」或「日語」。留空時使用你目前的遊戲介面語言。AI 會根據你的描述理解目標語言並翻譯。",
"fchat.help.blacklist": "用自然語言填寫不需要翻譯的語言名稱或描述,多個語言用逗號分隔,例如「英語, 日語」。留空表示不限制語言。AI 需要辨識每則訊息的實際語言,本機無法可靠判斷,因此即使最終跳過翻譯,訊息內容仍可能傳送至你設定的 AI 介面。語言辨識可能額外消耗 Token 並產生費用,請合理設定 API 預算。",
"fchat.error.target_invalid": "目標語言須為單行文字,最多 200 個字元。",
"fchat.error.blacklist_invalid": "語言黑名單須為單行文字,最多 2000 個字元。"
"fchat.error.blacklist_invalid": "語言黑名單須為單行文字,最多 2000 個字元。",
"fchat.friend.online": "線上"
}
+37
View File
@@ -0,0 +1,37 @@
using System;
using System.Reflection;
using BD2.GameNames;
using HarmonyLib;
using gamfs;
using TMPro;
using TextComponent = BD2.GameSdk.Component;
namespace Bd2FChat;
internal static class FriendPresence
{
private static FieldInfo friendInfo;
private static FieldInfo introduction;
internal static void Install(Harmony harmony)
{
const BindingFlags fields = BindingFlags.Instance | BindingFlags.NonPublic;
friendInfo = typeof(FriendItem).GetGameField("_friendInfoData", fields)
?? throw new MissingFieldException(nameof(FriendItem), "_friendInfoData");
introduction = typeof(FriendItem).GetGameField("_textIntroduction", fields)
?? throw new MissingFieldException(nameof(FriendItem), "_textIntroduction");
MethodInfo refresh = typeof(FriendItem).GetGameMethod("RefreshLoginUI", fields)
?? throw new MissingMethodException(nameof(FriendItem), "RefreshLoginUI");
harmony.Patch(refresh, prefix: new HarmonyMethod(typeof(FriendPresence), nameof(RefreshLoginPrefix)));
}
private static bool RefreshLoginPrefix(FriendItem __instance)
{
if (friendInfo.GetValue(__instance) is not FriendPacket.FriendInfoData info) return true;
var label = introduction.GetValue(__instance) as TMP_Text;
if (label == null || SG.Time.UnixTimeStampToDateTime(info.LastLoginDate) <= SG.Time.Now()) return true;
label.richText = true;
label.text = "<color=#63D189>● " + TextComponent.Translatable("fchat.friend.online").GetString() + "</color>";
return false;
}
}
+1
View File
@@ -27,6 +27,7 @@ public sealed class Plugin : BaseUnityPlugin
NativeChatTranslation.Install(harmony);
TranslationSettingsUI.Install(harmony);
ServerTextPolicy.Install(harmony, Logger);
FriendPresence.Install(harmony);
Logger.LogInfo("Client chat translation and server text policy installed");
}
catch (Exception error)
+43 -1
View File
@@ -26,7 +26,34 @@ internal static class BattleCheckpoint
MethodInfo send = typeof(BDNetwork.NetworkManager).GetMethods(All)
.Single(method => method.IsGameMethod("Send") && method.GetParameters().Length == 6 && method.GetParameters()[0].ParameterType == typeof(IMessage));
harmony.Patch(send, prefix: new HarmonyMethod(typeof(BattleCheckpoint), nameof(BeforeSend)));
harmony.Patch(typeof(ResumeBattleData).GetGameMethod("SetData", All),
prefix: new HarmonyMethod(typeof(BattleCheckpoint), nameof(BeforeResume)),
postfix: new HarmonyMethod(typeof(BattleCheckpoint), nameof(AfterResume)));
}
private static void BeforeResume(BattleResumeResponse __0, out int __state)
{
__state = __0.SupporterInfo.Count > 0 && __0.SupporterCharInfo.Count > 0
? __0.SupporterCharInfo[0].CharInfo?.SupporterSlotIndex ?? 0 : 0;
}
private static void AfterResume(BattleResumeResponse __0, int __state)
{
if (__state == 0 || __0.ModeInfo?.BattleMode == Define_BattleModeType.GuildRaidBoss) return;
CharDBInfo character = __0.SupporterCharInfo[0].CharInfo;
character.SupporterSlotIndex = __state;
(long, int, int) originalKey = (character.SupporterOwnerIndex, 0, (int)character.SupporterBorrowOwnerType);
(long, int, int) restoredKey = (character.SupporterOwnerIndex, __state, (int)character.SupporterBorrowOwnerType);
Dictionary<(long, int, int), SupporterBattleCharInfoEx> supporters = BattlePacket.DeckSupporterCharInfoDict;
if (supporters.TryGetValue(originalKey, out SupporterBattleCharInfoEx inserted)
&& ReferenceEquals(inserted.SupporterBattleCharInfo, __0.SupporterCharInfo[0]))
supporters.Remove(originalKey);
supporters[restoredKey] = new SupporterBattleCharInfoEx
{
SupporterBattleCharInfo = __0.SupporterCharInfo[0],
usageCount = __0.SupporterInfo[0].UsageCount,
userName = __0.SupporterInfo[0].UserId
};
}
private static void BeforeSend(IMessage __0)
@@ -95,6 +122,8 @@ internal static class BattleCheckpoint
RedTeamSkillBubbleCount = manager.GetPlayData(ETeamType.TT_RED).SkillBubbleCount,
MonsterHuntTeam = manager.MonsterHuntTeam,
CumulativeSummonCount = processor.CumulativeSummonCount,
ArmorBreakCount = processor.ArmorBreakCount,
CanIncreaseArmorBreak = processor.CanIncreaseArmorBreak,
BattleResult = Convert.ToBase64String(result.ToByteArray()),
EngineType = (Define_BattleEngineType)1,
ContinueRedTeamSkillBubbleCount = manager.ContinueEnemySkillBubblePoint,
@@ -171,7 +200,20 @@ internal static class BattleCheckpoint
FieldInfo season = typeof(GuildRaidPacket.GuildRaidMainInfo).GetGameField("season", All);
checkpoint.Season = (int)season.GetValue(GuildRaidPacket.MainInfo);
}
if (manager.BorrowedSupporterDeckInfo != null) checkpoint.SupporterInfo.Add(manager.BorrowedSupporterDeckInfo.Clone());
if (manager.BorrowedSupporterDeckInfo != null)
{
checkpoint.SupporterInfo.Add(manager.BorrowedSupporterDeckInfo.Clone());
foreach (BattleCharData character in manager.GetTeamBattleCharSequenceList(ETeamType.TT_BLUE))
{
if (!character.IsBorrowedSupporter) continue;
SupporterBattleCharInfoEx supporter = BattlePacket.GetSupporterBattleCharInfoEx(character.CharDBInfo.SupporterOwnerIndex,
character.CharDBInfo.SupporterSlotIndex, character.CharDBInfo.SupporterBorrowOwnerType);
if (supporter?.SupporterBattleCharInfo == null) continue;
GuildSupporterBattleCharInfo bundle = supporter.SupporterBattleCharInfo.Clone();
if (bundle.CharInfo != null) bundle.CharInfo.SupporterSlotIndex = character.CharDBInfo.SupporterSlotIndex;
checkpoint.SupporterCharInfo.Add(bundle);
}
}
checkpoint.CanRequestFriend = manager.CanRequestFriend;
var recommendation = new RecommendDeckInfoRequest { BattleMode = (int)battleMode, PackId = Singleton<PackManager>.Instance.PlayingPackID, BattleIndex = manager.CurrentBattleDeckInfo?.Id ?? 0 };
var packType = (Define_PackType)Singleton<PackManager>.Instance.EnterPackDTO.PackType;
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using BD2.GameNames;
using BDNetwork;
using BepInEx.Logging;
using HarmonyLib;
using Proto.Net;
namespace Bd2LocalIdentity;
internal static class BattleFormationDiagnostics
{
private static readonly FieldInfo BattleUI = typeof(BattleGridTouchManager).GetGameField("_battleUI", BindingFlags.Instance | BindingFlags.NonPublic);
private static ManualLogSource Log;
private static bool MissingGridReported;
internal static void Install(Harmony harmony, ManualLogSource logger)
{
if (BattleUI == null) throw new MissingFieldException(typeof(BattleGridTouchManager).FullName, "_battleUI");
Log = logger;
harmony.Patch(Game.Method(() => CommonPacket.RecvDeckCharAutoReviveResponse(null, 0, 0)),
postfix: new HarmonyMethod(typeof(BattleFormationDiagnostics), nameof(RecoveryApplied)));
harmony.Patch(Game.Method<BattlePlayManager>(battle => battle.InitBattle(default, default)),
prefix: new HarmonyMethod(typeof(BattleFormationDiagnostics), nameof(Reset)));
harmony.Patch(Game.Method<BattlePlayData>(data => data.SetPlayData(0, null, false, true)),
prefix: new HarmonyMethod(typeof(BattleFormationDiagnostics), nameof(BeforeSet)),
postfix: new HarmonyMethod(typeof(BattleFormationDiagnostics), nameof(AfterSet)));
harmony.Patch(Game.Method<BattleGridTouchManager>(touch => touch.OnTouchBegan(null)),
prefix: new HarmonyMethod(typeof(BattleFormationDiagnostics), nameof(TouchBegan)));
}
private static void Reset() => MissingGridReported = false;
private static void RecoveryApplied(byte[] __0, int __2, bool __result)
{
if (!ClientRouting.IsActive || __2 != 0 || !__result) return;
DeckCharAutoReviveResponse response = DeckCharAutoReviveResponse.Parser.ParseFrom(__0);
Log.LogInfo("Battle formation recovery applied: type=" + response.AutoReviveCharType + " deck=" + DeckHealth());
}
private static void BeforeSet(BattlePlayData __instance, int __0, out string __state)
{
__state = null;
if (!ClientRouting.IsActive || __instance.TeamType != ETeamType.TT_BLUE) return;
BattlePlayManager battle = BattlePlayManager.Instance;
__state = "mode=" + battle?.BattleMode + " engine_v2=" + battle?.BattleProcessor?.IsActiveBattleMachine +
" expected_grid=" + __0 + " before_count=" + __instance.BattleCharDataList?.Count + " deck=" + DeckHealth();
}
private static void AfterSet(BattlePlayData __instance, string __state)
{
if (__state == null) return;
Log.LogInfo("Battle formation initialized: " + __state + " after_count=" + __instance.BattleCharDataList?.Count);
}
private static void TouchBegan(BattleGridTouchManager __instance, BattleGridTouchData __0)
{
if (!ClientRouting.IsActive || MissingGridReported || __0 == null || __0.DragBattleCharData != null) return;
BattlePlayManager battle = BattlePlayManager.Instance;
var ui = BattleUI.GetValue(__instance) as BattleUIBase;
if (battle == null || !battle.IsBattleReadyState || ui == null || !ui.IsActive || !ui.CanTouchUICondition()) return;
List<BattleCharData> team = battle.GetTeamBattleCharList(__0.TeamType);
if (team != null && __0.GridIndex >= 0 && __0.GridIndex < team.Count && team[__0.GridIndex] != null) return;
MissingGridReported = true;
Log.LogWarning("Battle formation touch has no grid data: team=" + __0.TeamType + " grid=" + __0.GridIndex +
" count=" + (team == null ? "null" : team.Count.ToString(System.Globalization.CultureInfo.InvariantCulture)) +
" state=" + battle.CurrentBattleState + " mode=" + battle.BattleMode +
" engine_v2=" + battle.BattleProcessor?.IsActiveBattleMachine + " deck=" + DeckHealth());
}
private static string DeckHealth()
{
var text = new StringBuilder();
if (CommonPacket.DeckInfoList == null) return "null";
foreach (DeckDBInfo entry in CommonPacket.DeckInfoList)
{
if (text.Length != 0) text.Append(',');
if (entry == null)
{
text.Append("null");
continue;
}
CharDBInfo character = CommonPacket.GetCharInfo(entry.CharInvenIndex);
text.Append(entry.CharInvenIndex).Append('@').Append(entry.Position).Append(':');
if (character == null) text.Append("missing");
else text.Append(character.Hp);
}
return text.ToString();
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using BD2.GameNames;
using HarmonyLib;
using Proto.Net;
namespace Bd2LocalIdentity;
internal static class BattlePreparation
{
private static readonly FieldInfo RetryDeck = typeof(BattlePlayManager).GetGameField("_retryDeckInfoList", BindingFlags.Instance | BindingFlags.NonPublic);
internal static void Install(Harmony harmony)
{
if (RetryDeck == null) throw new MissingFieldException(typeof(BattlePlayManager).FullName, "_retryDeckInfoList");
harmony.Patch(Game.Method<BattlePlayManager>(battle => battle.Retry()),
prefix: new HarmonyMethod(typeof(BattlePreparation), nameof(BeforeRetry)));
}
private static void BeforeRetry(BattlePlayManager __instance)
{
if (!ClientRouting.IsActive || !__instance.IsSupportContent() || __instance.GetBattleTurn() != 1 || __instance.IsCompleteBattleStart) return;
var retry = (List<DeckDBInfo>)RetryDeck.GetValue(__instance);
// A rejected supporter borrow can retry before BattleStart creates the native snapshot.
retry.Clear();
foreach (DeckDBInfo entry in __instance.GetDeckInfoList(false, false))
retry.Add(entry.Clone());
}
}
+1 -1
View File
@@ -26,7 +26,7 @@ internal sealed class ClientRouting : IDisposable
MethodInfo makeCDNInfo = Game.Method(() => BDNetwork.CommonPacket.MakeCDNInfo(null));
if (load == null || sendMaintenance == null || makeCDNInfo == null)
{
throw new MissingMethodException("2.36.7 server/resource routing methods were not found");
throw new MissingMethodException("2.37.13 server/resource routing methods were not found");
}
harmony.Patch(load, postfix: new HarmonyMethod(typeof(ClientRouting), nameof(ApplyServerOriginHook)));
harmony.Patch(sendMaintenance, prefix: new HarmonyMethod(typeof(ClientRouting), nameof(ApplyServerOriginHook)));
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using BD2.GameNames;
using BepInEx.Logging;
using HarmonyLib;
using Proto.Net;
namespace Bd2LocalIdentity;
internal static class CostumeAutoMount
{
internal static void Install(Harmony harmony, ManualLogSource logger)
{
Type closure = Game.FindType("AutoMountManager+<>c__DisplayClass24_0");
MethodInfo apply = closure?.GetGameMethod("<ProcessCostumeAppliedOptions>g__AfterCostumeUseBatchRequest|1",
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
?? throw new MissingMethodException("Costume auto-mount batch method is unavailable");
harmony.Patch(apply, transpiler: new HarmonyMethod(typeof(CostumeAutoMount), nameof(PreserveInstanceIndices)));
logger.LogInfo("Costume auto-mount preserves 64-bit character and costume indices");
}
private static List<CodeInstruction> PreserveInstanceIndices(IEnumerable<CodeInstruction> instructions)
{
var code = instructions.ToList();
MethodInfo character = typeof(FieldDeckDBInfo).GetProperty(nameof(FieldDeckDBInfo.CharInvenIndex))?.SetMethod;
MethodInfo costume = typeof(FieldDeckDBInfo).GetProperty(nameof(FieldDeckDBInfo.CostumeInvenIndex))?.SetMethod;
int repaired = 0;
for (int i = 1; i + 2 < code.Count; i++)
{
if (code[i - 1].opcode != OpCodes.Ldfld || code[i - 1].operand is not FieldInfo { FieldType: var fieldType } ||
fieldType != typeof(long) || code[i].opcode != OpCodes.Conv_I4 || code[i + 1].opcode != OpCodes.Conv_I8 ||
code[i + 2].operand is not MethodInfo setter || setter != character && setter != costume) continue;
// Native auto-mount narrows these two long indices before assigning the long protocol fields.
code[i].opcode = OpCodes.Nop;
code[i + 1].opcode = OpCodes.Nop;
repaired++;
}
if (repaired != 2) throw new InvalidOperationException("Costume auto-mount index conversions differ from the supported client");
return code;
}
}
@@ -0,0 +1,45 @@
using System;
using System.Reflection;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
namespace Bd2LocalIdentity;
internal static class DebuggerErrorNotification
{
internal static void Install(Harmony harmony, ManualLogSource logger)
{
Type notifier = AccessTools.TypeByName("SRDebugger.UI.Other.ErrorNotifier");
MethodInfo show = notifier?.GetMethod(
"ShowErrorWarning", BindingFlags.Instance | BindingFlags.Public,
null, Type.EmptyTypes, null);
MethodInfo awake = notifier?.GetMethod(
"Awake", BindingFlags.Instance | BindingFlags.NonPublic,
null, Type.EmptyTypes, null);
if (notifier == null || !typeof(MonoBehaviour).IsAssignableFrom(notifier) ||
show == null || show.ReturnType != typeof(void) ||
awake == null || awake.ReturnType != typeof(void))
{
throw new MissingMethodException("SRDebugger ErrorNotifier methods were not found (client version mismatch)");
}
harmony.Patch(show, prefix: new HarmonyMethod(typeof(DebuggerErrorNotification), nameof(SuppressWarning)));
harmony.Patch(awake, postfix: new HarmonyMethod(typeof(DebuggerErrorNotification), nameof(HideNotifier)));
logger.LogInfo("SRDebugger blinking error notification disabled; console logging remains active");
}
private static bool SuppressWarning(object __instance)
{
HideNotifier(__instance);
return false;
}
private static void HideNotifier(object __instance)
{
if (__instance is Component component && component != null)
{
component.gameObject.SetActive(false);
}
}
}
@@ -27,7 +27,8 @@ internal static class FieldTransitionDiagnostics
{
Log = logger;
Patch(harmony, Game.Method(() => QuestPacket.SendQuestClearRequest(0)), nameof(QuestClearSend));
Patch(harmony, Game.Method(() => QuestPacket.RecvQuestClearResponse(null, 0, 0, null)), nameof(QuestClearReceive));
Patch(harmony, typeof(QuestPacket).GetGameMethod("RecvQuestClearResponse",
BindingFlags.NonPublic | BindingFlags.Static, null, [typeof(byte[]), typeof(int), typeof(int), typeof(Action)], null), nameof(QuestClearReceive));
Patch(harmony, Game.Method(() => QuestInfo.PlayQuestCinemaTimeline(0, false, null, null)), nameof(QuestCinema));
Patch(harmony, Game.Method(() => QuestInfo.PlayQuestCinemaTimelineAfterMoveScene(0, false, 0, null, null)), nameof(QuestCinemaAfterMove));
Patch(harmony, Game.Method<GameFieldManager>(field => field.SetCharPosition(default)), nameof(PositionBefore), nameof(PositionAfter));
+4
View File
@@ -64,12 +64,16 @@ public sealed class Plugin : BaseUnityPlugin
Routing.Install(harmony);
TryInstall("startup fullscreen", () => ClientPresentation.InstallStartupFullscreen(harmony, appManager));
TryInstall("performance overlay suppression", () => ClientPresentation.InstallPerformanceOverlaySuppression(harmony));
TryInstall("debugger error notification suppression", () => DebuggerErrorNotification.Install(harmony, Logger));
TryInstall("maintenance timeout guard", () => ClientDiagnostics.InstallMaintenanceTimeoutGuard(harmony, introUI));
TryInstall("age-gate persistence", () => LocalAccountPolicy.InstallAgeGatePersistence(harmony));
TryInstall("database diagnostics", () => ClientDiagnostics.InstallDatabaseDiagnostics(harmony));
TryInstall("commission navigation completion", () => CommissionNavigation.Install(harmony, Logger));
TryInstall("field reward position ordering", () => FieldRewardPosition.Install(harmony, Logger));
TryInstall("battle checkpoint", () => BattleCheckpoint.Install(harmony, Logger));
TryInstall("battle preparation recovery", () => BattlePreparation.Install(harmony));
TryInstall("costume auto-mount indices", () => CostumeAutoMount.Install(harmony, Logger));
TryInstall("battle formation diagnostics", () => BattleFormationDiagnostics.Install(harmony, Logger));
TryInstall("field transition diagnostics", () => FieldTransitionDiagnostics.Install(harmony, Logger));
TryInstall("event hub presentation", () => EventHubPresentation.Install(harmony, Logger));
TryInstall("notice presentation", () => NoticePresentation.Install(harmony));
+1 -1
View File
@@ -46,7 +46,7 @@ internal static class RealtimeBridge
private static void TcpConstructorPrefix(string __1, ref string __2, ref int __3)
{
if (LoginRuntime.ServerRoot == null || !string.Equals(__2, LoginRuntime.ServerRoot.Host, StringComparison.OrdinalIgnoreCase)) return;
string channel = __1 switch { "Chat" => "matching", "Action" => "action", "RandomDefense" => "defense", "Fishing" => "fishing", _ => null };
string channel = __1 switch { "Chat" => "matching", "Action" => "action", "RandomDefense" => "defense", "Fishing" => "fishing", "Field" => "square", _ => null };
if (channel == null) return;
if (channel == "action")
Volatile.Write(ref forceActionTCP, NativeProxyPolicy.Resolve(new UriBuilder("https", __2, __3).Uri).ProxyUrl == null ? 0 : 1);
+42 -1
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using System.Threading;
@@ -69,6 +70,7 @@ internal static class StoryCheckpoint
private static MethodInfo StartCinema;
private static MethodInfo CheckEntry;
private static MethodInfo Interact;
private static MethodInfo SetLocalInt;
private static int Session;
private static MethodInfo InvokingNative;
private static bool RestoringComplete;
@@ -78,12 +80,20 @@ internal static class StoryCheckpoint
internal static bool WaitingForEntrySync;
internal static bool SynchronizedStory;
private static bool IsStoryReplay => QuicklyQuestHelper.IsOpenUI || StoryReplaySuppoter.Instance?.IsReplayingStory == true;
internal static void Install(Harmony harmony)
{
StartCinema = typeof(TimelinePlayManager).GetGameMethod("StartCinemaTimeline", InstanceFlags, null,
[typeof(int), typeof(string), typeof(int), typeof(int), typeof(int), typeof(Action), typeof(Action), typeof(ETimelinePlayType), typeof(string)], null);
CheckEntry = typeof(GameFieldManager).GetGameMethod("CheckEnterPackQuest", InstanceFlags);
Interact = typeof(FieldQuestObjectController).GetGameMethod("InteractionQuest", InstanceFlags);
MethodInfo guildIntro = typeof(GameFieldManager).GetGameMethod("CoCheckGuildRaidIntroTimelineAndOpenUI", InstanceFlags, null, Type.EmptyTypes, null);
SetLocalInt = Game.FindType("gamfs.GameUtil")?.GetGameMethod("SetInt", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic,
null, [typeof(string), typeof(int), typeof(bool)], null);
if (guildIntro == null || SetLocalInt == null)
throw new MissingMethodException("Guild raid introduction recovery members are unavailable");
harmony.Patch(guildIntro, postfix: new HarmonyMethod(typeof(StoryCheckpoint), nameof(GuildIntroPostfix)));
harmony.Patch(StartCinema, prefix: new HarmonyMethod(typeof(StoryCheckpoint), nameof(CinemaPrefix)));
harmony.Patch(CheckEntry, prefix: new HarmonyMethod(typeof(StoryCheckpoint), nameof(EntryPrefix)));
harmony.Patch(Interact, prefix: new HarmonyMethod(typeof(StoryCheckpoint), nameof(InteractionPrefix)));
@@ -198,6 +208,7 @@ internal static class StoryCheckpoint
{
if (InvokingNative == StartCinema || ServerRoot == null || !EstablishedGameSession || (ETimelinePlayType)__args[7] != ETimelinePlayType.Quest || __instance.IsPlayCinemaTimeline)
return true;
if (IsStoryReplay) return true;
int questID = (int)__args[2];
string timeline = (string)__args[1];
if (questID <= 0 || string.IsNullOrEmpty(timeline)) return true;
@@ -241,7 +252,10 @@ internal static class StoryCheckpoint
private static bool EntryPrefix(GameFieldManager __instance)
{
if (InvokingNative == CheckEntry || ServerRoot == null || !EstablishedGameSession) return true;
if (InvokingNative == CheckEntry || ServerRoot == null || !EstablishedGameSession || IsStoryReplay) return true;
// The guild entry owns its intro callback and restarts an unfinished
// cinema through CinemaPrefix, without accepting or clearing a quest.
if (FindUnitySingleton<PackManager>()?.IsGuildRaidPack() == true) return true;
if (WaitingForEntrySync) return false;
WaitingForEntrySync = true;
FindUnitySingleton<TimelinePlayManager>().IsPlayCinemaTimeline = true;
@@ -249,6 +263,33 @@ internal static class StoryCheckpoint
return false;
}
private static void GuildIntroPostfix(ref IEnumerator __result)
{
if (ServerRoot != null && EstablishedGameSession)
__result = RestoreGuildIntro(__result, Session);
}
private static IEnumerator RestoreGuildIntro(IEnumerator native, int session)
{
Response response = null;
yield return Send("read", null, session, value => response = value);
if (session != Session || response == null) yield break;
Checkpoint pending = response.Pending;
if (pending != null)
{
PackManager pack = FindUnitySingleton<PackManager>();
if (pack?.IsGuildRaidPack() != true || pending.PackID != pack.PlayingPackID || pending.Phase != "accept")
{
ShowStoryFailure("pending checkpoint does not match the guild introduction");
yield break;
}
// The native end callback writes this before server confirmation.
// A pending checkpoint takes precedence over that local flag.
SetLocalInt.Invoke(null, [string.Format(CultureInfo.InvariantCulture, "guild_raid_timeline_{0}", BDNetwork.CommonPacket.UserInfo.OwnerIndex), 0, true]);
}
yield return native;
}
private static IEnumerator RestoreEntry(GameFieldManager field, int session)
{
Response response = null;