diff --git a/Engines/Bakin/BakinDetector.cs b/Engines/Bakin/BakinDetector.cs new file mode 100644 index 0000000..7573b8f --- /dev/null +++ b/Engines/Bakin/BakinDetector.cs @@ -0,0 +1,252 @@ +// Engines/Bakin/BakinDetector.cs — RPG Developer Bakin (Smile Game Builder 系 YUKRDATA) ゲーム検出ヘルパー +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Windows.Media; +using GameLauncher.Engines.Tkool; +using GameLauncher.Engines.Unity; + +namespace GameLauncher.Engines.Bakin +{ + /// + /// RPG Developer Bakin / Smile Game Builder 系ゲームの検出およびメタデータ解決を行うヘルパークラス。 + /// + public static class BakinDetector + { + #region □変数(Private) + + private static readonly HashSet ExcludedExeNames = new(StringComparer.OrdinalIgnoreCase) + { + "bakinplayer.exe", + "notification_helper.exe", + "crashpad_handler.exe", + "elevate.exe", + "UnityCrashHandler32.exe", + "UnityCrashHandler64.exe" + }; + + #endregion + + #region □メソッド(Public) + + /// + /// 指定されたディレクトリが RPG Developer Bakin 製ゲームであるかを判定します。 + /// + /// 対象ディレクトリパス + /// Bakin ゲームであれば true + public static bool IsBakinGame(string dirPath) + { + try + { + if (string.IsNullOrWhiteSpace(dirPath) || !Directory.Exists(dirPath)) + { + return false; + } + + var dataSubDir = Path.Combine(dirPath, "data"); + + // data/ サブフォルダまたはルート直下に Bakin 固有ファイルが存在するか確認 + if (File.Exists(Path.Combine(dataSubDir, "bakinplayer.exe")) || + File.Exists(Path.Combine(dataSubDir, "bakinengine.dll")) || + File.Exists(Path.Combine(dataSubDir, "data.rbpack")) || + File.Exists(Path.Combine(dirPath, "bakinplayer.exe")) || + File.Exists(Path.Combine(dirPath, "bakinengine.dll")) || + File.Exists(Path.Combine(dirPath, "data.rbpack"))) + { + return true; + } + } + catch + { + return false; + } + + return false; + } + + /// + /// 指定ディレクトリ内の RPG Developer Bakin ゲームを検出し、TkoolGameItem を生成します。 + /// + /// ゲームフォルダの絶対パス + /// フォルダ名 + /// フォルダ更新日時 + /// アイコン読み込み関数 + /// 検出されたゲームアイテム。該当しない場合は null + public static TkoolGameItem? DetectBakinGame( + string dirPath, + string folderName, + DateTime? folderModified, + Func? iconLoader) + { + try + { + if (!BakinDetector.IsBakinGame(dirPath)) + { + return null; + } + + var exePath = BakinDetector.FindBakinExecutable(dirPath, folderName); + string title = folderName; + if (!string.IsNullOrEmpty(exePath)) + { + var exeName = Path.GetFileNameWithoutExtension(exePath); + if (!string.IsNullOrWhiteSpace(exeName) && + !string.Equals(exeName, "bakinplayer", StringComparison.OrdinalIgnoreCase) && + !string.Equals(exeName, "Game", StringComparison.OrdinalIgnoreCase)) + { + title = folderName; + } + } + + ImageSource? icon = null; + if (iconLoader != null) + { + icon = iconLoader(exePath, dirPath); + } + + bool hasSave = BakinSaveService.HasAnySaveData(dirPath); + + return new TkoolGameItem + { + Title = title, + FolderName = folderName, + RootDirectory = dirPath, + ExecutablePath = exePath ?? string.Empty, + EngineType = TkoolEngineType.Bakin, + IsModded = false, + ApplyMod = false, + HasSaveData = hasSave, + IconImage = icon, + FolderLastModified = folderModified + }; + } + catch + { + return null; + } + } + + /// + /// Bakin ゲームの起動用実行ファイル(ランチャー .exe または bakinplayer.exe)を検索します。 + /// + /// ゲームルートディレクトリ + /// フォルダ名(省略可) + /// 実行ファイルのフルパス。見つからない場合は null + public static string? FindBakinExecutable(string dirPath, string? folderName = null) + { + try + { + if (string.IsNullOrWhiteSpace(dirPath) || !Directory.Exists(dirPath)) + { + return null; + } + + var topExes = Directory.GetFiles(dirPath, "*.exe", SearchOption.TopDirectoryOnly) + .Where(p => !BakinDetector.IsExcludedLauncherCandidate(p)) + .ToList(); + + if (topExes.Count == 1) + { + return topExes[0]; + } + + if (topExes.Count > 1) + { + if (!string.IsNullOrWhiteSpace(folderName)) + { + var match = topExes.FirstOrDefault(p => + folderName.Contains(Path.GetFileNameWithoutExtension(p), StringComparison.OrdinalIgnoreCase) || + Path.GetFileNameWithoutExtension(p).Contains(folderName, StringComparison.OrdinalIgnoreCase)); + if (match != null) + { + return match; + } + } + + return topExes + .OrderByDescending(p => + { + try { return new FileInfo(p).Length; } catch { return 0L; } + }) + .First(); + } + + var dataPlayer = Path.Combine(dirPath, "data", "bakinplayer.exe"); + if (File.Exists(dataPlayer)) + { + return dataPlayer; + } + + var rootPlayer = Path.Combine(dirPath, "bakinplayer.exe"); + if (File.Exists(rootPlayer)) + { + return rootPlayer; + } + } + catch + { + // 無視 + } + + return null; + } + + /// + /// Bakin ゲームのセーブデータ格納ディレクトリ (`data/savedata` または `savedata`) を解決します。 + /// + /// ゲームルートディレクトリ + /// セーブデータディレクトリのフルパス + public static string ResolveSaveDirectory(string dirPath) + { + if (string.IsNullOrWhiteSpace(dirPath)) + { + return string.Empty; + } + + var dataSaveDir = Path.Combine(dirPath, "data", "savedata"); + if (Directory.Exists(dataSaveDir)) + { + return dataSaveDir; + } + + var rootSaveDir = Path.Combine(dirPath, "savedata"); + if (Directory.Exists(rootSaveDir)) + { + return rootSaveDir; + } + + if (Directory.Exists(Path.Combine(dirPath, "data"))) + { + return dataSaveDir; + } + + return rootSaveDir; + } + + #endregion + + #region □メソッド(Private) + + private static bool IsExcludedLauncherCandidate(string exePath) + { + var fileName = Path.GetFileName(exePath); + if (BakinDetector.ExcludedExeNames.Contains(fileName)) + { + return true; + } + + if (fileName.StartsWith("unins", StringComparison.OrdinalIgnoreCase) || + fileName.Contains("setup", StringComparison.OrdinalIgnoreCase) || + fileName.Contains("config", StringComparison.OrdinalIgnoreCase) || + fileName.Contains("軽量化", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + return false; + } + + #endregion + } +} diff --git a/Engines/Bakin/BakinEngineModule.cs b/Engines/Bakin/BakinEngineModule.cs new file mode 100644 index 0000000..842fe7e --- /dev/null +++ b/Engines/Bakin/BakinEngineModule.cs @@ -0,0 +1,49 @@ +// Engines/Bakin/BakinEngineModule.cs — RPG Developer Bakin エンジンモジュール実装 +using GameLauncher.Engines.Common; +using GameLauncher.Helpers; +using GameLauncher.Models; + +namespace GameLauncher.Engines.Bakin +{ + /// + /// RPG Developer Bakin エンジン用の 実装クラス。 + /// + public sealed class BakinEngineModule : IEngineModule + { + #region □プロパティ(Public) + + /// + public string EngineName => EngineDetectionHelper.EngineBakin; + + #endregion + + #region □メソッド(Public) + + /// + public bool Detect(string gameDirectory) + { + return BakinDetector.IsBakinGame(gameDirectory); + } + + /// + public bool ApplyMod(string gameDirectory, ModPluginDefinition plugin) + { + // Bakin はセーブデータエディタ方式で改造を行うため、スクリプト注入は不要 + return false; + } + + /// + public bool IsModApplied(string gameDirectory) + { + return false; + } + + /// + public string ResolveToolPath(string toolFileName) + { + return AppPathHelper.ResolveEngineTool(this.EngineName, toolFileName) ?? string.Empty; + } + + #endregion + } +} diff --git a/Engines/Bakin/BakinSaveEditorDialog.xaml b/Engines/Bakin/BakinSaveEditorDialog.xaml new file mode 100644 index 0000000..4405a87 --- /dev/null +++ b/Engines/Bakin/BakinSaveEditorDialog.xaml @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +