diff --git a/.gitignore b/.gitignore
index c3cc3fd..271a9d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,9 @@
*.suo
*.userosscache
*.sln.docstates
+
+# Runtime data
+Backups/
+Profiles/
+config.json
+games_cache.json
diff --git a/ConfigDialog.xaml b/ConfigDialog.xaml
new file mode 100644
index 0000000..db1f815
--- /dev/null
+++ b/ConfigDialog.xaml
@@ -0,0 +1,136 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ConfigDialog.xaml.cs b/ConfigDialog.xaml.cs
new file mode 100644
index 0000000..fee9b34
--- /dev/null
+++ b/ConfigDialog.xaml.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Windows;
+using Microsoft.Win32;
+using GameLauncher.Helpers;
+using GameLauncher.Models;
+
+namespace GameLauncher
+{
+ ///
+ /// 設定ダイアログのロジック
+ ///
+ public partial class ConfigDialog : Window
+ {
+ private readonly LauncherConfig _config;
+
+ public bool IsSaved { get; private set; }
+
+ public ConfigDialog(LauncherConfig config)
+ {
+ InitializeComponent();
+ _config = config;
+
+ txtRgssExtractorPath.Text = _config.RgssExtractorPath ?? @"C:\Soft\RGSS-Extractor-v1.0\RGSS Extractor.exe";
+ txtBackupsPath.Text = AppPathHelper.GetBackupsDirectory();
+ chkDefaultApplyMod.IsChecked = _config.DefaultApplyMod;
+ }
+
+ private void btnBrowseExtractor_Click(object sender, RoutedEventArgs e)
+ {
+ var ofd = new OpenFileDialog
+ {
+ Title = "RGSS Extractor の実行ファイルを選択してください",
+ Filter = "実行ファイル (*.exe)|*.exe|すべてのファイル (*.*)|*.*",
+ FileName = "RGSS Extractor.exe"
+ };
+
+ var currentDir = Path.GetDirectoryName(txtRgssExtractorPath.Text);
+ if (!string.IsNullOrEmpty(currentDir) && Directory.Exists(currentDir))
+ {
+ ofd.InitialDirectory = currentDir;
+ }
+
+ if (ofd.ShowDialog() == true)
+ {
+ txtRgssExtractorPath.Text = ofd.FileName;
+ }
+ }
+
+ private void btnOpenBackupsDir_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ var dir = AppPathHelper.GetBackupsDirectory();
+ if (!Directory.Exists(dir))
+ {
+ Directory.CreateDirectory(dir);
+ }
+ Process.Start(new ProcessStartInfo { FileName = dir, UseShellExecute = true });
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"バックアップフォルダを開けませんでした:\n{ex.Message}", "エラー", MessageBoxButton.OK, MessageBoxImage.Warning);
+ }
+ }
+
+ private void btnSave_Click(object sender, RoutedEventArgs e)
+ {
+ _config.RgssExtractorPath = txtRgssExtractorPath.Text.Trim();
+ _config.DefaultApplyMod = chkDefaultApplyMod.IsChecked == true;
+ IsSaved = true;
+ DialogResult = true;
+ Close();
+ }
+
+ private void btnCancel_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = false;
+ Close();
+ }
+ }
+}
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 8d46fe9..d9f66de 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -32,6 +32,8 @@
+
+
@@ -341,58 +343,50 @@
-
+
+
-
+
-
-
+
+
-
-
-
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -426,6 +420,8 @@
+
+
@@ -539,6 +535,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -593,6 +621,12 @@
+
+
+
+
+
@@ -714,6 +748,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -746,6 +810,12 @@
+
+
+
+
+
@@ -842,6 +912,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index aeafe12..f1e6548 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -30,6 +30,7 @@ namespace GameLauncher
private readonly TyranoModService _tyranoModService = new();
private readonly AsarArchiveService _asarService = new();
private readonly UnitySaveManagerService _unitySaveService = new();
+ private readonly RgssModService _rgssModService = new();
private readonly ObservableCollection _games = [];
private ListCollectionView _gamesView = null!;
@@ -68,6 +69,20 @@ namespace GameLauncher
#region 設定のロード & セーブ
+ private void btnOpenConfig_Click(object sender, RoutedEventArgs e)
+ {
+ var dialog = new ConfigDialog(_config)
+ {
+ Owner = this
+ };
+
+ if (dialog.ShowDialog() == true)
+ {
+ SaveConfig();
+ AppendLog($"[設定変更] 設定を保存しました。(RGSS Extractor: {_config.RgssExtractorPath})");
+ }
+ }
+
private void LoadConfig()
{
try
@@ -82,12 +97,7 @@ namespace GameLauncher
_gameComparer.SortOrder = _config.SortOrder;
ApplySortOrderToComboBox(_config.SortOrder);
- // タブ復元
- if (_config.SelectedTab == 1) tabTkool.IsChecked = true;
- else if (_config.SelectedTab == 2) tabUnity.IsChecked = true;
- else tabAll.IsChecked = true;
-
- // フィルター復元
+ // フィルター設定の復元
RestoreFilterSettings();
}
}
@@ -99,20 +109,30 @@ namespace GameLauncher
private void RestoreFilterSettings()
{
- // ツクールフィルター
- if (_config.TkoolEngineFilter == "MV") rbTkoolMV.IsChecked = true;
- else if (_config.TkoolEngineFilter == "MZ") rbTkoolMZ.IsChecked = true;
- else if (_config.TkoolEngineFilter == "Tyrano") rbTkoolTyrano.IsChecked = true;
- else rbTkoolAll.IsChecked = true;
+ switch (_config.SelectedTab)
+ {
+ case 1: tabMV.IsChecked = true; break;
+ case 2: tabMZ.IsChecked = true; break;
+ case 3: tabVXAce.IsChecked = true; break;
+ case 4: tabVX.IsChecked = true; break;
+ case 5: tabTyrano.IsChecked = true; break;
+ case 6: tabUnity.IsChecked = true; break;
+ default: tabAll.IsChecked = true; break;
+ }
- chkFilterModdedOnly.IsChecked = _config.TkoolFilterModdedOnly;
- chkFilterAsarOnly.IsChecked = _config.TkoolFilterAsarOnly;
+ if (pnlUnityBackendFilter != null)
+ {
+ pnlUnityBackendFilter.Visibility = tabUnity.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
+ }
// Unityフィルター
if (_config.UnityBackendFilter == "IL2CPP") rbUnityIL2CPP.IsChecked = true;
else if (_config.UnityBackendFilter == "Mono") rbUnityMono.IsChecked = true;
else rbUnityAll.IsChecked = true;
+ chkFilterModdedOnly.IsChecked = _config.TkoolFilterModdedOnly;
+ chkFilterAsarOnly.IsChecked = _config.TkoolFilterAsarOnly;
+ chkFilterRgssOnly.IsChecked = _config.TkoolFilterRgssOnly;
chkFilterSaveOnly.IsChecked = _config.UnityFilterSaveOnly;
}
@@ -123,13 +143,21 @@ namespace GameLauncher
try
{
_config.SortOrder = _gameComparer.SortOrder;
- _config.SelectedTab = tabTkool.IsChecked == true ? 1 : (tabUnity.IsChecked == true ? 2 : 0);
- _config.TkoolEngineFilter = rbTkoolMV.IsChecked == true ? "MV" : (rbTkoolMZ.IsChecked == true ? "MZ" : (rbTkoolTyrano.IsChecked == true ? "Tyrano" : "All"));
+ int tabIndex = 0;
+ if (tabMV.IsChecked == true) tabIndex = 1;
+ else if (tabMZ.IsChecked == true) tabIndex = 2;
+ else if (tabVXAce.IsChecked == true) tabIndex = 3;
+ else if (tabVX.IsChecked == true) tabIndex = 4;
+ else if (tabTyrano.IsChecked == true) tabIndex = 5;
+ else if (tabUnity.IsChecked == true) tabIndex = 6;
+
+ _config.SelectedTab = tabIndex;
+ _config.UnityBackendFilter = rbUnityIL2CPP.IsChecked == true ? "IL2CPP" : (rbUnityMono.IsChecked == true ? "Mono" : "All");
+
_config.TkoolFilterModdedOnly = chkFilterModdedOnly.IsChecked == true;
_config.TkoolFilterAsarOnly = chkFilterAsarOnly.IsChecked == true;
-
- _config.UnityBackendFilter = rbUnityIL2CPP.IsChecked == true ? "IL2CPP" : (rbUnityMono.IsChecked == true ? "Mono" : "All");
+ _config.TkoolFilterRgssOnly = chkFilterRgssOnly.IsChecked == true;
_config.UnityFilterSaveOnly = chkFilterSaveOnly.IsChecked == true;
var options = new JsonSerializerOptions
@@ -171,6 +199,15 @@ namespace GameLauncher
}
}
+ foreach (var rgssPlugin in TkoolGameItem.DefaultRgssPlugins)
+ {
+ if (!_config.DefaultPluginSettings.ContainsKey(rgssPlugin.Id))
+ {
+ _config.DefaultPluginSettings[rgssPlugin.Id] = true;
+ modified = true;
+ }
+ }
+
if (modified || !File.Exists(_configFilePath))
{
SaveConfig();
@@ -376,70 +413,50 @@ namespace GameLauncher
}
}
- // 2. メインタブフィルター
- if (tabTkool.IsChecked == true)
+ // 2. エンジンの種類フィルター
+ if (tabMV.IsChecked == true)
{
- if (game is not TkoolGameItem tg) return false;
-
- // ツクールサブフィルター
- if (rbTkoolMV.IsChecked == true && tg.EngineType != TkoolEngineType.MV) return false;
- if (rbTkoolMZ.IsChecked == true && tg.EngineType != TkoolEngineType.MZ) return false;
- if (rbTkoolTyrano.IsChecked == true && tg.EngineType != TkoolEngineType.Tyrano) return false;
-
- if (chkFilterModdedOnly.IsChecked == true && !tg.IsModded) return false;
- if (chkFilterAsarOnly.IsChecked == true && !tg.IsAsar) return false;
+ if (game is not TkoolGameItem tg || tg.EngineType != TkoolEngineType.MV) return false;
+ }
+ else if (tabMZ.IsChecked == true)
+ {
+ if (game is not TkoolGameItem tg || tg.EngineType != TkoolEngineType.MZ) return false;
+ }
+ else if (tabVXAce.IsChecked == true)
+ {
+ if (game is not TkoolGameItem tg || tg.EngineType != TkoolEngineType.VXAce) return false;
+ }
+ else if (tabVX.IsChecked == true)
+ {
+ if (game is not TkoolGameItem tg || tg.EngineType != TkoolEngineType.VX) return false;
+ }
+ else if (tabTyrano.IsChecked == true)
+ {
+ if (game is not TkoolGameItem tg || tg.EngineType != TkoolEngineType.Tyrano) return false;
}
else if (tabUnity.IsChecked == true)
{
if (game is not UnityGameItem ug) return false;
-
- // Unityサブフィルター
if (rbUnityIL2CPP.IsChecked == true && ug.BackendType != UnityBackendType.IL2CPP) return false;
if (rbUnityMono.IsChecked == true && ug.BackendType != UnityBackendType.Mono) return false;
- if (chkFilterSaveOnly.IsChecked == true && !ug.HasSaveData) return false;
- }
- else
- {
- // 「すべて」タブ
- if (chkFilterAllModded.IsChecked == true)
- {
- if (game is not TkoolGameItem tg || !tg.IsModded) return false;
- }
- if (chkFilterAllAsar.IsChecked == true)
- {
- if (game is not TkoolGameItem tg || !tg.IsAsar) return false;
- }
- if (chkFilterAllSave.IsChecked == true)
- {
- if (game is not UnityGameItem ug || !ug.HasSaveData) return false;
- }
}
+ // 3. 追加属性フィルター(全タブ共通)
+ if (chkFilterModdedOnly.IsChecked == true && !game.IsModded) return false;
+ if (chkFilterAsarOnly.IsChecked == true && (game is not TkoolGameItem tgAsar || !tgAsar.IsAsar)) return false;
+ if (chkFilterRgssOnly.IsChecked == true && (game is not TkoolGameItem tgRgss || !tgRgss.HasRgssArchive)) return false;
+ if (chkFilterSaveOnly.IsChecked == true && (game is not UnityGameItem ugSave || !ugSave.HasSaveData)) return false;
+
return true;
}
- private void MainTab_Checked(object sender, RoutedEventArgs e)
+ private void EngineTab_Checked(object sender, RoutedEventArgs e)
{
if (!_isInitialized) return;
- if (pnlTkoolFilters == null || pnlUnityFilters == null || pnlAllFilters == null) return;
- if (tabTkool.IsChecked == true)
+ if (pnlUnityBackendFilter != null)
{
- pnlTkoolFilters.Visibility = Visibility.Visible;
- pnlUnityFilters.Visibility = Visibility.Collapsed;
- pnlAllFilters.Visibility = Visibility.Collapsed;
- }
- else if (tabUnity.IsChecked == true)
- {
- pnlTkoolFilters.Visibility = Visibility.Collapsed;
- pnlUnityFilters.Visibility = Visibility.Visible;
- pnlAllFilters.Visibility = Visibility.Collapsed;
- }
- else
- {
- pnlTkoolFilters.Visibility = Visibility.Collapsed;
- pnlUnityFilters.Visibility = Visibility.Collapsed;
- pnlAllFilters.Visibility = Visibility.Visible;
+ pnlUnityBackendFilter.Visibility = tabUnity.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
}
_gamesView?.Refresh();
@@ -486,12 +503,13 @@ namespace GameLauncher
int total = _games.Count;
int visible = _gamesView?.Count ?? 0;
- int tkoolCount = _games.Count(g => g is TkoolGameItem tg && tg.EngineType != TkoolEngineType.Tyrano);
+ int tkoolCount = _games.Count(g => g is TkoolGameItem tg && tg.EngineType != TkoolEngineType.Tyrano && !tg.IsRgss);
+ int rgssCount = _games.Count(g => g is TkoolGameItem tg && tg.IsRgss);
int tyranoCount = _games.Count(g => g is TkoolGameItem tg && tg.EngineType == TkoolEngineType.Tyrano);
int unityCount = _games.Count(g => g is UnityGameItem);
lblStatusSummary.Text = $"総ゲーム数: {total} 件 | 表示: {visible} 件";
- lblStatusBreakdown.Text = $"(ツクール: {tkoolCount}, ティラノ: {tyranoCount}, Unity: {unityCount})";
+ lblStatusBreakdown.Text = $"(ツクールMV/MZ: {tkoolCount}, ツクールVX系: {rgssCount}, ティラノ: {tyranoCount}, Unity: {unityCount})";
}
#endregion
@@ -613,8 +631,23 @@ namespace GameLauncher
}
}
- // スクリプト改造の適用または復元
- if (tg.EngineType == TkoolEngineType.Tyrano)
+ // RGSSゲーム(ツクールVX / VX Ace)の場合
+ if (tg.IsRgss)
+ {
+ var (success, msg) = await _rgssModService.ApplyOrRestoreModAsync(tg, tg.PluginSettings, _config.RgssExtractorPath);
+ AppendLog($"[RGSS改造処理] {tg.Title}: {msg}");
+ if (!success && tg.ApplyMod)
+ {
+ var res = MessageBox.Show(
+ $"スクリプト改造の適用中に警告/エラーが発生しました:\n{msg}\n\nこのまま通常(未改造)でゲームを起動しますか?",
+ "RGSS改造警告",
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Warning);
+ if (res != MessageBoxResult.Yes) return;
+ }
+ }
+ // スクリプト改造の適用または復元(ティラノ)
+ else if (tg.EngineType == TkoolEngineType.Tyrano)
{
if (tg.ApplyMod)
{
@@ -627,6 +660,7 @@ namespace GameLauncher
AppendLog($"[ティラノ復元] {tg.Title}: {msg}");
}
}
+ // スクリプト改造の適用または復元(ツクールMV/MZ)
else
{
var (success, msg) = _modService.ApplyOrRestoreMod(tg, _config.DefaultPluginSettings);
@@ -655,7 +689,8 @@ namespace GameLauncher
// ツクール/ティラノ等のWebランタイム(NW.js / Chromium)ゲームの場合、
// GameLauncher.exe のあるフォルダ配下の Profiles フォルダに隔離した専用プロファイルディレクトリを指定して起動
- if (game is TkoolGameItem tg)
+ // ※RGSS(DirectX/Ruby)やUnity等のネイティブアプリには引数を付与しない
+ if (game is TkoolGameItem tg && !tg.IsRgss)
{
try
{
@@ -699,19 +734,48 @@ namespace GameLauncher
// ツクール専用メニュー
menuTkoolOpenFolder.Visibility = isTkool ? Visibility.Visible : Visibility.Collapsed;
- menuTkoolOpenProfile.Visibility = isTkool ? Visibility.Visible : Visibility.Collapsed;
- menuTkoolOpenPluginsJs.Visibility = isTkool ? Visibility.Visible : Visibility.Collapsed;
menuTkoolRestoreOriginal.Visibility = isTkool ? Visibility.Visible : Visibility.Collapsed;
- if (selected is TkoolGameItem tg && tg.IsAsar)
+ if (selected is TkoolGameItem tg)
{
- menuTkoolExtractAsar.Visibility = !tg.IsAsarExtracted ? Visibility.Visible : Visibility.Collapsed;
- menuTkoolRestoreAsar.Visibility = tg.IsAsarExtracted ? Visibility.Visible : Visibility.Collapsed;
+ // ASAR メニュー
+ if (tg.IsAsar)
+ {
+ menuTkoolExtractAsar.Visibility = !tg.IsAsarExtracted ? Visibility.Visible : Visibility.Collapsed;
+ menuTkoolRestoreAsar.Visibility = tg.IsAsarExtracted ? Visibility.Visible : Visibility.Collapsed;
+ }
+ else
+ {
+ menuTkoolExtractAsar.Visibility = Visibility.Collapsed;
+ menuTkoolRestoreAsar.Visibility = Visibility.Collapsed;
+ }
+
+ // RGSS メニュー
+ if (tg.IsRgss && tg.HasRgssArchive)
+ {
+ menuTkoolExtractRgss.Visibility = !tg.IsRgssExtracted ? Visibility.Visible : Visibility.Collapsed;
+ menuTkoolRestoreRgss.Visibility = tg.IsRgssExtracted ? Visibility.Visible : Visibility.Collapsed;
+ }
+ else
+ {
+ menuTkoolExtractRgss.Visibility = Visibility.Collapsed;
+ menuTkoolRestoreRgss.Visibility = Visibility.Collapsed;
+ }
+
+ // plugins.js は MV/MZ のみ
+ menuTkoolOpenPluginsJs.Visibility = (tg.IsMV || tg.IsMZ) && File.Exists(tg.PluginsJsPath) ? Visibility.Visible : Visibility.Collapsed;
+
+ // 専用プロファイルフォルダは Chromium/NW.js 系(MV/MZ/Tyrano)のみ
+ menuTkoolOpenProfile.Visibility = !tg.IsRgss ? Visibility.Visible : Visibility.Collapsed;
}
else
{
menuTkoolExtractAsar.Visibility = Visibility.Collapsed;
menuTkoolRestoreAsar.Visibility = Visibility.Collapsed;
+ menuTkoolExtractRgss.Visibility = Visibility.Collapsed;
+ menuTkoolRestoreRgss.Visibility = Visibility.Collapsed;
+ menuTkoolOpenPluginsJs.Visibility = Visibility.Collapsed;
+ menuTkoolOpenProfile.Visibility = Visibility.Collapsed;
}
// Unity専用メニュー
@@ -724,7 +788,7 @@ namespace GameLauncher
#endregion
- #region ツクール専用機能 (ASAR解凍・復元・MOD解除・Profile)
+ #region ツクール専用機能 (ASAR解凍・復元・RGSS抽出・復元・MOD解除・Profile)
private async void btnExtractAsar_Click(object sender, RoutedEventArgs e)
{
@@ -849,6 +913,102 @@ namespace GameLauncher
}
}
+ #region RGSS スクリプト抽出・復元
+
+ private async void btnExtractRgss_Click(object sender, RoutedEventArgs e)
+ {
+ if (lstGames.SelectedItem is TkoolGameItem tg)
+ {
+ await ExtractRgssForGame(tg);
+ }
+ }
+
+ private async void MenuExtractRgss_Click(object sender, RoutedEventArgs e)
+ {
+ if (lstGames.SelectedItem is TkoolGameItem tg)
+ {
+ await ExtractRgssForGame(tg);
+ }
+ }
+
+ private async Task ExtractRgssForGame(TkoolGameItem tg)
+ {
+ if (!tg.IsRgss) return;
+
+ btnExtractRgss.IsEnabled = false;
+ pbRgssProgress.Visibility = Visibility.Visible;
+ pbRgssProgress.IsIndeterminate = true;
+ lblRgssProgressStatus.Visibility = Visibility.Visible;
+ lblRgssProgressStatus.Text = "RGSSスクリプトを抽出中...";
+
+ AppendLog($"[RGSS抽出開始] {tg.Title} (アーカイブ: {tg.RgssArchivePath})");
+
+ var (success, message) = await _rgssModService.ExtractScriptsAsync(tg, _config.RgssExtractorPath);
+
+ pbRgssProgress.Visibility = Visibility.Collapsed;
+ lblRgssProgressStatus.Visibility = Visibility.Collapsed;
+ btnExtractRgss.IsEnabled = true;
+
+ if (success)
+ {
+ _scannerService.SaveCache(_games);
+ AppendLog($"[RGSS抽出成功] {message}");
+ MessageBox.Show(message, "RGSS スクリプト抽出完了", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ else
+ {
+ AppendLog($"[RGSS抽出失敗] {message}");
+ MessageBox.Show(message, "RGSS スクリプト抽出エラー", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+
+ private void btnRestoreRgss_Click(object sender, RoutedEventArgs e)
+ {
+ if (lstGames.SelectedItem is TkoolGameItem tg)
+ {
+ RestoreRgssForGame(tg);
+ }
+ }
+
+ private void MenuRestoreRgss_Click(object sender, RoutedEventArgs e)
+ {
+ if (lstGames.SelectedItem is TkoolGameItem tg)
+ {
+ RestoreRgssForGame(tg);
+ }
+ }
+
+ private void RestoreRgssForGame(TkoolGameItem tg)
+ {
+ if (!tg.IsRgss) return;
+
+ var confirm = MessageBox.Show(
+ "抽出したスクリプト(Data\\Scripts)や改造を元に戻し、元のアーカイブ暗号化状態に戻しますか?",
+ "RGSSスクリプト復元の確認",
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Question);
+
+ if (confirm != MessageBoxResult.Yes) return;
+
+ AppendLog($"[RGSS復元開始] {tg.Title}");
+ var (success, message) = _rgssModService.RestoreOriginal(tg);
+
+ if (success)
+ {
+ tg.IsModded = false;
+ _scannerService.SaveCache(_games);
+ AppendLog($"[RGSS復元成功] {message}");
+ MessageBox.Show(message, "RGSS 復元完了", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ else
+ {
+ AppendLog($"[RGSS復元失敗] {message}");
+ MessageBox.Show(message, "RGSS 復元エラー", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+
+ #endregion
+
private void btnRestoreOriginal_Click(object sender, RoutedEventArgs e)
{
if (lstGames.SelectedItem is TkoolGameItem tg)
@@ -867,9 +1027,11 @@ namespace GameLauncher
private void RestoreOriginalMod(TkoolGameItem tg)
{
- var result = tg.EngineType == TkoolEngineType.Tyrano
- ? _tyranoModService.RestoreOriginal(tg)
- : _modService.RestoreOriginal(tg);
+ var result = tg.IsRgss
+ ? _rgssModService.RestoreOriginal(tg)
+ : (tg.EngineType == TkoolEngineType.Tyrano
+ ? _tyranoModService.RestoreOriginal(tg)
+ : _modService.RestoreOriginal(tg));
tg.IsModded = false;
AppendLog($"[改造解除] {tg.Title}: {result.Message}");
diff --git a/Models/GameItemBase.cs b/Models/GameItemBase.cs
index 5c72a93..cd269f9 100644
--- a/Models/GameItemBase.cs
+++ b/Models/GameItemBase.cs
@@ -134,9 +134,44 @@ namespace GameLauncher.Models
/// ツクールMZか
public virtual bool IsMZ => false;
+ /// ツクールVXか
+ public virtual bool IsVX => false;
+
+ /// ツクールVX Aceか
+ public virtual bool IsVXAce => false;
+
+ /// RGSS系(VX / VX Ace)か
+ public virtual bool IsRgss => false;
+
/// ティラノスクリプトか
public virtual bool IsTyrano => false;
+ /// RGSSアーカイブ(rgss3a/rgss2a等)を持つか
+ public virtual bool HasRgssArchive
+ {
+ get => false;
+ set { }
+ }
+
+ /// RGSSアーカイブが抽出済み(Scripts.rvdata/rvdata2が存在)か
+ public virtual bool IsRgssExtracted
+ {
+ get => false;
+ set { }
+ }
+
+ /// RGSSバッジのテキスト
+ public virtual string RgssBadgeText => string.Empty;
+
+ /// RGSSバッジの背景色
+ public virtual Brush RgssBadgeBackground => Brushes.Transparent;
+
+ /// RGSSバッジの可視性
+ public virtual Visibility RgssBadgeVisibility => Visibility.Collapsed;
+
+ /// RGSS詳細状態テキスト
+ public virtual string RgssDetailStatusText => string.Empty;
+
/// Unity IL2CPPか
public virtual bool IsIL2CPP => false;
diff --git a/Models/LauncherConfig.cs b/Models/LauncherConfig.cs
index 3f9465e..1e5fb2d 100644
--- a/Models/LauncherConfig.cs
+++ b/Models/LauncherConfig.cs
@@ -23,10 +23,15 @@ namespace GameLauncher.Models
/// 追加のスキャン対象ルートディレクトリ一覧
public List TargetDirectories { get; set; } = [];
+ /// RGSS Extractor の実行ファイルパス(ツクールVX/VX Ace暗号化アーカイブ展開用)
+ public string RgssExtractorPath { get; set; } = @"C:\Soft\RGSS-Extractor-v1.0\RGSS Extractor.exe";
+
// フィルター状態の保存(再起動時復元用)
public string TkoolEngineFilter { get; set; } = "All";
public bool TkoolFilterModdedOnly { get; set; }
public bool TkoolFilterAsarOnly { get; set; }
+ public bool TkoolFilterRgssOnly { get; set; }
+ public bool TkoolFilterAllRgss { get; set; }
public string UnityBackendFilter { get; set; } = "All";
public bool UnityFilterSaveOnly { get; set; }
}
diff --git a/Models/TkoolGameItem.cs b/Models/TkoolGameItem.cs
index 306a844..8181f18 100644
--- a/Models/TkoolGameItem.cs
+++ b/Models/TkoolGameItem.cs
@@ -131,6 +131,65 @@ namespace GameLauncher.Models
public override bool IsMV => EngineType == TkoolEngineType.MV;
public override bool IsMZ => EngineType == TkoolEngineType.MZ;
public override bool IsTyrano => EngineType == TkoolEngineType.Tyrano;
+ public override bool IsVX => EngineType == TkoolEngineType.VX;
+ public override bool IsVXAce => EngineType == TkoolEngineType.VXAce;
+ public override bool IsRgss => EngineType is TkoolEngineType.VX or TkoolEngineType.VXAce;
+
+ // RGSS (VX / VX Ace) アーカイブ関連プロパティ
+ private bool _hasRgssArchive;
+ private bool _isRgssExtracted;
+ private string? _rgssArchivePath;
+
+ public override bool HasRgssArchive
+ {
+ get => _hasRgssArchive;
+ set
+ {
+ if (_hasRgssArchive != value)
+ {
+ _hasRgssArchive = value;
+ OnPropertyChanged();
+ OnPropertyChanged(nameof(RgssBadgeVisibility));
+ OnPropertyChanged(nameof(RgssBadgeText));
+ OnPropertyChanged(nameof(RgssBadgeBackground));
+ OnPropertyChanged(nameof(RgssDetailStatusText));
+ }
+ }
+ }
+
+ public override bool IsRgssExtracted
+ {
+ get => _isRgssExtracted;
+ set
+ {
+ if (_isRgssExtracted != value)
+ {
+ _isRgssExtracted = value;
+ OnPropertyChanged();
+ OnPropertyChanged(nameof(RgssBadgeText));
+ OnPropertyChanged(nameof(RgssBadgeBackground));
+ OnPropertyChanged(nameof(RgssDetailStatusText));
+ }
+ }
+ }
+
+ public string? RgssArchivePath
+ {
+ get => _rgssArchivePath;
+ set { if (_rgssArchivePath != value) { _rgssArchivePath = value; OnPropertyChanged(); } }
+ }
+
+ public override Visibility RgssBadgeVisibility => HasRgssArchive ? Visibility.Visible : Visibility.Collapsed;
+
+ public override string RgssBadgeText => !HasRgssArchive ? string.Empty : (IsRgssExtracted ? "RGSS (抽出済)" : "RGSS (暗号化)");
+
+ public override Brush RgssBadgeBackground => IsRgssExtracted
+ ? new SolidColorBrush(Color.FromRgb(0x00, 0x89, 0x7B))
+ : new SolidColorBrush(Color.FromRgb(0xD3, 0x54, 0x00));
+
+ public override string RgssDetailStatusText => !HasRgssArchive
+ ? string.Empty
+ : (IsRgssExtracted ? "📦 RGSSアーカイブ(スクリプト抽出済み・改造可能)" : "🔒 RGSS暗号化アーカイブ(起動時またはボタンでスクリプト抽出可能)");
public TkoolEngineType EngineType
{
@@ -146,6 +205,9 @@ namespace GameLauncher.Models
OnPropertyChanged(nameof(IsMV));
OnPropertyChanged(nameof(IsMZ));
OnPropertyChanged(nameof(IsTyrano));
+ OnPropertyChanged(nameof(IsVX));
+ OnPropertyChanged(nameof(IsVXAce));
+ OnPropertyChanged(nameof(IsRgss));
}
}
}
@@ -307,10 +369,37 @@ namespace GameLauncher.Models
new() { Id = "TyranoCheatMenu", Name = "🎛 画面上変数(f)チートエディタ表示", Description = "画面右上にボタンを配置し、ゲーム内変数・フラグの閲覧と直接書き換えができるメニューを表示します。" }
];
+ /// ツクールVX / VX Ace用スクリプト改造定義一覧
+ public static readonly ModPluginDefinition[] DefaultRgssPlugins =
+ [
+ new() { Id = "RgssDashSpeedUp", Name = "⚡ 移動速度高速化&常時オートダッシュ", Description = "キャラクターの移動速度を高速化し、Shiftキーを押さなくても常時ダッシュ状態にします。" },
+ new() { Id = "RgssItemGainMax", Name = "🎁 アイテム入手時 99個固定化", Description = "宝箱・イベント・戦闘等で通常アイテムを入手した際、入手個数を99個にします。" },
+ new() { Id = "RgssItemNoConsume", Name = "♾️ アイテム消費なし", Description = "アイテムを使用しても所持個数を減少しないようにします。" },
+ new() { Id = "RgssGoldGainMax", Name = "💰 獲得ゴールド最大化 (999,999G)", Description = "戦闘勝利時の獲得ゴールドを999,999Gにします。" },
+ new() { Id = "RgssExpGainMax", Name = "📈 獲得経験値最大化 (999,999Exp)", Description = "戦闘勝利時の獲得経験値を999,999Expにします。" },
+ new() { Id = "RgssBattleTurnRecoverHp", Name = "💖 ターン開始時 全回復 (HP)", Description = "戦闘中の毎ターン開始時にパーティ全員のHPを全回復します。" },
+ new() { Id = "RgssBattleTurnRecoverMp", Name = "🔷 ターン開始時 全回復 (MP)", Description = "戦闘中の毎ターン開始時にパーティ全員のMPを全回復します。" },
+ new() { Id = "RgssBattleTurnRecoverTp", Name = "⚡ ターン開始時 全回復 (TP)", Description = "戦闘中の毎ターン開始時にパーティ全員のTPを最大(100)にします。(VX Ace)" },
+ new() { Id = "RgssMessageInstant", Name = "⏩ メッセージ瞬間表示・高速スキップ", Description = "会話ウィンドウの文字送りウェイトをカットし、瞬間表示します。" },
+ new() { Id = "RgssCommandMemory", Name = "🧠 コマンド位置記憶 (ツクールMV風)", Description = "メニュー画面や戦闘中のアクターコマンドのカーソル選択位置を記憶して次回遷移時に復元します。" }
+ ];
+
public void SyncPluginOptions(IEnumerable availablePlugins, Dictionary? defaultSettings = null)
{
_pluginOptions.Clear();
- var targetDefs = EngineType == TkoolEngineType.Tyrano ? DefaultTyranoPlugins : availablePlugins;
+ IEnumerable targetDefs;
+ if (EngineType == TkoolEngineType.Tyrano)
+ {
+ targetDefs = DefaultTyranoPlugins;
+ }
+ else if (IsRgss)
+ {
+ targetDefs = DefaultRgssPlugins;
+ }
+ else
+ {
+ targetDefs = availablePlugins;
+ }
foreach (var def in targetDefs)
{
@@ -342,6 +431,8 @@ namespace GameLauncher.Models
TkoolEngineType.MV => "RPGツクールMV",
TkoolEngineType.MZ => "RPGツクールMZ",
TkoolEngineType.Tyrano => "ティラノスクリプト",
+ TkoolEngineType.VX => "RPGツクールVX",
+ TkoolEngineType.VXAce => "RPGツクールVX Ace",
_ => "ツクール/ティラノ"
};
}
diff --git a/Models/UnityEnums.cs b/Models/UnityEnums.cs
index 06eb5af..36d169b 100644
--- a/Models/UnityEnums.cs
+++ b/Models/UnityEnums.cs
@@ -18,6 +18,8 @@ namespace GameLauncher.Models
MV,
MZ,
Tyrano,
+ VX,
+ VXAce,
Unknown
}
diff --git a/Services/GameScannerService.cs b/Services/GameScannerService.cs
index f8f96a3..e616c09 100644
--- a/Services/GameScannerService.cs
+++ b/Services/GameScannerService.cs
@@ -45,6 +45,9 @@ namespace GameLauncher.Services
public string? AsarPath { get; set; }
public string? AsarExtractedDirPath { get; set; }
public string? RelativePluginsJsInAsar { get; set; }
+ public bool HasRgssArchive { get; set; }
+ public bool IsRgssExtracted { get; set; }
+ public string? RgssArchivePath { get; set; }
// Unity専用
public string DataDirectoryPath { get; set; } = string.Empty;
@@ -133,7 +136,10 @@ namespace GameLauncher.Services
IsAsarExtracted = entry.IsAsarExtracted,
AsarPath = entry.AsarPath,
AsarExtractedDirPath = entry.AsarExtractedDirPath,
- RelativePluginsJsInAsar = entry.RelativePluginsJsInAsar
+ RelativePluginsJsInAsar = entry.RelativePluginsJsInAsar,
+ HasRgssArchive = entry.HasRgssArchive,
+ IsRgssExtracted = entry.IsRgssExtracted,
+ RgssArchivePath = entry.RgssArchivePath
};
if (entry.PluginSettings != null)
{
@@ -333,7 +339,10 @@ namespace GameLauncher.Services
IsAsarExtracted = tg.IsAsarExtracted,
AsarPath = tg.AsarPath,
AsarExtractedDirPath = tg.AsarExtractedDirPath,
- RelativePluginsJsInAsar = tg.RelativePluginsJsInAsar
+ RelativePluginsJsInAsar = tg.RelativePluginsJsInAsar,
+ HasRgssArchive = tg.HasRgssArchive,
+ IsRgssExtracted = tg.IsRgssExtracted,
+ RgssArchivePath = tg.RgssArchivePath
});
}
}
@@ -448,6 +457,25 @@ namespace GameLauncher.Services
onGameUpdated(tg);
}
}
+ else if (tg.IsRgss)
+ {
+ var archiveExists = !string.IsNullOrEmpty(tg.RgssArchivePath) && File.Exists(tg.RgssArchivePath);
+ var scriptExists = !string.IsNullOrEmpty(tg.PluginsJsPath) && File.Exists(tg.PluginsJsPath);
+
+ if (!archiveExists && !scriptExists)
+ {
+ onGameRemoved(tg);
+ cacheNeedsSave = true;
+ continue;
+ }
+
+ if (tg.IsRgssExtracted != scriptExists)
+ {
+ tg.IsRgssExtracted = scriptExists;
+ cacheNeedsSave = true;
+ onGameUpdated(tg);
+ }
+ }
else
{
if (!File.Exists(tg.PluginsJsPath))
@@ -475,6 +503,10 @@ namespace GameLauncher.Services
{
tg.IsModded = false;
}
+ else if (tg.IsRgss)
+ {
+ tg.IsModded = !string.IsNullOrEmpty(tg.PluginsJsPath) && File.Exists(tg.PluginsJsPath) && RgssModService.CheckIsModded(tg.PluginsJsPath);
+ }
else if (File.Exists(tg.PluginsJsPath))
{
if (tg.EngineType == TkoolEngineType.Tyrano)
@@ -721,6 +753,199 @@ namespace GameLauncher.Services
};
}
}
+
+ // 4. ツクールVX / VX Ace (RGSS2 / RGSS3) ゲームの検出
+ var rgssGame = DetectRgssGameInDirectory(dirPath, folderName, folderModified);
+ if (rgssGame != null)
+ {
+ return rgssGame;
+ }
+ }
+ catch { }
+
+ return null;
+ }
+
+ private TkoolGameItem? DetectRgssGameInDirectory(string dirPath, string folderName, DateTime? folderModified)
+ {
+ try
+ {
+ // 1. Game.ini または RGSS アーカイブ / スクリプトファイルの存在チェック
+ string? gameIniPath = null;
+ string searchDir = dirPath;
+
+ var directIni = Path.Combine(dirPath, "Game.ini");
+ if (File.Exists(directIni))
+ {
+ gameIniPath = directIni;
+ }
+ else
+ {
+ try
+ {
+ foreach (var sub in Directory.GetDirectories(dirPath))
+ {
+ var subIni = Path.Combine(sub, "Game.ini");
+ if (File.Exists(subIni))
+ {
+ gameIniPath = subIni;
+ searchDir = sub;
+ break;
+ }
+ }
+ }
+ catch { }
+ }
+
+ // 2. アーカイブおよびスクリプト実ファイルの探索
+ string? archivePath = null;
+ string? scriptsPath = null;
+ TkoolEngineType engineType = TkoolEngineType.Unknown;
+ string? title = null;
+
+ if (gameIniPath != null)
+ {
+ try
+ {
+ var lines = File.ReadAllLines(gameIniPath);
+ foreach (var line in lines)
+ {
+ var trim = line.Trim();
+ if (trim.StartsWith("Title=", StringComparison.OrdinalIgnoreCase))
+ {
+ var val = trim.Substring(6).Trim();
+ if (!string.IsNullOrEmpty(val)) title = val;
+ }
+ else if (trim.StartsWith("RTP=", StringComparison.OrdinalIgnoreCase))
+ {
+ var val = trim.Substring(4).Trim();
+ if (val.Contains("RPGVXAce", StringComparison.OrdinalIgnoreCase))
+ engineType = TkoolEngineType.VXAce;
+ else if (val.Contains("RPGVX", StringComparison.OrdinalIgnoreCase))
+ engineType = TkoolEngineType.VX;
+ }
+ else if (trim.StartsWith("Library=", StringComparison.OrdinalIgnoreCase))
+ {
+ var val = trim.Substring(8).Trim();
+ if (val.Contains("RGSS3", StringComparison.OrdinalIgnoreCase) && engineType == TkoolEngineType.Unknown)
+ engineType = TkoolEngineType.VXAce;
+ else if (val.Contains("RGSS2", StringComparison.OrdinalIgnoreCase) && engineType == TkoolEngineType.Unknown)
+ engineType = TkoolEngineType.VX;
+ }
+ else if (trim.StartsWith("Scripts=", StringComparison.OrdinalIgnoreCase))
+ {
+ var val = trim.Substring(8).Trim();
+ if (val.EndsWith(".rvdata2", StringComparison.OrdinalIgnoreCase) && engineType == TkoolEngineType.Unknown)
+ engineType = TkoolEngineType.VXAce;
+ else if (val.EndsWith(".rvdata", StringComparison.OrdinalIgnoreCase) && engineType == TkoolEngineType.Unknown)
+ engineType = TkoolEngineType.VX;
+ }
+ }
+ }
+ catch { }
+ }
+
+ // アーカイブファイルの探索
+ var rgss3aFiles = Directory.GetFiles(searchDir, "*.rgss3a", SearchOption.TopDirectoryOnly);
+ var rgss2aFiles = Directory.GetFiles(searchDir, "*.rgss2a", SearchOption.TopDirectoryOnly);
+
+ if (rgss3aFiles.Length > 0)
+ {
+ archivePath = rgss3aFiles[0];
+ if (engineType == TkoolEngineType.Unknown) engineType = TkoolEngineType.VXAce;
+ }
+ else if (rgss2aFiles.Length > 0)
+ {
+ archivePath = rgss2aFiles[0];
+ if (engineType == TkoolEngineType.Unknown) engineType = TkoolEngineType.VX;
+ }
+
+ // スクリプト実ファイルの探索 (Data\Scripts.rvdata2 または rvdata)
+ var rvdata2Path = Path.Combine(searchDir, "Data", "Scripts.rvdata2");
+ var rvdataPath = Path.Combine(searchDir, "Data", "Scripts.rvdata");
+
+ if (File.Exists(rvdata2Path))
+ {
+ scriptsPath = rvdata2Path;
+ if (engineType == TkoolEngineType.Unknown) engineType = TkoolEngineType.VXAce;
+ }
+ else if (File.Exists(rvdataPath))
+ {
+ scriptsPath = rvdataPath;
+ if (engineType == TkoolEngineType.Unknown) engineType = TkoolEngineType.VX;
+ }
+
+ // RGSS系でない場合はスキップ
+ if (engineType == TkoolEngineType.Unknown && archivePath == null && scriptsPath == null && gameIniPath == null)
+ {
+ return null;
+ }
+
+ if (engineType == TkoolEngineType.Unknown)
+ {
+ engineType = TkoolEngineType.VXAce;
+ }
+
+ // 実行ファイルの探索 (Game.exe、または searchDir 内の exe)
+ var exePath = FindRgssExecutable(searchDir, dirPath);
+ if (exePath == null)
+ {
+ return null;
+ }
+
+ var icon = LoadIcon(exePath, dirPath);
+ bool hasArchive = archivePath != null;
+ bool isExtracted = scriptsPath != null;
+ bool isModded = isExtracted && RgssModService.CheckIsModded(scriptsPath!);
+
+ var plannedScriptName = engineType == TkoolEngineType.VXAce ? "Scripts.rvdata2" : "Scripts.rvdata";
+ var plannedScriptPath = Path.Combine(searchDir, "Data", plannedScriptName);
+ var plannedDataDir = Path.Combine(searchDir, "Data");
+
+ return new TkoolGameItem
+ {
+ Title = !string.IsNullOrWhiteSpace(title) ? title : folderName,
+ FolderName = folderName,
+ RootDirectory = dirPath,
+ ExecutablePath = exePath,
+ PluginsJsPath = isExtracted ? scriptsPath! : plannedScriptPath,
+ PluginsDirPath = plannedDataDir,
+ EngineType = engineType,
+ IsModded = isModded,
+ ApplyMod = true,
+ IconImage = icon,
+ FolderLastModified = folderModified,
+ HasRgssArchive = hasArchive,
+ IsRgssExtracted = isExtracted,
+ RgssArchivePath = archivePath
+ };
+ }
+ catch { }
+
+ return null;
+ }
+
+ private static string? FindRgssExecutable(string searchDir, string rootDir)
+ {
+ try
+ {
+ var gameExe = Path.Combine(searchDir, "Game.exe");
+ if (File.Exists(gameExe)) return gameExe;
+
+ var rootGameExe = Path.Combine(rootDir, "Game.exe");
+ if (File.Exists(rootGameExe)) return rootGameExe;
+
+ var exes = Directory.GetFiles(searchDir, "*.exe", SearchOption.TopDirectoryOnly);
+ foreach (var exe in exes)
+ {
+ var name = Path.GetFileName(exe);
+ if (!name.Contains("unins", StringComparison.OrdinalIgnoreCase) &&
+ !name.Contains("extractor", StringComparison.OrdinalIgnoreCase) &&
+ !name.Contains("patch", StringComparison.OrdinalIgnoreCase))
+ {
+ return exe;
+ }
+ }
}
catch { }
diff --git a/Services/RgssModService.cs b/Services/RgssModService.cs
new file mode 100644
index 0000000..113d5d7
--- /dev/null
+++ b/Services/RgssModService.cs
@@ -0,0 +1,1131 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using GameLauncher.Helpers;
+using GameLauncher.Models;
+
+namespace GameLauncher.Services
+{
+ ///
+ /// ツクールVX / VX Ace の Scripts.rvdata2 / Scripts.rvdata 内の1つのスクリプト項目
+ ///
+ public class RgssScriptEntry
+ {
+ public int Id { get; set; }
+ public string Name { get; set; } = string.Empty;
+ public string Code { get; set; } = string.Empty;
+ }
+
+ ///
+ /// Ruby Marshal 4.8 形式で保存された ツクールVX/VX Ace スクリプトデータの
+ /// 解析・抽出・注入・再エンコードを行うヘルパークラス
+ ///
+ public static class RubyMarshalHelper
+ {
+ ///
+ /// Scripts.rvdata2 または Scripts.rvdata を読み込み、スクリプト一覧を取得します。
+ ///
+ public static List LoadScripts(string filePath)
+ {
+ var list = new List();
+ if (!File.Exists(filePath)) return list;
+
+ byte[] data = File.ReadAllBytes(filePath);
+ using var ms = new MemoryStream(data);
+ using var reader = new BinaryReader(ms);
+
+ if (ms.Length < 3) return list;
+
+ byte vMaj = reader.ReadByte();
+ byte vMin = reader.ReadByte();
+ if (vMaj != 4 || vMin != 8)
+ {
+ throw new InvalidDataException($"未対応の Ruby Marshal バージョンです: {vMaj}.{vMin}");
+ }
+
+ byte tag = reader.ReadByte();
+ if (tag != '[')
+ {
+ throw new InvalidDataException("ルート要素が Array ('[') ではありません。");
+ }
+
+ int count = ReadFixnum(reader);
+ for (int i = 0; i < count; i++)
+ {
+ byte subTag = reader.ReadByte();
+ if (subTag != '[') break;
+
+ int subCount = ReadFixnum(reader);
+
+ // 要素0: Fixnum Id
+ int id = ReadObjectAsInt(reader);
+
+ // 要素1: String Name
+ string name = ReadObjectAsString(reader);
+
+ // 要素2: String CompressedCode (zlib)
+ byte[] compBytes = ReadObjectAsBytes(reader);
+
+ string code = string.Empty;
+ if (compBytes.Length > 0)
+ {
+ try
+ {
+ code = DecompressZlib(compBytes);
+ }
+ catch
+ {
+ // 解凍失敗時は空文字
+ }
+ }
+
+ list.Add(new RgssScriptEntry
+ {
+ Id = id,
+ Name = name,
+ Code = code
+ });
+ }
+
+ return list;
+ }
+
+ ///
+ /// スクリプト一覧を Ruby Marshal 4.8 形式でシリアライズし、ファイルへ保存します。
+ ///
+ public static void SaveScripts(string filePath, List scripts)
+ {
+ using var ms = new MemoryStream();
+ using var writer = new BinaryWriter(ms);
+
+ // 1. Marshal ヘッダ (4.8)
+ writer.Write((byte)4);
+ writer.Write((byte)8);
+
+ // 2. ルート Array タグ '[' と要素数
+ writer.Write((byte)'[');
+ WriteFixnum(writer, scripts.Count);
+
+ // 3. 各スクリプト項目
+ foreach (var script in scripts)
+ {
+ // 各項目は [id, name, compressed_code] の 3要素配列
+ writer.Write((byte)'[');
+ WriteFixnum(writer, 3);
+
+ // 要素0: Fixnum Id
+ WriteObjectAsInt(writer, script.Id);
+
+ // 要素1: String Name
+ WriteObjectAsString(writer, script.Name);
+
+ // 要素2: String CompressedCode (zlib圧縮)
+ byte[] uncompressed = Encoding.UTF8.GetBytes(script.Code ?? string.Empty);
+ byte[] compressed = CompressZlib(uncompressed);
+ WriteObjectAsBytes(writer, compressed);
+ }
+
+ var dir = Path.GetDirectoryName(filePath);
+ if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
+ {
+ Directory.CreateDirectory(dir);
+ }
+
+ File.WriteAllBytes(filePath, ms.ToArray());
+ }
+
+ #region Marshal 内部リーダー / ライター
+
+ private static int ReadFixnum(BinaryReader reader)
+ {
+ sbyte b = reader.ReadSByte();
+ if (b == 0) return 0;
+ if (b > 0)
+ {
+ if (b > 4) return b - 5;
+ int len = b;
+ int res = 0;
+ for (int i = 0; i < len; i++) res |= (reader.ReadByte() << (8 * i));
+ return res;
+ }
+ else
+ {
+ if (b < -4) return b + 5;
+ int len = -b;
+ int res = -1;
+ for (int i = 0; i < len; i++)
+ {
+ res &= ~(0xFF << (8 * i));
+ res |= (reader.ReadByte() << (8 * i));
+ }
+ return res;
+ }
+ }
+
+ private static void WriteFixnum(BinaryWriter writer, int value)
+ {
+ if (value == 0)
+ {
+ writer.Write((sbyte)0);
+ }
+ else if (value > 0 && value < 123)
+ {
+ writer.Write((sbyte)(value + 5));
+ }
+ else if (value < 0 && value > -124)
+ {
+ writer.Write((sbyte)(value - 5));
+ }
+ else if (value > 0)
+ {
+ if (value <= 0xFF)
+ {
+ writer.Write((sbyte)1);
+ writer.Write((byte)value);
+ }
+ else if (value <= 0xFFFF)
+ {
+ writer.Write((sbyte)2);
+ writer.Write((ushort)value);
+ }
+ else if (value <= 0xFFFFFF)
+ {
+ writer.Write((sbyte)3);
+ writer.Write((byte)(value & 0xFF));
+ writer.Write((byte)((value >> 8) & 0xFF));
+ writer.Write((byte)((value >> 16) & 0xFF));
+ }
+ else
+ {
+ writer.Write((sbyte)4);
+ writer.Write(value);
+ }
+ }
+ else
+ {
+ // 負の大きな数
+ writer.Write((sbyte)-4);
+ writer.Write(value);
+ }
+ }
+
+ private static int ReadObjectAsInt(BinaryReader reader)
+ {
+ byte tag = reader.ReadByte();
+ if (tag == 'i') return ReadFixnum(reader);
+ reader.BaseStream.Position--;
+ return ReadFixnum(reader);
+ }
+
+ private static void WriteObjectAsInt(BinaryWriter writer, int value)
+ {
+ writer.Write((byte)'i');
+ WriteFixnum(writer, value);
+ }
+
+ private static string ReadObjectAsString(BinaryReader reader)
+ {
+ byte tag = reader.ReadByte();
+ if (tag == 'I')
+ {
+ reader.ReadByte(); // '"'
+ int len = ReadFixnum(reader);
+ byte[] strBytes = reader.ReadBytes(len);
+ int ivarCount = ReadFixnum(reader);
+ for (int k = 0; k < ivarCount; k++)
+ {
+ byte symTag = reader.ReadByte();
+ if (symTag == ':')
+ {
+ int symLen = ReadFixnum(reader);
+ reader.ReadBytes(symLen);
+ }
+ else if (symTag == ';')
+ {
+ ReadFixnum(reader);
+ }
+ byte valTag = reader.ReadByte();
+ if (valTag == 'T' || valTag == 'F') { }
+ else if (valTag == '"') { int l = ReadFixnum(reader); reader.ReadBytes(l); }
+ else if (valTag == 'i') { ReadFixnum(reader); }
+ }
+ return Encoding.UTF8.GetString(strBytes);
+ }
+ else if (tag == '"')
+ {
+ int len = ReadFixnum(reader);
+ byte[] strBytes = reader.ReadBytes(len);
+ return Encoding.UTF8.GetString(strBytes);
+ }
+ return string.Empty;
+ }
+
+ private static void WriteObjectAsString(BinaryWriter writer, string text)
+ {
+ byte[] bytes = Encoding.UTF8.GetBytes(text ?? string.Empty);
+ // インスタンス変数付きUTF-8文字列 (I"...\x06: \x06ET)
+ writer.Write((byte)'I');
+ writer.Write((byte)'"');
+ WriteFixnum(writer, bytes.Length);
+ writer.Write(bytes);
+ // 1つのインスタンス変数 (:E => true UTF-8)
+ WriteFixnum(writer, 1);
+ writer.Write((byte)':');
+ byte[] symE = Encoding.UTF8.GetBytes("E");
+ WriteFixnum(writer, symE.Length);
+ writer.Write(symE);
+ writer.Write((byte)'T'); // true
+ }
+
+ private static byte[] ReadObjectAsBytes(BinaryReader reader)
+ {
+ byte tag = reader.ReadByte();
+ if (tag == '"')
+ {
+ int len = ReadFixnum(reader);
+ return reader.ReadBytes(len);
+ }
+ else if (tag == 'I')
+ {
+ reader.ReadByte(); // '"'
+ int len = ReadFixnum(reader);
+ byte[] bytes = reader.ReadBytes(len);
+ int ivarCount = ReadFixnum(reader);
+ for (int k = 0; k < ivarCount; k++)
+ {
+ byte symTag = reader.ReadByte();
+ if (symTag == ':') { int l = ReadFixnum(reader); reader.ReadBytes(l); }
+ else if (symTag == ';') { ReadFixnum(reader); }
+ byte valTag = reader.ReadByte();
+ if (valTag == 'T' || valTag == 'F') { }
+ else if (valTag == '"') { int l = ReadFixnum(reader); reader.ReadBytes(l); }
+ else if (valTag == 'i') { ReadFixnum(reader); }
+ }
+ return bytes;
+ }
+ return [];
+ }
+
+ private static void WriteObjectAsBytes(BinaryWriter writer, byte[] data)
+ {
+ writer.Write((byte)'"');
+ WriteFixnum(writer, data.Length);
+ writer.Write(data);
+ }
+
+ #endregion
+
+ #region Zlib 圧縮 / 解凍 / Adler32
+
+ private static string DecompressZlib(byte[] data)
+ {
+ if (data == null || data.Length < 6) return string.Empty;
+
+ // 先頭2バイト(zlibヘッダ)と末尾4バイト(Adler32)を除いて raw deflate 解凍
+ using var ms = new MemoryStream(data, 2, data.Length - 6);
+ using var deflate = new DeflateStream(ms, CompressionMode.Decompress);
+ using var reader = new StreamReader(deflate, Encoding.UTF8);
+ return reader.ReadToEnd();
+ }
+
+ private static byte[] CompressZlib(byte[] uncompressed)
+ {
+ using var ms = new MemoryStream();
+ // 1. Zlib ヘッダ (0x78, 0x9C: Default Compression)
+ ms.WriteByte(0x78);
+ ms.WriteByte(0x9C);
+
+ // 2. Raw Deflate
+ using (var deflate = new DeflateStream(ms, CompressionLevel.Optimal, leaveOpen: true))
+ {
+ deflate.Write(uncompressed, 0, uncompressed.Length);
+ }
+
+ // 3. Adler-32 チェックサム (ビッグエンディアン)
+ uint adler = ComputeAdler32(uncompressed);
+ ms.WriteByte((byte)((adler >> 24) & 0xFF));
+ ms.WriteByte((byte)((adler >> 16) & 0xFF));
+ ms.WriteByte((byte)((adler >> 8) & 0xFF));
+ ms.WriteByte((byte)(adler & 0xFF));
+
+ return ms.ToArray();
+ }
+
+ private static uint ComputeAdler32(byte[] data)
+ {
+ const uint MOD_ADLER = 65521;
+ uint a = 1, b = 0;
+ for (int i = 0; i < data.Length; i++)
+ {
+ a = (a + data[i]) % MOD_ADLER;
+ b = (b + a) % MOD_ADLER;
+ }
+ return (b << 16) | a;
+ }
+
+ #endregion
+ }
+
+ ///
+ /// ツクールVX / VX Ace (RGSS2 / RGSS3) ゲームのMOD適用・解除・アーカイブ抽出を統括するサービス
+ ///
+ public class RgssModService
+ {
+ /// MODスクリプトのセクション名
+ public const string ModSectionName = "GameLauncher_Mod";
+
+ /// バックアップファイルのサフィックス
+ public const string BackupSuffix = ".original_launcher_backup";
+
+ ///
+ /// 指定されたスクリプトファイルに GameLauncher の改造スクリプトが含まれているか判定します。
+ ///
+ public static bool CheckIsModded(string scriptsFilePath)
+ {
+ if (string.IsNullOrEmpty(scriptsFilePath) || !File.Exists(scriptsFilePath))
+ {
+ return false;
+ }
+
+ try
+ {
+ var scripts = RubyMarshalHelper.LoadScripts(scriptsFilePath);
+ return scripts.Any(s => s.Name.Equals(ModSectionName, StringComparison.OrdinalIgnoreCase));
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ ///
+ /// ツクールVX/VX Aceゲームに対して、チェック状態に応じた改造の適用または復元を行います。
+ ///
+ public async Task<(bool Success, string Message)> ApplyOrRestoreModAsync(
+ TkoolGameItem game,
+ Dictionary? pluginSettings = null,
+ string? rgssExtractorPath = null)
+ {
+ if (game.ApplyMod)
+ {
+ return await ApplyModAsync(game, pluginSettings, rgssExtractorPath);
+ }
+ else
+ {
+ return RestoreOriginal(game);
+ }
+ }
+
+ ///
+ /// 改造スクリプトを適用します。
+ /// スクリプトファイルが未抽出の場合は自動でアーカイブから抽出します。
+ ///
+ public async Task<(bool Success, string Message)> ApplyModAsync(
+ TkoolGameItem game,
+ Dictionary? pluginSettings = null,
+ string? rgssExtractorPath = null)
+ {
+ try
+ {
+ var scriptsPath = game.PluginsJsPath;
+
+ // 1. スクリプトファイルが存在しない場合(RGSS暗号化アーカイブ内の場合)、自動抽出
+ if (string.IsNullOrEmpty(scriptsPath) || !File.Exists(scriptsPath))
+ {
+ var (extractSuccess, extractMsg) = await ExtractScriptsAsync(game, rgssExtractorPath);
+ if (!extractSuccess)
+ {
+ return (false, $"スクリプトの抽出に失敗したため改造を適用できませんでした: {extractMsg}");
+ }
+ scriptsPath = game.PluginsJsPath;
+ }
+
+ if (string.IsNullOrEmpty(scriptsPath) || !File.Exists(scriptsPath))
+ {
+ return (false, "スクリプトファイル (Scripts.rvdata2 または Scripts.rvdata) が見つかりません。");
+ }
+
+ // 2. バックアップの作成 (Backups フォルダへ保存)
+ var gameBackupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
+ var scriptFileName = Path.GetFileName(scriptsPath);
+ var backupPath = Path.Combine(gameBackupDir, scriptFileName + BackupSuffix);
+ var legacyBackupPath = scriptsPath + BackupSuffix;
+
+ if (!File.Exists(backupPath))
+ {
+ if (File.Exists(legacyBackupPath))
+ {
+ File.Copy(legacyBackupPath, backupPath, true);
+ }
+ else
+ {
+ // 現在のスクリプトを読み込み、MODセクションを除去したクリーンな状態でバックアップ
+ var currentScripts = RubyMarshalHelper.LoadScripts(scriptsPath);
+ currentScripts.RemoveAll(s => s.Name.Equals(ModSectionName, StringComparison.OrdinalIgnoreCase));
+ RubyMarshalHelper.SaveScripts(backupPath, currentScripts);
+ }
+ }
+
+ // 3. バックアップ(クリーン状態)を元に編集
+ var baseScripts = RubyMarshalHelper.LoadScripts(backupPath);
+ baseScripts.RemoveAll(s => s.Name.Equals(ModSectionName, StringComparison.OrdinalIgnoreCase));
+
+ // 4. 有効化するMOD項目の Ruby スクリプトコードを生成
+ string modRubyCode = BuildModScript(game, pluginSettings);
+
+ var modEntry = new RgssScriptEntry
+ {
+ Id = 99999999,
+ Name = ModSectionName,
+ Code = modRubyCode
+ };
+
+ // Main セクションの直前(Mainが無ければ末尾)に挿入
+ int mainIndex = baseScripts.FindIndex(s => s.Name.Equals("Main", StringComparison.OrdinalIgnoreCase) || s.Name.Contains("メイン"));
+ if (mainIndex >= 0)
+ {
+ baseScripts.Insert(mainIndex, modEntry);
+ }
+ else
+ {
+ baseScripts.Add(modEntry);
+ }
+
+ // 5. 書き込み保存
+ RubyMarshalHelper.SaveScripts(scriptsPath, baseScripts);
+
+ game.IsModded = true;
+ return (true, "ツクールVX/VX Ace用スクリプト改造を正常に適用しました。");
+ }
+ catch (Exception ex)
+ {
+ return (false, $"ツクールVX改造適用中にエラーが発生しました: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 改造を解除し、ゲームを改造前のオリジナル状態に復元します。
+ ///
+ public (bool Success, string Message) RestoreOriginal(TkoolGameItem game)
+ {
+ try
+ {
+ var scriptsPath = game.PluginsJsPath;
+ var gameBackupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
+ var scriptFileName = !string.IsNullOrEmpty(scriptsPath)
+ ? Path.GetFileName(scriptsPath)
+ : (game.EngineType == TkoolEngineType.VXAce ? "Scripts.rvdata2" : "Scripts.rvdata");
+
+ var backupPath = Path.Combine(gameBackupDir, scriptFileName + BackupSuffix);
+ var legacyBackupPath = !string.IsNullOrEmpty(scriptsPath) ? scriptsPath + BackupSuffix : null;
+
+ // 1. バックアップが存在する場合はバックアップから復元
+ if (File.Exists(backupPath))
+ {
+ if (!string.IsNullOrEmpty(scriptsPath))
+ {
+ File.Copy(backupPath, scriptsPath, true);
+ }
+ }
+ else if (legacyBackupPath != null && File.Exists(legacyBackupPath))
+ {
+ File.Copy(legacyBackupPath, scriptsPath!, true);
+ try { File.Copy(legacyBackupPath, backupPath, true); } catch { }
+ }
+ else if (!string.IsNullOrEmpty(scriptsPath) && File.Exists(scriptsPath))
+ {
+ // バックアップが無い場合、現在のファイルからMODセクションを除去
+ var currentScripts = RubyMarshalHelper.LoadScripts(scriptsPath);
+ currentScripts.RemoveAll(s => s.Name.Equals(ModSectionName, StringComparison.OrdinalIgnoreCase));
+ RubyMarshalHelper.SaveScripts(scriptsPath, currentScripts);
+ }
+
+ // ゲームフォルダ内の旧バックアップファイルを削除
+ if (legacyBackupPath != null && File.Exists(legacyBackupPath))
+ {
+ try { File.Delete(legacyBackupPath); } catch { }
+ }
+
+ // 2. もし元々アーカイブのみのゲーム(初回にスクリプトのみを新規抽出して実ファイル配置しただけ)の場合、
+ // 配置したスクリプトを安全に削除すれば、ゲームは再び完全な暗号化アーカイブ起動状態に戻る
+ if (game.HasRgssArchive && !string.IsNullOrEmpty(scriptsPath) && File.Exists(scriptsPath))
+ {
+ var isNewlyExtractedFlag = Path.Combine(gameBackupDir, ".extracted_by_launcher");
+ if (File.Exists(isNewlyExtractedFlag))
+ {
+ try
+ {
+ File.Delete(scriptsPath);
+ File.Delete(isNewlyExtractedFlag);
+ game.IsRgssExtracted = false;
+ game.PluginsJsPath = string.Empty;
+
+ var dataDir = Path.GetDirectoryName(scriptsPath);
+ if (!string.IsNullOrEmpty(dataDir) && Directory.Exists(dataDir) && Directory.GetFileSystemEntries(dataDir).Length == 0)
+ {
+ try { Directory.Delete(dataDir); } catch { }
+ }
+ }
+ catch { }
+ }
+ }
+
+ game.IsModded = false;
+ return (true, "ツクールVXゲームを改造前のオリジナル状態に正常に復元しました。");
+ }
+ catch (Exception ex)
+ {
+ return (false, $"復元中にエラーが発生しました: {ex.Message}");
+ }
+ }
+
+ ///
+ /// アーカイブから Scripts.rvdata2 または Scripts.rvdata を抽出します。
+ /// 内蔵アンパッカーを使用し、高速かつ確実に抽出します。
+ ///
+ public async Task<(bool Success, string Message)> ExtractScriptsAsync(TkoolGameItem game, string? rgssExtractorPath)
+ {
+ return await Task.Run(() =>
+ {
+ try
+ {
+ var archivePath = game.RgssArchivePath;
+ if (string.IsNullOrEmpty(archivePath) || !File.Exists(archivePath))
+ {
+ // ルートフォルダからアーカイブを探索
+ var candidates = Directory.GetFiles(game.RootDirectory, "*.rgss*a", SearchOption.TopDirectoryOnly);
+ if (candidates.Length > 0)
+ {
+ archivePath = candidates[0];
+ game.RgssArchivePath = archivePath;
+ }
+ }
+
+ if (string.IsNullOrEmpty(archivePath) || !File.Exists(archivePath))
+ {
+ return (false, "RGSSアーカイブ (*.rgss3a / *.rgss2a) が見つかりません。");
+ }
+
+ var targetScriptName = game.EngineType == TkoolEngineType.VXAce ? "Scripts.rvdata2" : "Scripts.rvdata";
+ var dataDir = Path.Combine(game.RootDirectory, "Data");
+ if (!Directory.Exists(dataDir))
+ {
+ Directory.CreateDirectory(dataDir);
+ }
+ var destScriptPath = Path.Combine(dataDir, targetScriptName);
+
+ // 1. RGSS Extractor.exe が設定されている場合は、確実な外部ツール抽出(インメモリリフレクション)を最優先で実行
+ bool extracted = false;
+ if (!string.IsNullOrEmpty(rgssExtractorPath) && File.Exists(rgssExtractorPath))
+ {
+ extracted = ExtractUsingRgssExtractorExe(rgssExtractorPath, archivePath, targetScriptName, destScriptPath);
+ }
+
+ // 2. 外部ツールがない、または抽出に失敗した場合は C# 内蔵高速アンパッカーを実行
+ if (!extracted)
+ {
+ extracted = ExtractSingleFileFromRgssArchive(archivePath, targetScriptName, destScriptPath);
+ }
+
+ if (!extracted || !File.Exists(destScriptPath))
+ {
+ return (false, $"アーカイブ内から {targetScriptName} を抽出できませんでした。");
+ }
+
+ game.PluginsJsPath = destScriptPath;
+ game.PluginsDirPath = dataDir;
+ game.IsRgssExtracted = true;
+
+ // 当ランチャーによって新規抽出されたことを示すマーカーを Backups フォルダに記録(復元時の完全クリーンアップ用)
+ var gameBackupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
+ var marker = Path.Combine(gameBackupDir, ".extracted_by_launcher");
+ try { File.WriteAllText(marker, DateTime.Now.ToString("o")); } catch { }
+
+ // クリーンな抽出スクリプトを直ちに Backups フォルダにバックアップ
+ var backupPath = Path.Combine(gameBackupDir, targetScriptName + BackupSuffix);
+ if (!File.Exists(backupPath))
+ {
+ try { File.Copy(destScriptPath, backupPath, true); } catch { }
+ }
+
+ return (true, $"{targetScriptName} の抽出が完了しました。(ゲームの Data フォルダに配置完了)");
+ }
+ catch (Exception ex)
+ {
+ return (false, $"スクリプト抽出中にエラーが発生しました: {ex.Message}");
+ }
+ });
+ }
+
+ #region RGSS アンパッカー (内蔵実装)
+
+ ///
+ /// RGSS3A / RGSS2A / RGSSAD アーカイブから指定ファイル(Scripts.rvdata2 等)をピンポイントで抽出します。
+ ///
+ private static bool ExtractSingleFileFromRgssArchive(string archivePath, string targetFileName, string destinationPath)
+ {
+ try
+ {
+ using var fs = new FileStream(archivePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+ using var br = new BinaryReader(fs);
+
+ if (fs.Length < 16) return false;
+
+ byte[] header = br.ReadBytes(8);
+ string magic = Encoding.ASCII.GetString(header, 0, 6);
+ if (!magic.Equals("RGSSAD", StringComparison.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+
+ byte ver = header[7]; // 3: RGSS3A (VX Ace), 1: RGSSAD (XP/VX)
+
+ if (ver == 3)
+ {
+ // RGSS3A (ツクールVX Ace)
+ uint magicKey = br.ReadUInt32();
+ magicKey = magicKey * 9 + 3;
+
+ while (fs.Position < fs.Length)
+ {
+ uint offset = br.ReadUInt32() ^ magicKey;
+ uint size = br.ReadUInt32() ^ magicKey;
+ uint dataKey = br.ReadUInt32() ^ magicKey;
+ uint nameLen = br.ReadUInt32() ^ magicKey;
+
+ if (offset == 0) break;
+
+ byte[] nameBytes = br.ReadBytes((int)nameLen);
+ for (int i = 0; i < nameBytes.Length; i++)
+ {
+ nameBytes[i] ^= (byte)((magicKey >> (8 * (i % 4))) & 0xFF);
+ }
+ string entryName = Encoding.UTF8.GetString(nameBytes);
+
+ if (entryName.EndsWith(targetFileName, StringComparison.OrdinalIgnoreCase) ||
+ Path.GetFileName(entryName).Equals(targetFileName, StringComparison.OrdinalIgnoreCase))
+ {
+ // 該当ファイル発見!データを読み取り復号
+ long currentPos = fs.Position;
+ fs.Seek(offset, SeekOrigin.Begin);
+
+ byte[] fileData = br.ReadBytes((int)size);
+ uint key = dataKey;
+ for (int i = 0; i < fileData.Length; i++)
+ {
+ fileData[i] ^= (byte)(key & 0xFF);
+ if (i % 4 == 3)
+ {
+ key = key * 7 + 3;
+ }
+ }
+
+ var destDir = Path.GetDirectoryName(destinationPath);
+ if (!string.IsNullOrEmpty(destDir) && !Directory.Exists(destDir))
+ {
+ Directory.CreateDirectory(destDir);
+ }
+
+ File.WriteAllBytes(destinationPath, fileData);
+ return true;
+ }
+ }
+ }
+ else
+ {
+ // RGSSAD (ツクールXP / VX)
+ uint key = 0xDEADCAFE;
+ while (fs.Position < fs.Length)
+ {
+ if (fs.Position + 4 > fs.Length) break;
+ int nameLen = (int)(br.ReadUInt32() ^ key);
+ key = key * 7 + 3;
+
+ if (nameLen <= 0 || nameLen > 1024 || fs.Position + nameLen > fs.Length) break;
+
+ byte[] nameBytes = br.ReadBytes(nameLen);
+ for (int i = 0; i < nameLen; i++)
+ {
+ nameBytes[i] ^= (byte)(key & 0xFF);
+ key = key * 7 + 3;
+ }
+ string entryName = Encoding.UTF8.GetString(nameBytes);
+
+ uint size = br.ReadUInt32() ^ key;
+ key = key * 7 + 3;
+
+ long dataOffset = fs.Position;
+
+ if (entryName.EndsWith(targetFileName, StringComparison.OrdinalIgnoreCase) ||
+ Path.GetFileName(entryName).Equals(targetFileName, StringComparison.OrdinalIgnoreCase))
+ {
+ byte[] fileData = br.ReadBytes((int)size);
+ uint dKey = key;
+ for (int i = 0; i < fileData.Length; i++)
+ {
+ fileData[i] ^= (byte)(dKey & 0xFF);
+ dKey = dKey * 7 + 3;
+ }
+
+ var destDir = Path.GetDirectoryName(destinationPath);
+ if (!string.IsNullOrEmpty(destDir) && !Directory.Exists(destDir))
+ {
+ Directory.CreateDirectory(destDir);
+ }
+
+ File.WriteAllBytes(destinationPath, fileData);
+ return true;
+ }
+ else
+ {
+ // スキップ
+ fs.Seek(size, SeekOrigin.Current);
+ }
+ }
+ }
+ }
+ catch
+ {
+ // 解析失敗時はフォールバック
+ }
+
+ return false;
+ }
+
+ ///
+ ///
+ /// 外部ツール RGSS Extractor.exe を利用して抽出し、生成物を配置します。
+ /// .NET アセンブリであるため、まずはインメモリで直接 Main_Parser を呼び出して高速・無音で抽出し、
+ /// フォールバックとしてプロセス起動による抽出を行います。
+ ///
+ private static bool ExtractUsingRgssExtractorExe(string exePath, string archivePath, string targetFileName, string destinationPath)
+ {
+ try
+ {
+ if (File.Exists(exePath))
+ {
+ // 1. .NET リフレクションによる直接インメモリ高速抽出
+ try
+ {
+ var asm = System.Reflection.Assembly.LoadFrom(exePath);
+ var parserType = asm.GetType("RGSS_Extractor.Main_Parser");
+ if (parserType != null)
+ {
+ var parser = Activator.CreateInstance(parserType);
+ var parseFileMethod = parserType.GetMethod("parse_file", new[] { typeof(string) });
+ var getFileDataMethod = parserType.GetMethod("get_filedata");
+ var closeFileMethod = parserType.GetMethod("close_file");
+
+ if (parseFileMethod != null && getFileDataMethod != null && parser != null)
+ {
+ var entries = parseFileMethod.Invoke(parser, new object[] { archivePath }) as System.Collections.IEnumerable;
+ if (entries != null)
+ {
+ foreach (var entry in entries)
+ {
+ var nameProp = entry.GetType().GetProperty("name") ?? (System.Reflection.MemberInfo?)entry.GetType().GetField("name");
+ string? entryName = null;
+ if (nameProp is System.Reflection.PropertyInfo pi) entryName = pi.GetValue(entry) as string;
+ else if (nameProp is System.Reflection.FieldInfo fi) entryName = fi.GetValue(entry) as string;
+
+ if (!string.IsNullOrEmpty(entryName) &&
+ (entryName.EndsWith(targetFileName, StringComparison.OrdinalIgnoreCase) ||
+ Path.GetFileName(entryName).Equals(targetFileName, StringComparison.OrdinalIgnoreCase)))
+ {
+ var fileBytes = getFileDataMethod.Invoke(parser, new object[] { entry }) as byte[];
+ if (fileBytes != null && fileBytes.Length > 0)
+ {
+ closeFileMethod?.Invoke(parser, null);
+
+ var destDir = Path.GetDirectoryName(destinationPath);
+ if (!string.IsNullOrEmpty(destDir) && !Directory.Exists(destDir))
+ {
+ Directory.CreateDirectory(destDir);
+ }
+ File.WriteAllBytes(destinationPath, fileBytes);
+ return true;
+ }
+ }
+ }
+ }
+ closeFileMethod?.Invoke(parser, null);
+ }
+ }
+ }
+ catch { }
+
+ // 2. フォールバック: プロセス起動による抽出
+ var toolDir = Path.GetDirectoryName(exePath) ?? AppDomain.CurrentDomain.BaseDirectory;
+ var psi = new ProcessStartInfo
+ {
+ FileName = exePath,
+ Arguments = $"\"{archivePath}\"",
+ WorkingDirectory = toolDir,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ };
+
+ using var proc = Process.Start(psi);
+ if (proc != null)
+ {
+ proc.WaitForExit(30000); // 最大30秒待機
+ }
+
+ // RGSS Extractor はツール自身のフォルダ配下に Data\Scripts.rvdata2 等を出力
+ var possibleOutput = Path.Combine(toolDir, "Data", targetFileName);
+ if (File.Exists(possibleOutput))
+ {
+ var destDir = Path.GetDirectoryName(destinationPath);
+ if (!string.IsNullOrEmpty(destDir) && !Directory.Exists(destDir))
+ {
+ Directory.CreateDirectory(destDir);
+ }
+ File.Copy(possibleOutput, destinationPath, true);
+ try { File.Delete(possibleOutput); } catch { }
+ return true;
+ }
+ }
+ }
+ catch { }
+
+ return false;
+ }
+
+ #endregion
+
+ #region Ruby MOD スクリプト生成
+
+ ///
+ /// 有効化された各MOD設定に応じた Ruby スクリプトコードを生成します。
+ ///
+ public static string BuildModScript(TkoolGameItem game, Dictionary? pluginSettings)
+ {
+ var sb = new StringBuilder();
+ sb.AppendLine("#==============================================================================");
+ sb.AppendLine("# ■ GameLauncher 自動生成 MOD スクリプト (ツクールVX / VX Ace用)");
+ sb.AppendLine($"# 生成日時: {DateTime.Now:yyyy/MM/dd HH:mm:ss}");
+ sb.AppendLine("#==============================================================================");
+ sb.AppendLine();
+
+ bool isAce = game.EngineType == TkoolEngineType.VXAce;
+
+ // 1. 移動速度アップ&常時ダッシュ
+ if (game.IsPluginEnabled("RgssDashSpeedUp", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- 移動速度高速化&常時オートダッシュ ---
+class Game_Player < Game_Character
+ alias org_gl_move_speed move_speed
+ def move_speed
+ return 5
+ end
+
+ alias org_gl_dash? dash?
+ def dash?
+ return false if @move_route_forcing
+ return false if $game_map && $game_map.disable_dash?
+ return false if (respond_to?(:vehicle) && vehicle)
+ return true
+ end
+end
+");
+ }
+
+ // 2. アイテム入手時 99個固定化
+ if (game.IsPluginEnabled("RgssItemGainMax", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- アイテム入手時 99個固定化 ---
+class Game_Party < Game_Unit
+ alias org_gl_gain_item gain_item
+ def gain_item(item, amount, include_equip = false)
+ if item && amount > 0
+ amount = 99
+ end
+ org_gl_gain_item(item, amount, include_equip)
+ end
+end
+");
+ }
+
+ // 3. アイテム消費なし
+ if (game.IsPluginEnabled("RgssItemNoConsume", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- アイテム消費なし ---
+class Game_Party < Game_Unit
+ alias org_gl_consume_item consume_item
+ def consume_item(item)
+ # 消費処理をスキップ(何もしない)
+ end
+end
+");
+ }
+
+ // 4. 獲得ゴールド最大化
+ if (game.IsPluginEnabled("RgssGoldGainMax", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- 獲得ゴールド最大化 ---
+class Game_Troop < Game_Unit
+ alias org_gl_gold_total gold_total
+ def gold_total
+ return 999999
+ end
+end
+");
+ }
+
+ // 5. 獲得経験値最大化
+ if (game.IsPluginEnabled("RgssExpGainMax", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- 獲得経験値最大化 ---
+class Game_Troop < Game_Unit
+ alias org_gl_exp_total exp_total
+ def exp_total
+ return 999999
+ end
+end
+");
+ }
+
+ // 6. 戦闘ターン開始時 全回復 (HP)
+ if (game.IsPluginEnabled("RgssBattleTurnRecoverHp", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- 戦闘中ターン全回復 (HP) ---
+class Game_Actor < Game_Battler
+ alias org_gl_on_turn_end_hp on_turn_end
+ def on_turn_end
+ org_gl_on_turn_end_hp
+ begin
+ self.hp = self.mhp if respond_to?(:mhp) && respond_to?(:hp=)
+ rescue
+ end
+ end
+end
+");
+ }
+
+ // 7. 戦闘ターン開始時 全回復 (MP)
+ if (game.IsPluginEnabled("RgssBattleTurnRecoverMp", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- 戦闘中ターン全回復 (MP) ---
+class Game_Actor < Game_Battler
+ alias org_gl_on_turn_end_mp on_turn_end
+ def on_turn_end
+ org_gl_on_turn_end_mp
+ begin
+ self.mp = self.mmp if respond_to?(:mmp) && respond_to?(:mp=)
+ rescue
+ end
+ end
+end
+");
+ }
+
+ // 8. 戦闘ターン開始時 全回復 (TP) - VX Ace専用
+ if (isAce && game.IsPluginEnabled("RgssBattleTurnRecoverTp", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- 戦闘中ターン全回復 (TP) ---
+class Game_Actor < Game_Battler
+ alias org_gl_on_turn_end_tp on_turn_end
+ def on_turn_end
+ org_gl_on_turn_end_tp
+ begin
+ self.tp = self.max_tp if respond_to?(:max_tp) && respond_to?(:tp=)
+ rescue
+ end
+ end
+end
+");
+ }
+
+ // 9. メッセージ瞬間表示・超高速化
+ if (game.IsPluginEnabled("RgssMessageInstant", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- メッセージ瞬間表示・ウェイト短縮 ---
+class Window_Message < Window_Base
+ # 1文字送りのウェイトをスキップ
+ def wait_for_one_character
+ end
+
+ # 通常ウェイトの短縮
+ alias org_gl_wait wait
+ def wait(duration)
+ # ウェイト時間を大幅短縮
+ org_gl_wait([duration / 3, 1].max)
+ end
+end
+");
+ }
+
+ // 10. コマンド位置記憶 (ツクールMV風)
+ if (game.IsPluginEnabled("RgssCommandMemory", pluginSettings, true))
+ {
+ sb.AppendLine(@"# --- コマンド位置記憶スクリプト ---
+class Game_System
+ def menu_command_index
+ @menu_command_index ||= 0
+ end
+ attr_writer :menu_command_index
+end
+
+class Game_Actor < Game_Battler
+ def last_command_index
+ @last_command_index ||= 0
+ end
+ attr_writer :last_command_index
+end
+
+class Window_MenuCommand < Window_Command
+ alias org_gl_select_last select_last
+ def select_last
+ if $game_system && $game_system.menu_command_index < item_max
+ select($game_system.menu_command_index)
+ else
+ org_gl_select_last rescue nil
+ end
+ end
+end
+
+class Scene_Menu < Scene_MenuBase
+ alias org_gl_terminate_cmd_mem terminate
+ def terminate
+ org_gl_terminate_cmd_mem
+ if $game_system && @command_window
+ $game_system.menu_command_index = @command_window.index
+ end
+ end
+end
+
+class Window_ActorCommand < Window_Command
+ alias org_gl_idx_set index=
+ def index=(idx)
+ org_gl_idx_set(idx)
+ if @actor && @actor_command_updating
+ @actor.last_command_index = self.index
+ end
+ end
+
+ alias org_gl_setup_cmd_mem setup
+ def setup(actor)
+ @actor_command_updating = false
+ org_gl_setup_cmd_mem(actor)
+ if @actor
+ idx = @actor.last_command_index
+ idx = 0 if idx >= item_max
+ select(idx)
+ end
+ @actor_command_updating = true
+ end
+end
+");
+ }
+
+ return sb.ToString();
+ }
+
+ #endregion
+ }
+}
diff --git a/Services/TkoolModService.cs b/Services/TkoolModService.cs
index b76a800..215357c 100644
--- a/Services/TkoolModService.cs
+++ b/Services/TkoolModService.cs
@@ -178,15 +178,25 @@ namespace GameLauncher.Services
Directory.CreateDirectory(pluginsDir);
}
- var backupPath = pluginsJsPath + BackupSuffix;
+ var gameBackupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
+ var backupPath = Path.Combine(gameBackupDir, "plugins.js" + BackupSuffix);
+ var legacyBackupPath = pluginsJsPath + BackupSuffix;
- // 1. バックアップが存在しない場合、バックアップを作成する
+ // 1. バックアップが存在しない場合、バックアップを作成する (Backups フォルダに保存)
if (!File.Exists(backupPath))
{
- string currentContent = File.ReadAllText(pluginsJsPath, Encoding.UTF8);
- // 既に改造プラグイン(新旧問わず)が埋め込まれている場合はクリーンアップしたものをバックアップとして保持
- string cleanContent = CleanManagedPluginsFromContent(currentContent);
- File.WriteAllText(backupPath, cleanContent, new UTF8Encoding(false));
+ if (File.Exists(legacyBackupPath))
+ {
+ // 既存のゲーム内バックアップがあれば Backups フォルダへコピー
+ File.Copy(legacyBackupPath, backupPath, true);
+ }
+ else
+ {
+ string currentContent = File.ReadAllText(pluginsJsPath, Encoding.UTF8);
+ // 既に改造プラグイン(新旧問わず)が埋め込まれている場合はクリーンアップしたものをバックアップとして保持
+ string cleanContent = CleanManagedPluginsFromContent(currentContent);
+ File.WriteAllText(backupPath, cleanContent, new UTF8Encoding(false));
+ }
}
// 2. バックアップ(クリーン状態)を元に編集を開始
@@ -245,7 +255,9 @@ namespace GameLauncher.Services
{
var pluginsJsPath = game.PluginsJsPath;
var pluginsDir = game.PluginsDirPath;
- var backupPath = pluginsJsPath + BackupSuffix;
+ var gameBackupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
+ var backupPath = Path.Combine(gameBackupDir, "plugins.js" + BackupSuffix);
+ var legacyBackupPath = pluginsJsPath + BackupSuffix;
// 1. バックアップが存在する場合はバックアップから復元(再構築を通すことで壊れたバックアップも修復)
if (File.Exists(backupPath))
@@ -254,6 +266,14 @@ namespace GameLauncher.Services
string cleanContent = RebuildPluginsJs(backupContent, null);
File.WriteAllText(pluginsJsPath, cleanContent, new UTF8Encoding(false));
}
+ else if (File.Exists(legacyBackupPath))
+ {
+ string backupContent = File.ReadAllText(legacyBackupPath, Encoding.UTF8);
+ string cleanContent = RebuildPluginsJs(backupContent, null);
+ File.WriteAllText(pluginsJsPath, cleanContent, new UTF8Encoding(false));
+ // Backups フォルダへもコピー
+ try { File.Copy(legacyBackupPath, backupPath, true); } catch { }
+ }
else
{
// バックアップがなくても、現在の plugins.js から新旧すべての管理プラグインを綺麗に除去
@@ -276,6 +296,12 @@ namespace GameLauncher.Services
}
}
+ // 3. ゲームフォルダ内の旧バックアップファイルがあれば削除してBackupsフォルダに一本化
+ if (File.Exists(legacyBackupPath))
+ {
+ try { File.Delete(legacyBackupPath); } catch { }
+ }
+
game.IsModded = false;
return (true, "ゲームを改造前のオリジナル状態に正常に復元しました。(旧プラグインも完全削除済み)");
}
diff --git a/Services/TyranoModService.cs b/Services/TyranoModService.cs
index 2c22e25..8913908 100644
--- a/Services/TyranoModService.cs
+++ b/Services/TyranoModService.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
+using GameLauncher.Helpers;
using GameLauncher.Models;
namespace GameLauncher.Services
@@ -69,15 +70,24 @@ namespace GameLauncher.Services
try
{
var dir = Path.GetDirectoryName(indexPath)!;
- var backupPath = indexPath + IndexBackupSuffix;
+ var gameBackupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
+ var backupPath = Path.Combine(gameBackupDir, "index.html" + IndexBackupSuffix);
+ var legacyBackupPath = indexPath + IndexBackupSuffix;
- // 1. バックアップの作成(存在しない場合)
+ // 1. バックアップの作成(存在しない場合、Backups フォルダに保存)
if (!File.Exists(backupPath))
{
- string originalContent = File.ReadAllText(indexPath, Encoding.UTF8);
- // 既にタグが含まれていた場合は除去したものをバックアップとする
- string cleanContent = RemoveScriptTag(originalContent);
- File.WriteAllText(backupPath, cleanContent, new UTF8Encoding(false));
+ if (File.Exists(legacyBackupPath))
+ {
+ File.Copy(legacyBackupPath, backupPath, true);
+ }
+ else
+ {
+ string originalContent = File.ReadAllText(indexPath, Encoding.UTF8);
+ // 既にタグが含まれていた場合は除去したものをバックアップとする
+ string cleanContent = RemoveScriptTag(originalContent);
+ File.WriteAllText(backupPath, cleanContent, new UTF8Encoding(false));
+ }
}
// 2. 有効化する機能の判定
@@ -121,14 +131,21 @@ namespace GameLauncher.Services
try
{
var dir = Path.GetDirectoryName(indexPath)!;
- var backupPath = indexPath + IndexBackupSuffix;
+ var gameBackupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
+ var backupPath = Path.Combine(gameBackupDir, "index.html" + IndexBackupSuffix);
+ var legacyBackupPath = indexPath + IndexBackupSuffix;
var modJsPath = Path.Combine(dir, ModScriptFileName);
- // 1. index.html の復元
+ // 1. index.html の復元 (Backups フォルダを優先)
if (File.Exists(backupPath))
{
File.Copy(backupPath, indexPath, true);
}
+ else if (File.Exists(legacyBackupPath))
+ {
+ File.Copy(legacyBackupPath, indexPath, true);
+ try { File.Copy(legacyBackupPath, backupPath, true); } catch { }
+ }
else if (File.Exists(indexPath))
{
string content = File.ReadAllText(indexPath, Encoding.UTF8);
@@ -136,6 +153,12 @@ namespace GameLauncher.Services
File.WriteAllText(indexPath, clean, new UTF8Encoding(false));
}
+ // ゲームフォルダ内の旧バックアップがあれば削除
+ if (File.Exists(legacyBackupPath))
+ {
+ try { File.Delete(legacyBackupPath); } catch { }
+ }
+
// 2. tyrano_launcher_mod.js の削除
if (File.Exists(modJsPath))
{
diff --git a/publish.ps1 b/publish.ps1
index 925bdbc..6838a98 100644
--- a/publish.ps1
+++ b/publish.ps1
@@ -14,7 +14,7 @@ if (!(Test-Path $publishDir)) {
Write-Host 'プロジェクトのビルドおよび単一ファイル発行中...' -ForegroundColor Yellow
-dotnet publish "$projectDir\GameLauncher.csproj" -c Release -r win-x64 --self-contained false -o $publishDir
+dotnet publish "$projectDir\GameLauncher.csproj" -c Release -r win-x64 --self-contained false -p:PublishSingleFile=true -p:PublishDir="$publishDir\"
if ($LASTEXITCODE -eq 0) {
# プラグインおよび設定ファイルの配置