using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Windows; using System.Windows.Media; namespace GameLauncher.Models { /// /// 各プラグイン改造の個別有効/無効オプション(互換用) /// public class ModPluginOptions : System.ComponentModel.INotifyPropertyChanged { private bool _speedUp = true; private bool _antigravityGameTweaks = true; private bool _dropItem99 = true; private bool _turnStartFullRecover = true; private bool _turnStartFullRecoverHp = true; private bool _turnStartFullRecoverMp = true; private bool _turnStartFullRecoverTp = true; private bool _maxGainGold = true; private bool _maxGainExp = true; private bool _instantMessage = true; public bool SpeedUp { get => _speedUp; set { if (_speedUp != value) { _speedUp = value; OnPropertyChanged(); } } } public bool AntigravityGameTweaks { get => _antigravityGameTweaks; set { if (_antigravityGameTweaks != value) { _antigravityGameTweaks = value; OnPropertyChanged(); } } } public bool DropItem99 { get => _dropItem99; set { if (_dropItem99 != value) { _dropItem99 = value; OnPropertyChanged(); } } } public bool TurnStartFullRecover { get => _turnStartFullRecover; set { if (_turnStartFullRecover != value) { _turnStartFullRecover = value; OnPropertyChanged(); } } } public bool TurnStartFullRecoverHp { get => _turnStartFullRecoverHp; set { if (_turnStartFullRecoverHp != value) { _turnStartFullRecoverHp = value; OnPropertyChanged(); } } } public bool TurnStartFullRecoverMp { get => _turnStartFullRecoverMp; set { if (_turnStartFullRecoverMp != value) { _turnStartFullRecoverMp = value; OnPropertyChanged(); } } } public bool TurnStartFullRecoverTp { get => _turnStartFullRecoverTp; set { if (_turnStartFullRecoverTp != value) { _turnStartFullRecoverTp = value; OnPropertyChanged(); } } } public bool MaxGainGold { get => _maxGainGold; set { if (_maxGainGold != value) { _maxGainGold = value; OnPropertyChanged(); } } } public bool MaxGainExp { get => _maxGainExp; set { if (_maxGainExp != value) { _maxGainExp = value; OnPropertyChanged(); } } } public bool InstantMessage { get => _instantMessage; set { if (_instantMessage != value) { _instantMessage = value; OnPropertyChanged(); } } } public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged; protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? name = null) { PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(name)); } } /// /// ツクールおよびティラノスクリプトゲームのデータモデル /// public class TkoolGameItem : GameItemBase { private string _pluginsJsPath = string.Empty; private string _pluginsDirPath = string.Empty; private TkoolEngineType _engineType = TkoolEngineType.Unknown; private bool _isModded; private bool _applyMod = true; private bool _hasCustomApplyMod; private bool _isInitializingApplyMod; private ModPluginOptions _modOptions = new(); // app.asar 関連プロパティ private bool _isAsar; private bool _isAsarExtracted; private string? _asarPath; private string? _asarExtractedDirPath; private string? _relativePluginsJsInAsar; public override GameEngineKind EngineKind => EngineType == TkoolEngineType.Tyrano ? GameEngineKind.Tyrano : GameEngineKind.Tkool; public string PluginsJsPath { get => _pluginsJsPath; set { if (_pluginsJsPath != value) { _pluginsJsPath = value; OnPropertyChanged(); } } } public string PluginsDirPath { get => _pluginsDirPath; set { if (_pluginsDirPath != value) { _pluginsDirPath = value; OnPropertyChanged(); } } } public override bool IsMV => EngineType == TkoolEngineType.MV; public override bool IsMZ => EngineType == TkoolEngineType.MZ; public override bool IsTyrano => EngineType == TkoolEngineType.Tyrano; public TkoolEngineType EngineType { get => _engineType; set { if (_engineType != value) { _engineType = value; OnPropertyChanged(); OnPropertyChanged(nameof(EngineKind)); OnPropertyChanged(nameof(EngineDisplayName)); OnPropertyChanged(nameof(IsMV)); OnPropertyChanged(nameof(IsMZ)); OnPropertyChanged(nameof(IsTyrano)); } } } public override bool IsModded { get => _isModded; set { if (_isModded != value) { _isModded = value; OnPropertyChanged(); } } } public bool HasCustomApplyMod { get => _hasCustomApplyMod; set { if (_hasCustomApplyMod != value) { _hasCustomApplyMod = value; OnPropertyChanged(); } } } public override bool ApplyMod { get => _applyMod; set { if (_applyMod != value) { _applyMod = value; if (!_isInitializingApplyMod) { HasCustomApplyMod = true; } OnPropertyChanged(); } } } public void SetDefaultApplyMod(bool defaultVal) { if (!_hasCustomApplyMod) { _isInitializingApplyMod = true; _applyMod = defaultVal; _isInitializingApplyMod = false; OnPropertyChanged(nameof(ApplyMod)); } } public override bool IsAsar { get => _isAsar; set { if (_isAsar != value) { _isAsar = value; OnPropertyChanged(); OnPropertyChanged(nameof(AsarBadgeVisibility)); OnPropertyChanged(nameof(AsarBadgeText)); OnPropertyChanged(nameof(AsarBadgeBackground)); OnPropertyChanged(nameof(AsarDetailStatusText)); } } } public override bool IsAsarExtracted { get => _isAsarExtracted; set { if (_isAsarExtracted != value) { _isAsarExtracted = value; OnPropertyChanged(); OnPropertyChanged(nameof(AsarBadgeText)); OnPropertyChanged(nameof(AsarBadgeBackground)); OnPropertyChanged(nameof(AsarDetailStatusText)); } } } public string? AsarPath { get => _asarPath; set { if (_asarPath != value) { _asarPath = value; OnPropertyChanged(); } } } public string? AsarExtractedDirPath { get => _asarExtractedDirPath; set { if (_asarExtractedDirPath != value) { _asarExtractedDirPath = value; OnPropertyChanged(); } } } public string? RelativePluginsJsInAsar { get => _relativePluginsJsInAsar; set { if (_relativePluginsJsInAsar != value) { _relativePluginsJsInAsar = value; OnPropertyChanged(); } } } public override Visibility AsarBadgeVisibility => IsAsar ? Visibility.Visible : Visibility.Collapsed; public override string AsarBadgeText => !IsAsar ? string.Empty : (IsAsarExtracted ? "ASAR (解凍済)" : "ASAR (圧縮)"); public override Brush AsarBadgeBackground => IsAsarExtracted ? new SolidColorBrush(Color.FromRgb(0x00, 0x89, 0x7B)) : new SolidColorBrush(Color.FromRgb(0x5E, 0x35, 0xB1)); public override string AsarDetailStatusText => !IsAsar ? string.Empty : (IsAsarExtracted ? "📦 app.asar 形式(解凍済み・改造可能)" : "📦 app.asar 形式(圧縮中・起動時またはボタンで解凍可能)"); private Dictionary _pluginSettings = new(StringComparer.OrdinalIgnoreCase); private ObservableCollection _pluginOptions = []; public Dictionary PluginSettings { get => _pluginSettings; set { if (_pluginSettings != value) { _pluginSettings = value; OnPropertyChanged(); } } } public override ObservableCollection PluginOptions { get => _pluginOptions; set { if (_pluginOptions != value) { _pluginOptions = value; OnPropertyChanged(); } } } public bool IsPluginEnabled(string pluginId, Dictionary? defaultSettings = null, bool fallbackVal = true) { if (_pluginSettings.TryGetValue(pluginId, out var val)) { return val; } if (pluginId is "BattleTurnRecoverHp" or "BattleTurnRecoverMp" or "BattleTurnRecoverTp") { if (_pluginSettings.TryGetValue("BattleTurnRecover", out var legacyVal)) { return legacyVal; } } if (defaultSettings != null && defaultSettings.TryGetValue(pluginId, out var defVal)) { return defVal; } if (pluginId is "BattleTurnRecoverHp" or "BattleTurnRecoverMp" or "BattleTurnRecoverTp") { if (defaultSettings != null && defaultSettings.TryGetValue("BattleTurnRecover", out var legacyDefVal)) { return legacyDefVal; } } return fallbackVal; } public static readonly ModPluginDefinition[] DefaultTyranoPlugins = [ new() { Id = "TyranoUnlockAllCg", Name = "🔓 全CG・全回想の全開放", Description = "システム変数(sf)のCG・回想フラグを全開放し、最初からCG・シーン鑑賞を可能にします。" }, new() { Id = "TyranoFastMessage", Name = "⚡ メッセージ超高速化・演出ウェイト短縮", Description = "文字送り速度を最大化し、[wait]演出の停止時間を短縮して快適にスキップ可能にします。" }, new() { Id = "TyranoDevTools", Name = "🛠 開発者ツール (F12) の有効化", Description = "F12キーでブラウザ・アプリの開発者ツールコンソールを開けるようにします。" }, new() { Id = "TyranoCheatMenu", Name = "🎛 画面上変数(f)チートエディタ表示", Description = "画面右上にボタンを配置し、ゲーム内変数・フラグの閲覧と直接書き換えができるメニューを表示します。" } ]; public void SyncPluginOptions(IEnumerable availablePlugins, Dictionary? defaultSettings = null) { _pluginOptions.Clear(); var targetDefs = EngineType == TkoolEngineType.Tyrano ? DefaultTyranoPlugins : availablePlugins; foreach (var def in targetDefs) { bool isEnabled = IsPluginEnabled(def.Id, defaultSettings, fallbackVal: true); var item = new ModPluginOptionItem { Definition = def, IsEnabled = isEnabled }; item.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(ModPluginOptionItem.IsEnabled)) { _pluginSettings[def.Id] = item.IsEnabled; } }; _pluginOptions.Add(item); } } public ModPluginOptions ModOptions { get => _modOptions; set { if (_modOptions != value) { _modOptions = value; OnPropertyChanged(); } } } public string EngineDisplayName => EngineType switch { TkoolEngineType.MV => "RPGツクールMV", TkoolEngineType.MZ => "RPGツクールMZ", TkoolEngineType.Tyrano => "ティラノスクリプト", _ => "ツクール/ティラノ" }; } }