Add AC_Subtitles plugin - Subtitle support for H and Touch scenes #13

Merged
ManlyMarco merged 3 commits from subsplug into main 2025-10-14 16:55:52 +00:00
ManlyMarco commented 2025-10-14 16:19:02 +00:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2025-10-14 16:21:09 +00:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull Request Overview

Adds a new BepInEx IL2CPP plugin to provide subtitles in H and Touch scenes by hooking scene initialization and rendering a subtitle canvas with localized text.

  • Introduces AC_Subtitles project and includes it in the solution.
  • Implements SubtitlesPlugin (BepInEx plugin + Harmony hooks), SubtitlesCanvas (UI and display logic), and AutoTranslatorHelper (integration with XUnity AutoTranslator).
  • Configurable behavior via BepInEx config (enable/disable, language override, show character name).

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tools/Aicomi-Translation-Tools.sln Adds AC_Subtitles project to the solution with build configurations.
tools/AC_Subtitles/AC_Subtitles.csproj New SDK-style project targeting net6.0 with required package references and output settings.
tools/AC_Subtitles/SubtitlesPlugin.cs Core plugin: config, language detection, subtitle map loading, Harmony hooks, and canvas creation.
tools/AC_Subtitles/SubtitlesCanvas.cs Runtime subtitle UI creation, update loop, voice key detection, and text assembly.
tools/AC_Subtitles/AutoTranslatorHelper.cs Helper to interact with XUnity AutoTranslator and to read language settings.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

## Pull Request Overview Adds a new BepInEx IL2CPP plugin to provide subtitles in H and Touch scenes by hooking scene initialization and rendering a subtitle canvas with localized text. - Introduces AC_Subtitles project and includes it in the solution. - Implements SubtitlesPlugin (BepInEx plugin + Harmony hooks), SubtitlesCanvas (UI and display logic), and AutoTranslatorHelper (integration with XUnity AutoTranslator). - Configurable behavior via BepInEx config (enable/disable, language override, show character name). ### Reviewed Changes Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments. <details> <summary>Show a summary per file</summary> | File | Description | | ---- | ----------- | | tools/Aicomi-Translation-Tools.sln | Adds AC_Subtitles project to the solution with build configurations. | | tools/AC_Subtitles/AC_Subtitles.csproj | New SDK-style project targeting net6.0 with required package references and output settings. | | tools/AC_Subtitles/SubtitlesPlugin.cs | Core plugin: config, language detection, subtitle map loading, Harmony hooks, and canvas creation. | | tools/AC_Subtitles/SubtitlesCanvas.cs | Runtime subtitle UI creation, update loop, voice key detection, and text assembly. | | tools/AC_Subtitles/AutoTranslatorHelper.cs | Helper to interact with XUnity AutoTranslator and to read language settings. | </details> --- <sub>**Tip:** Customize your code reviews with copilot-instructions.md. <a href="/IllusionMods/Aicomi-Translation/new/main/.github?filename=copilot-instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Create the file</a> or <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">learn how to get started</a>.</sub>
@ -0,0 +1,110 @@
using BepInEx;
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-14 16:21:09 +00:00

File.ReadAllLines will throw if AutoTranslatorConfig.ini is missing; guard with File.Exists (or use File.ReadLines with an existence check) to avoid an unhandled exception when AutoTranslator is installed but the config file is absent.

File.ReadAllLines will throw if AutoTranslatorConfig.ini is missing; guard with File.Exists (or use File.ReadLines with an existence check) to avoid an unhandled exception when AutoTranslator is installed but the config file is absent.
@ -0,0 +36,4 @@
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.sortingOrder = -2; // Draw under UI
_canvasGroupCmp = gameObject.AddComponent<CanvasGroup>();
_canvasGroupCmp.blocksRaycasts = false;
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-14 16:21:08 +00:00

The GameObject created in MakeCanvas does not have a Canvas component; GetComponent() will return null and accessing canvas.renderMode will throw a NullReferenceException. Add the Canvas component before using it, e.g., replace GetComponent with AddComponent or null-check and add if missing.

The GameObject created in MakeCanvas does not have a Canvas component; GetComponent<Canvas>() will return null and accessing canvas.renderMode will throw a NullReferenceException. Add the Canvas component before using it, e.g., replace GetComponent with AddComponent or null-check and add if missing.
@ -0,0 +49,4 @@
_subtitleGo.name = "SubtitleText";
DestroyImmediate(_subtitleGo.GetComponent<UIBindData>());
DestroyImmediate(_subtitleGo.GetComponent<TMP_SpriteAnimator>());
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-14 16:21:08 +00:00

DestroyImmediate is discouraged at runtime and can cause unexpected behavior; use Destroy for runtime object/component cleanup. Replace DestroyImmediate calls with Destroy to align with Unity runtime best practices.

            Destroy(_subtitleGo.GetComponent<UIBindData>());
            Destroy(_subtitleGo.GetComponent<TMP_SpriteAnimator>());
DestroyImmediate is discouraged at runtime and can cause unexpected behavior; use Destroy for runtime object/component cleanup. Replace DestroyImmediate calls with Destroy to align with Unity runtime best practices. ```suggestion Destroy(_subtitleGo.GetComponent<UIBindData>()); Destroy(_subtitleGo.GetComponent<TMP_SpriteAnimator>()); ```
@ -0,0 +71,4 @@
}
catch (Exception e)
{
SubtitlesPlugin.Log.LogError("Failed to create subtitle canvas! I am die, thank you forever.\n" + e);
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-14 16:21:09 +00:00

The error message is unclear and unprofessional. Replace it with a concise, actionable message that includes context and the exception, e.g., 'Failed to create subtitle canvas. Subtitles will be disabled for this scene.' and append the exception.

            SubtitlesPlugin.Log.LogError("Failed to create subtitle canvas. Subtitles will be disabled for this scene.\n" + e);
The error message is unclear and unprofessional. Replace it with a concise, actionable message that includes context and the exception, e.g., 'Failed to create subtitle canvas. Subtitles will be disabled for this scene.' and append the exception. ```suggestion SubtitlesPlugin.Log.LogError("Failed to create subtitle canvas. Subtitles will be disabled for this scene.\n" + e); ```
@ -0,0 +113,4 @@
if (_canvasGroupCmp.alpha <= 0)
_subtitleCmp.text = "";
}
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-14 16:21:08 +00:00

CanvasGroup.alpha is decremented/incremented without clamping, allowing it to drift below 0 or above 1. Clamp the value to [0, 1] to avoid negative or >1 alpha values that can lead to inconsistent behavior.

CanvasGroup.alpha is decremented/incremented without clamping, allowing it to drift below 0 or above 1. Clamp the value to [0, 1] to avoid negative or >1 alpha values that can lead to inconsistent behavior.
@ -0,0 +118,4 @@
else
{
if (_canvasGroupCmp.alpha < 1)
_canvasGroupCmp.alpha += Time.deltaTime * 4;
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-14 16:21:08 +00:00

CanvasGroup.alpha is decremented/incremented without clamping, allowing it to drift below 0 or above 1. Clamp the value to [0, 1] to avoid negative or >1 alpha values that can lead to inconsistent behavior.

CanvasGroup.alpha is decremented/incremented without clamping, allowing it to drift below 0 or above 1. Clamp the value to [0, 1] to avoid negative or >1 alpha values that can lead to inconsistent behavior.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
IllusionMods/Aicomi-Translation!13
No description provided.