mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-15 18:37:29 +08:00
[RF] AquaMai configuration refactor (#82)
更新了配置文件格式,原有的配置文件将被自动无缝迁移,详情请见新的配置文件中的注释(例外:`SlideJudgeTweak` 不再默认启用) 旧配置文件将被重命名备份,如果更新到此版本遇到 Bug 请联系我们 Updated configuration file schema. The old config file will be migrated automatically and seamlessly. See the comments in the new configuration file for details. (Except for `SlideJudgeTweak` is no longer enabled by default) Your old configuration file will be renamed as a backup. If you encounter any bug with this version, please contact us.
This commit is contained in:
53
AquaMai/AquaMai.Mods/Utils/DisplayFrameRate.cs
Normal file
53
AquaMai/AquaMai.Mods/Utils/DisplayFrameRate.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using AquaMai.Config.Attributes;
|
||||
using AquaMai.Core.Helpers;
|
||||
using HarmonyLib;
|
||||
using Main;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AquaMai.Mods.Utils;
|
||||
|
||||
[ConfigSection(
|
||||
en: "Display framerate.",
|
||||
zh: "显示帧率")]
|
||||
public class DisplayFrameRate
|
||||
{
|
||||
[HarmonyPatch(typeof(GameMainObject), "Awake")]
|
||||
[HarmonyPostfix]
|
||||
public static void ShowUi(GameMainObject __instance)
|
||||
{
|
||||
__instance.gameObject.AddComponent<Ui>();
|
||||
}
|
||||
|
||||
private class Ui : MonoBehaviour
|
||||
{
|
||||
private static float sampleTime = 1f;
|
||||
private static int frame;
|
||||
private static float time;
|
||||
private static float fps;
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
var labelStyle = GUI.skin.GetStyle("label");
|
||||
labelStyle.fontSize = GuiSizes.FontSize;
|
||||
labelStyle.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
const float x = 10f;
|
||||
const float y = 10f;
|
||||
var width = GuiSizes.FontSize * 7f;
|
||||
var height = GuiSizes.LabelHeight * 1.5f;
|
||||
|
||||
frame += 1;
|
||||
time += Time.deltaTime;
|
||||
|
||||
if (time >= sampleTime)
|
||||
{
|
||||
fps = frame / time;
|
||||
frame = 0;
|
||||
time = 0;
|
||||
}
|
||||
|
||||
GUI.Box(new Rect(x, y, width, height), "");
|
||||
GUI.Label(new Rect(x, y, width, height), $"{fps:0.0} FPS");
|
||||
}
|
||||
}
|
||||
}
|
||||
49
AquaMai/AquaMai.Mods/Utils/LogNetworkErrors.cs
Normal file
49
AquaMai/AquaMai.Mods/Utils/LogNetworkErrors.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Diagnostics;
|
||||
using AquaMai.Config.Attributes;
|
||||
using HarmonyLib;
|
||||
using Manager;
|
||||
using Manager.Operation;
|
||||
using MelonLoader;
|
||||
using Net.Packet;
|
||||
|
||||
namespace AquaMai.Mods.Utils;
|
||||
|
||||
[ConfigSection(exampleHidden: true, defaultOn: true)]
|
||||
public class LogNetworkErrors
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(Packet), "ProcImpl")]
|
||||
public static void Postfix(PacketState __result, Packet __instance)
|
||||
{
|
||||
if (__result == PacketState.Error)
|
||||
{
|
||||
MelonLogger.Msg($"[LogNetworkErrors] {__instance.Query.Api}: {__instance.Status}");
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(DataDownloader), "NotifyOffline")]
|
||||
public static void DataDownloader()
|
||||
{
|
||||
MelonLogger.Msg("[LogNetworkErrors] DataDownloader NotifyOffline");
|
||||
var stackTrace = new StackTrace();
|
||||
MelonLogger.Msg(stackTrace.ToString());
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(OnlineCheckInterval), "NotifyOffline")]
|
||||
public static void OnlineCheckInterval()
|
||||
{
|
||||
MelonLogger.Msg("[LogNetworkErrors] OnlineCheckInterval NotifyOffline");
|
||||
var stackTrace = new StackTrace();
|
||||
MelonLogger.Msg(stackTrace.ToString());
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(OperationManager), "IsAliveAimeServer", MethodType.Getter)]
|
||||
public static void IsAliveAimeServer(bool __result)
|
||||
{
|
||||
if (__result == false)
|
||||
MelonLogger.Msg($"[LogNetworkErrors] IsAliveAimeServer Is {__result}");
|
||||
}
|
||||
}
|
||||
22
AquaMai/AquaMai.Mods/Utils/LogUserId.cs
Normal file
22
AquaMai/AquaMai.Mods/Utils/LogUserId.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using AquaMai.Config.Attributes;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using Net.Packet;
|
||||
using Net.Packet.Mai2;
|
||||
using Net.VO.Mai2;
|
||||
|
||||
namespace AquaMai.Mods.Utils;
|
||||
|
||||
[ConfigSection(
|
||||
en: "Log user ID on login.",
|
||||
zh: "登录时将 UserID 输出到日志")]
|
||||
public class LogUserId
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PacketGetUserPreview), MethodType.Constructor, typeof(ulong), typeof(string), typeof(Action<ulong, UserPreviewResponseVO>), typeof(Action<PacketStatus>))]
|
||||
public static void Postfix(ulong userId)
|
||||
{
|
||||
MelonLogger.Msg($"[LogUserId] UserLogin: {userId}");
|
||||
}
|
||||
}
|
||||
3
AquaMai/AquaMai.Mods/Utils/README.md
Normal file
3
AquaMai/AquaMai.Mods/Utils/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Utils
|
||||
|
||||
Debugging or diagnostic purpose utilities goes here. They don't affect the game play at all, but may show UIs if needed.
|
||||
100
AquaMai/AquaMai.Mods/Utils/ShowErrorLog.cs
Normal file
100
AquaMai/AquaMai.Mods/Utils/ShowErrorLog.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using AquaMai.Config.Attributes;
|
||||
using AquaMai.Core.Helpers;
|
||||
using HarmonyLib;
|
||||
using Main;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AquaMai.Mods.Utils;
|
||||
|
||||
[ConfigSection(
|
||||
en: "Show error log in the game.",
|
||||
zh: "在游戏中显示错误日志窗口而不是关闭游戏进程")]
|
||||
public class ShowErrorLog
|
||||
{
|
||||
private static Ui _errorUi;
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(GameMain), "ExceptionHandler")]
|
||||
private static void ExceptionHandler(GameMain __instance, Exception e)
|
||||
{
|
||||
if (_errorUi == null)
|
||||
{
|
||||
_errorUi = new GameObject("ErrorUI").AddComponent<Ui>();
|
||||
_errorUi.gameObject.SetActive(true);
|
||||
}
|
||||
string logFile = $"{MAI2System.Path.ErrorLogPath}{DateTime.Now:yyyyMMddHHmmss}.log";
|
||||
MelonLogger.Msg("Error Log:");
|
||||
if (File.Exists(logFile))
|
||||
{
|
||||
MelonLogger.Error(File.ReadAllText(logFile));
|
||||
_errorUi.SetErrorLog(File.ReadAllText(logFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
MelonLogger.Error(e);
|
||||
_errorUi.SetErrorLog(e.ToString());
|
||||
}
|
||||
|
||||
Application.quitting += ApplicationOnQuitting;
|
||||
_errorUi.StartCoroutine(_errorUi.Show());
|
||||
}
|
||||
|
||||
private static void ApplicationOnQuitting()
|
||||
{
|
||||
Thread.Sleep(Timeout.Infinite);
|
||||
}
|
||||
|
||||
private class Ui : MonoBehaviour
|
||||
{
|
||||
private string _errorLog = "";
|
||||
|
||||
public void SetErrorLog(string text)
|
||||
{
|
||||
_errorLog = "Error Log:\n" + text;
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
var labelStyle = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
fontSize = GuiSizes.FontSize,
|
||||
alignment = TextAnchor.MiddleLeft,
|
||||
normal = new GUIStyleState(){textColor = Color.black}
|
||||
};
|
||||
|
||||
var boxStyle = new GUIStyle(GUI.skin.box)
|
||||
{
|
||||
normal = new GUIStyleState() { background = Texture2D.whiteTexture }
|
||||
};
|
||||
|
||||
int logLineCount = Regex.Matches(_errorLog, "\n").Count + 1;
|
||||
float offset = GuiSizes.PlayerCenter * 0.12f;
|
||||
var x = GuiSizes.PlayerCenter / 2f + offset / 2f;
|
||||
var y = Screen.height / 1.8f;
|
||||
var width = GuiSizes.PlayerCenter - offset;
|
||||
var height = GuiSizes.LabelHeight * logLineCount + GuiSizes.Margin * 2;
|
||||
|
||||
GUI.Box(new Rect(x, y, width, height), "", boxStyle);
|
||||
GUI.Label(new Rect(x, y, width, height), _errorLog, labelStyle);
|
||||
if (!GuiSizes.SinglePlayer)
|
||||
{
|
||||
GUI.Box(new Rect(x + GuiSizes.PlayerWidth, y, width, height), "", boxStyle);
|
||||
GUI.Label(new Rect(x + GuiSizes.PlayerWidth, y, width, height), _errorLog, labelStyle);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator Show()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return null; // 让 Unity 处理一帧
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
72
AquaMai/AquaMai.Mods/Utils/ShowNetErrorDetail.cs
Normal file
72
AquaMai/AquaMai.Mods/Utils/ShowNetErrorDetail.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using AquaMai.Config.Attributes;
|
||||
using AquaMai.Core.Helpers;
|
||||
using AquaMai.Core.Resources;
|
||||
using HarmonyLib;
|
||||
using MAI2.Util;
|
||||
using Manager;
|
||||
using Monitor;
|
||||
using Process;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AquaMai.Mods.Utils;
|
||||
|
||||
[ConfigSection(
|
||||
en: "Show Network error detail in the game when gray network icon appears.",
|
||||
zh: "出现灰网时显示原因")]
|
||||
public class ShowNetErrorDetail
|
||||
{
|
||||
[HarmonyPatch(typeof(CommonProcess), "OnStart")]
|
||||
[HarmonyPostfix]
|
||||
public static void SetIconStatus(CommonMonitor[] ____monitors)
|
||||
{
|
||||
____monitors[0].gameObject.AddComponent<DetailUi>();
|
||||
}
|
||||
|
||||
private class DetailUi : MonoBehaviour
|
||||
{
|
||||
public void OnGUI()
|
||||
{
|
||||
var errors = new List<string>();
|
||||
if (!Singleton<OperationManager>.Instance.IsAliveServer)
|
||||
{
|
||||
errors.Add(Locale.NetErrIsAliveServer);
|
||||
}
|
||||
|
||||
if (!Singleton<OperationManager>.Instance.IsAliveAimeReader)
|
||||
{
|
||||
errors.Add(Locale.NetErrIsAliveAimeReader);
|
||||
}
|
||||
|
||||
if (!Singleton<OperationManager>.Instance.IsAliveAimeServer)
|
||||
{
|
||||
errors.Add(Locale.NetErrIsAliveAimeServer);
|
||||
}
|
||||
|
||||
if (!Singleton<OperationManager>.Instance.WasDownloadSuccessOnce)
|
||||
{
|
||||
errors.Add(Locale.NetErrWasDownloadSuccessOnce);
|
||||
}
|
||||
|
||||
if (errors.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var labelStyle = GUI.skin.GetStyle("label");
|
||||
labelStyle.fontSize = GuiSizes.FontSize;
|
||||
labelStyle.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
var x = GuiSizes.PlayerCenter + GuiSizes.PlayerWidth * .2f;
|
||||
var y = Screen.height * .01f;
|
||||
var width = GuiSizes.FontSize * 15f;
|
||||
var height = GuiSizes.LabelHeight * errors.Count + GuiSizes.Margin * 2;
|
||||
|
||||
GUI.Box(new Rect(x, y, width, height), "");
|
||||
for (var i = 0; i < errors.Count; i++)
|
||||
{
|
||||
GUI.Label(new Rect(x, y + GuiSizes.Margin + GuiSizes.LabelHeight * i, width, GuiSizes.LabelHeight), errors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user