-
Notifications
You must be signed in to change notification settings - Fork 58
feat: HeadphoneVolumeOverride #136
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using HarmonyLib; | ||
|
|
||
| using AquaMai.Config.Attributes; | ||
| using UnityEngine; | ||
|
|
||
| namespace AquaMai.Mods.GameSystem; | ||
|
|
||
| [ConfigSection( | ||
| name: "耳机音量覆盖", | ||
| en: "Override 1P/2P headphone volume to a fixed value, ignoring the user's in-game setting. Set to -1 to disable (use user setting). Range: 0–20.", | ||
| zh: "将 1P/2P 耳机音量强制覆盖为固定值,忽略用户的游戏内设置。设为 -1 则禁用(使用用户设置)。范围:0–20。")] | ||
| public static class HeadphoneVolumeOverride | ||
| { | ||
| [ConfigEntry( | ||
| name: "1P 音量覆盖", | ||
| en: "1P headphone volume override. -1 = use user setting, 0–20 = fixed volume (20 is max).", | ||
| zh: "1P 耳机音量覆盖值。-1 = 使用用户设置,0–20 = 固定音量(20 为最大值)。")] | ||
| private static readonly float p1 = -1f; | ||
|
|
||
| [ConfigEntry( | ||
| name: "2P 音量覆盖", | ||
| en: "2P headphone volume override. -1 = use user setting, 0–20 = fixed volume (20 is max).", | ||
| zh: "2P 耳机音量覆盖值。-1 = 使用用户设置,0–20 = 固定音量(20 为最大值)。")] | ||
| private static readonly float p2 = -1f; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this field is intended to be modified by the config loader at runtime, it should not be marked as private static float p2 = -1f; |
||
|
|
||
| [HarmonyPrefix] | ||
| [HarmonyPatch(typeof(CriAtomExPlayer), "SetAisacControl", [typeof(uint), typeof(float)])] | ||
| public static void PreSetAisacControl(uint controlId, ref float value) | ||
| { | ||
| if (controlId == 2 && p1 >= 0f) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Replace magic AISAC control IDs Prompt for AI agents |
||
| { | ||
| value = Mathf.Clamp(p1 / 20f, 0f, 1f); | ||
| } | ||
| else if (controlId == 3 && p2 >= 0f) | ||
|
Comment on lines
+30
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: 考虑将魔法 AISAC 控制 ID 替换为具名常量或枚举。 直接使用像 建议实现方式: [ConfigEntry(
name: "2P 音量覆盖",
en: "2P headphone volume override. -1 = use user setting, 0–20 = fixed volume (20 is max).",
zh: "2P 耳机音量覆盖值。-1 = 使用用户设置,0–20 = 固定音量(20 为最大值)。")]
private static readonly float p2 = -1f;
private const uint Headphone1AisacControlId = 2;
private const uint Headphone2AisacControlId = 3;
[HarmonyPrefix] public static void PreSetAisacControl(uint controlId, ref float value)
{
if (controlId == Headphone1AisacControlId && p1 >= 0f)
{
value = Mathf.Clamp(p1 / 20f, 0f, 1f);
}
else if (controlId == Headphone2AisacControlId && p2 >= 0f)
{
value = Mathf.Clamp(p2 / 20f, 0f, 1f);
}
}Original comment in Englishsuggestion: Consider replacing magic AISAC control IDs with named constants or an enum. Using raw values like Suggested implementation: [ConfigEntry(
name: "2P 音量覆盖",
en: "2P headphone volume override. -1 = use user setting, 0–20 = fixed volume (20 is max).",
zh: "2P 耳机音量覆盖值。-1 = 使用用户设置,0–20 = 固定音量(20 为最大值)。")]
private static readonly float p2 = -1f;
private const uint Headphone1AisacControlId = 2;
private const uint Headphone2AisacControlId = 3;
[HarmonyPrefix] public static void PreSetAisacControl(uint controlId, ref float value)
{
if (controlId == Headphone1AisacControlId && p1 >= 0f)
{
value = Mathf.Clamp(p1 / 20f, 0f, 1f);
}
else if (controlId == Headphone2AisacControlId && p2 >= 0f)
{
value = Mathf.Clamp(p2 / 20f, 0f, 1f);
}
} |
||
| { | ||
| value = Mathf.Clamp(p2 / 20f, 0f, 1f); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this field is intended to be modified by the config loader at runtime, it should not be marked as
readonly. In some .NET runtimes or under certain JIT optimization levels,static readonlyfields of primitive types can be inlined as constants by the JIT compiler, which would prevent any runtime config updates from taking effect. Removingreadonlyensures correctness and avoids potential JIT inlining issues.