refactor: reorganize engine-based structure and add agent rules

- Engines/ 配下へエンジン別に再編 (Common/Rgss/Tkool/Tyrano/Wolf/Unity/Nwjs)
- ゲーム個別処理を Engines/<Engine>/Games/<GameName>/ へ分離し、共通処理から明示呼び出し
- 外部ツールを Engines/<Engine>/Tools/ へ移動し、AppPathHelper 経由で解決
- 旧 Tools/ 直下参照と不要な参照ファイル/バックアップを削除
- エージェント規則 AGENTS.md を追加し、README から参照
- publish.ps1 を Engines/<Engine>/Tools/ の再帰配置に対応
This commit is contained in:
armonica committed 2026-10-07 02:30:49 +09:00
1 parent 0d11039ee9
commit 8cea2a147d
47 files changed
+2976 -176

No files matched your search

+186 -2
View File
@@ -17,6 +17,12 @@ using Microsoft.Win32;
using GameLauncher.Helpers;
using GameLauncher.Models;
using GameLauncher.Services;
using GameLauncher.Engines.Rgss;
using GameLauncher.Engines.Tkool;
using GameLauncher.Engines.Tyrano;
using GameLauncher.Engines.Wolf;
using GameLauncher.Engines.Unity;
using GameLauncher.Engines.Nwjs;
namespace GameLauncher
{
@@ -36,6 +42,12 @@ namespace GameLauncher
private readonly WolfModService _wolfModService = new();
private readonly SrpgArchiveService _srpgArchiveService = new();
private readonly SrpgModService _srpgModService = new();
private readonly TkoolPackagedExtractionService _extractionService = new();
private readonly TkoolInjectionService _injectionService = new();
private readonly WindowResizeService _windowResizeService = new();
/// <summary>直近に起動したゲームプロセス(起動後の外部連携処理で使用)</summary>
private Process? _lastStartedProcess;
private readonly ObservableCollection<GameItemBase> _games = [];
private ListCollectionView _gamesView = null!;
@@ -671,6 +683,13 @@ namespace GameLauncher
return;
}
// 単体exe梱包ゲーム(FOSSIL / boxed)の場合の起動処理
if (tg.IsStandaloneExePackage)
{
await LaunchStandaloneExeGameAsync(tg);
return;
}
// ASAR形式ゲームで未解凍かつ改造適用ONの場合、解凍を促す
if (tg.IsAsar && !tg.IsAsarExtracted && tg.ApplyMod)
{
@@ -730,6 +749,104 @@ namespace GameLauncher
}
StartGameProcess(tg);
// RGSSゲーム(ツクールVX / VX Ace)で外部ツール方式のウィンドウ拡大がONの場合、起動後に拡大を適用
if (tg.IsRgss && tg.IsPluginEnabled("RgssWindowResizeExternal", tg.PluginSettings, false))
{
var resizeProc = _lastStartedProcess;
if (resizeProc != null)
{
var (resizeOk, resizeMsg) = await _windowResizeService.ApplyResizeAsync(resizeProc, _config.WindowResizeToolPath);
AppendLog($"[ウィンドウ拡大] {tg.Title}: {resizeMsg}");
}
}
}
/// <summary>
/// 単体exe梱包ゲーム(FOSSIL / boxed)の起動処理。
/// ディスク上に js 実体が無い形態は、改造適用ON時に _extracted へ展開してから注入し、
/// 展開先が無い/展開不可の場合はそのままexeを起動する(起動対応のみ)。
/// </summary>
private async Task LaunchStandaloneExeGameAsync(TkoolGameItem tg)
{
// 1. 改造適用ON時は埋め込みコンテナを _extracted へ展開を試行(冪等)
// 展開戦略: 組み込みZIP展開 → 外部アンパッカー委譲(未配置なら自動取得)の順で試行。
if (tg.ApplyMod)
{
var progress = new Progress<string>(m => AppendLog($"[単体exe展開] {m}"));
var relPlugins = _extractionService.ExtractPackageNw(tg.ExecutablePath, tg.RootDirectory, out var extractedDir, progress);
if (relPlugins != null)
{
tg.IsStandaloneExeExtracted = true;
tg.StandaloneExtractedDirPath = extractedDir;
}
else if (tg.IsBoxedExe)
{
AppendLog($"[単体exe展開] {tg.Title}: 埋め込み/外部いずれの展開も不可でした(起動のみ対応)。");
}
// 2. 注入可能な plugins.js が得られた場合のみ注入を適用(可逆)
var injectable = ResolveInjectablePluginsJs(tg.RootDirectory);
if (injectable != null)
{
var modPluginPath = Path.Combine(TkoolModService.GetPluginsDirectory(), TkoolInjectionService.ModPluginFileName);
var pluginsDir = Path.GetDirectoryName(injectable)!;
var ok = _injectionService.Apply(injectable, Path.Combine(pluginsDir, "plugins"), modPluginPath);
AppendLog($"[単体exe改造] {tg.Title}: {(ok ? "注入しました(可逆)" : "注入に失敗しました")}");
if (ok)
{
tg.IsModded = true;
tg.StandaloneBackupPath = injectable + TkoolInjectionService.ExeBackupSuffix;
}
}
else
{
AppendLog($"[単体exe改造] {tg.Title}: exe内にJSが埋め込まれているため注入不可(起動のみ)。");
}
_scannerService.SaveCache(_games);
}
else
{
// 改造OFF時は復元を試行
var injectable = ResolveInjectablePluginsJs(tg.RootDirectory);
if (injectable != null)
{
var pluginsDir = Path.Combine(Path.GetDirectoryName(injectable)!, "plugins");
var ok = _injectionService.Restore(injectable, pluginsDir);
AppendLog($"[単体exe復元] {tg.Title}: {(ok ? "オリジナルへ復元しました" : "復元に失敗しました")}");
}
tg.IsModded = false;
_scannerService.SaveCache(_games);
}
AppendLog($"[単体exe起動] {tg.Title} を起動します...");
StartGameProcess(tg);
}
/// <summary>
/// 単体exe梱包ゲームで注入/復元の対象となる plugins.js を解決します。
/// 優先順: `_extracted` 内 → ディスク上(js / www/js)。無ければ null。
/// </summary>
private static string? ResolveInjectablePluginsJs(string gameRootDir)
{
try
{
var candidates = new[]
{
Path.Combine(gameRootDir, TkoolPackagedExtractionService.ExtractedDirName, "js", "plugins.js"),
Path.Combine(gameRootDir, TkoolPackagedExtractionService.ExtractedDirName, "js", "plugins", "plugins.js"),
Path.Combine(gameRootDir, TkoolPackagedExtractionService.ExtractedDirName, "www", "js", "plugins.js"),
Path.Combine(gameRootDir, "js", "plugins.js"),
Path.Combine(gameRootDir, "www", "js", "plugins.js"),
};
return candidates.FirstOrDefault(File.Exists);
}
catch
{
return null;
}
}
private void LaunchUnityGame(UnityGameItem ug)
@@ -770,7 +887,7 @@ namespace GameLauncher
}
}
Process.Start(startInfo);
_lastStartedProcess = Process.Start(startInfo);
game.LastLaunched = DateTime.Now;
_scannerService.SaveCache(_games);
@@ -942,6 +1059,73 @@ namespace GameLauncher
}
}
/// <summary>
/// 単体exe梱包ゲーム(FOSSIL / boxed)の埋め込みコンテナを _extracted へ展開します。
/// </summary>
private async void btnExtractStandalone_Click(object sender, RoutedEventArgs e)
{
if (lstGames.SelectedItem is not TkoolGameItem tg || !tg.IsStandaloneExePackage) return;
btnExtractStandalone.IsEnabled = false;
AppendLog($"[単体exe展開開始] {tg.Title}");
try
{
var progress = new Progress<string>(m => AppendLog($"[単体exe展開] {m}"));
var relPlugins = await Task.Run(() =>
_extractionService.ExtractPackageNw(tg.ExecutablePath, tg.RootDirectory, out var dir, progress));
if (relPlugins != null)
{
tg.IsStandaloneExeExtracted = true;
tg.StandaloneExtractedDirPath = TkoolPackagedExtractionService.GetExtractedDir(tg.RootDirectory);
_scannerService.SaveCache(_games);
AppendLog($"[単体exe展開成功] {tg.Title}: {relPlugins}");
MessageBox.Show("埋め込みコンテナを _extracted へ展開しました。", "埋め込み展開",
MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
AppendLog($"[単体exe展開失敗] {tg.Title}: exe内に展開可能なZIPコンテナを検出できませんでした。");
MessageBox.Show("exe内に展開可能なZIPコンテナを検出できませんでした。起動対応のみ可能です。",
"埋め込み展開", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
finally
{
btnExtractStandalone.IsEnabled = true;
}
}
/// <summary>
/// 単体exe梱包ゲームの改造プラグイン注入を除去し、オリジナル状態へ復元します(可逆)。
/// </summary>
private void btnRestoreStandalone_Click(object sender, RoutedEventArgs e)
{
if (lstGames.SelectedItem is not TkoolGameItem tg || !tg.IsStandaloneExePackage) return;
var injectable = ResolveInjectablePluginsJs(tg.RootDirectory);
if (injectable == null)
{
AppendLog($"[単体exe復元] {tg.Title}: 復元対象の plugins.js が見つかりません。");
MessageBox.Show("復元対象の plugins.js が見つかりません。", "改造の復元",
MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
var pluginsDir = Path.Combine(Path.GetDirectoryName(injectable)!, "plugins");
var ok = _injectionService.Restore(injectable, pluginsDir);
if (ok)
{
tg.IsModded = false;
tg.StandaloneBackupPath = null;
_scannerService.SaveCache(_games);
}
AppendLog($"[単体exe復元{(ok ? "成功" : "失敗")}] {tg.Title}");
MessageBox.Show(ok ? "ゲームを改造前のオリジナル状態へ復元しました。" : "復元に失敗しました。",
"改造の復元", MessageBoxButton.OK,
ok ? MessageBoxImage.Information : MessageBoxImage.Warning);
}
private async Task RestoreAsarForGame(TkoolGameItem tg)
{
if (!tg.IsAsar || string.IsNullOrEmpty(tg.AsarPath) || string.IsNullOrEmpty(tg.AsarExtractedDirPath)) return;
@@ -1486,7 +1670,7 @@ namespace GameLauncher
}
else
{
MessageBox.Show("プロキシDLLの配置に失敗しました。\nTools/speedhack-i686/version.dll が存在するか確認してください。", "エラー", MessageBoxButton.OK, MessageBoxImage.Warning);
MessageBox.Show("プロキシDLLの配置に失敗しました。\nEngines/Rgss/Tools/speedhack-i686/version.dll が存在するか確認してください。", "エラー", MessageBoxButton.OK, MessageBoxImage.Warning);
}
_scannerService.SaveCache(_games);
}