機能追加: Bakin・NW.jsエンジンおよびセーブ編集対応、ES3パスワード解決機能とRPGツクールMZ修正サービスの追加
This commit is contained in:
1 parent
f50976a6c0
commit
152abae1f8
33 files changed
+11356
-175
No files matched your search
@@ -105,6 +105,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
private bool _applyMod = true;
|
||||
private bool _hasCustomApplyMod;
|
||||
private bool _isInitializingApplyMod;
|
||||
private bool _hasSaveData;
|
||||
private ModPluginOptions _modOptions = new();
|
||||
|
||||
// app.asar 関連プロパティ
|
||||
@@ -130,6 +131,20 @@ namespace GameLauncher.Engines.Tkool
|
||||
private string? _evbBackupPath;
|
||||
private string _evbUnderlyingEngine = string.Empty;
|
||||
|
||||
/// <summary>セーブデータ検出フラグ</summary>
|
||||
public override bool HasSaveData
|
||||
{
|
||||
get => this._hasSaveData;
|
||||
set
|
||||
{
|
||||
if (this._hasSaveData != value)
|
||||
{
|
||||
this._hasSaveData = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Enigma Virtual Box でパックされた exe を持つゲームかどうか</summary>
|
||||
public override bool IsEvbPacked
|
||||
{
|
||||
@@ -306,6 +321,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
TkoolEngineType.Wolf => GameEngineKind.Wolf,
|
||||
TkoolEngineType.SrpgStudio => GameEngineKind.SrpgStudio,
|
||||
TkoolEngineType.Nwjs => GameEngineKind.Nwjs,
|
||||
TkoolEngineType.Bakin => GameEngineKind.Bakin,
|
||||
TkoolEngineType.Other => GameEngineKind.Other,
|
||||
_ => GameEngineKind.Tkool
|
||||
};
|
||||
@@ -331,17 +347,18 @@ namespace GameLauncher.Engines.Tkool
|
||||
public override bool IsSrpgStudio => this.EngineType == TkoolEngineType.SrpgStudio;
|
||||
public override bool IsRgss => this.EngineType is TkoolEngineType.VX or TkoolEngineType.VXAce;
|
||||
public override bool IsNwjs => this.EngineType == TkoolEngineType.Nwjs;
|
||||
public override bool IsBakin => this.EngineType == TkoolEngineType.Bakin;
|
||||
public override bool IsOther => this.EngineType == TkoolEngineType.Other;
|
||||
|
||||
/// <summary>
|
||||
/// スクリプト改造(プラグイン注入など)が適用可能な状態かどうか。
|
||||
/// 該当ゲームが改造非対応(ウディタ・SRPG・NW.js・その他・未解凍状態など)の場合は false を返します。
|
||||
/// 該当ゲームが改造非対応(ウディタ・SRPG・Bakin・NW.js・その他・未解凍状態など)の場合は false を返します。
|
||||
/// </summary>
|
||||
public override bool CanApplyScriptMod
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsWolf || this.IsNwjs || this.IsSrpgStudio || this.IsOther)
|
||||
if (this.IsWolf || this.IsSrpgStudio || this.IsBakin || this.IsOther)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -365,7 +382,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
}
|
||||
return !string.IsNullOrEmpty(this.PluginsJsPath) && File.Exists(this.PluginsJsPath);
|
||||
}
|
||||
if (this.IsMV || this.IsMZ || this.IsTyrano)
|
||||
if (this.IsMV || this.IsMZ || this.IsTyrano || this.IsNwjs)
|
||||
{
|
||||
return !string.IsNullOrEmpty(this.PluginsJsPath) && File.Exists(this.PluginsJsPath);
|
||||
}
|
||||
@@ -385,6 +402,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
TkoolEngineType.Tyrano => "ティラノ",
|
||||
TkoolEngineType.Wolf => "ウディタ",
|
||||
TkoolEngineType.SrpgStudio => "SRPG",
|
||||
TkoolEngineType.Bakin => "Bakin",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
@@ -398,6 +416,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
TkoolEngineType.Tyrano => new SolidColorBrush(Color.FromRgb(0xD3, 0x54, 0x00)),
|
||||
TkoolEngineType.Wolf => new SolidColorBrush(Color.FromRgb(0x8B, 0x57, 0x1E)),
|
||||
TkoolEngineType.SrpgStudio => new SolidColorBrush(Color.FromRgb(0x1E, 0x7A, 0x5F)),
|
||||
TkoolEngineType.Bakin => new SolidColorBrush(Color.FromRgb(0xD9, 0x77, 0x06)),
|
||||
_ => Brushes.Transparent
|
||||
};
|
||||
|
||||
@@ -562,6 +581,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
this.OnPropertyChanged(nameof(this.IsSrpgStudio));
|
||||
this.OnPropertyChanged(nameof(this.IsRgss));
|
||||
this.OnPropertyChanged(nameof(this.IsNwjs));
|
||||
this.OnPropertyChanged(nameof(this.IsBakin));
|
||||
this.OnPropertyChanged(nameof(this.IsOther));
|
||||
this.OnPropertyChanged(nameof(this.NwjsBadgeText));
|
||||
this.OnPropertyChanged(nameof(this.NwjsBadgeVisibility));
|
||||
@@ -583,6 +603,44 @@ namespace GameLauncher.Engines.Tkool
|
||||
}
|
||||
}
|
||||
|
||||
// ================= ツクールMZ関連プロパティ =================
|
||||
private bool _mzPixiErrorFix = true;
|
||||
private bool _mzSpineErrorFix = true;
|
||||
|
||||
/// <summary>
|
||||
/// ツクールMZ専用: Pixi.jsのテクスチャ参照エラー(Cannot read property 'valid' of null)修復およびDevTools有効化フラグ。
|
||||
/// 初期値は true(チェックON)
|
||||
/// </summary>
|
||||
public override bool MzPixiErrorFix
|
||||
{
|
||||
get => this._mzPixiErrorFix;
|
||||
set
|
||||
{
|
||||
if (this._mzPixiErrorFix != value)
|
||||
{
|
||||
this._mzPixiErrorFix = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ツクールMZ専用: Spineアニメーション未定義エラー(Animation not found: 0_idle 等)修復フラグ。
|
||||
/// 初期値は true(チェックON)
|
||||
/// </summary>
|
||||
public override bool MzSpineErrorFix
|
||||
{
|
||||
get => this._mzSpineErrorFix;
|
||||
set
|
||||
{
|
||||
if (this._mzSpineErrorFix != value)
|
||||
{
|
||||
this._mzSpineErrorFix = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ================= WOLF RPGエディター関連プロパティ =================
|
||||
private bool _wolfProxyDll = false;
|
||||
private double _wolfSpeedMultiplier = 3.0;
|
||||
@@ -919,6 +977,15 @@ namespace GameLauncher.Engines.Tkool
|
||||
new() { Id = "RgssWindowResizeExternal", Name = "🪟 外部ツールでウィンドウ拡大 (Win32 API / Sizer等)", Description = "ゲーム側は無改造のまま、ランチャーがゲームウィンドウを検出してディスプレイに収まる最大の整数倍へ拡大します。外部ツールパス設定があればそちらを優先起動します。(既定OFF)" }
|
||||
];
|
||||
|
||||
/// <summary>NW.js (GameCreator / HTML5・JS) 用スクリプト改造定義一覧</summary>
|
||||
public static readonly ModPluginDefinition[] DefaultNwjsPlugins =
|
||||
[
|
||||
new() { Id = "NwjsCheatMenu", Name = "🎛 ゲーム内ステータス・変数・所持金チートメニュー ([F10] / 画面右上ボタン)", Description = "画面右上の『⚙ チート [F10]』ボタンまたはF10キーで、所持金・ステータス・変数・スイッチ・所持アイテムをリアルタイムに検索・書き換えできるオーバーレイメニューを表示します(GameCreator / HTML5ステート / 汎用NW.js自動認識)。" },
|
||||
new() { Id = "NwjsSpeedHack", Name = "⚡ ゲーム倍速・高速化ショートカット ([F6] 倍速切替 / [Ctrl] 5倍速ブースト)", Description = "F6キーでゲーム速度を 1x → 2x → 3x → 5x に切り替え、Ctrlキー押下中は一時的に5倍速へ加速します(LayaAir/GameCreatorタイマー・アニメーション・動画再生速度対応)。" },
|
||||
new() { Id = "NwjsUnlockGallery", Name = "🔓 全CG・ギャラリー・回想フラグの自動解放", Description = "GalleryStoreやGameCreatorのワールド永続スイッチ(life.gcdata)、localStorage内のギャラリー・回想解放フラグを解放します。" },
|
||||
new() { Id = "NwjsDevTools", Name = "🛠 開発者ツール (F12) の有効化", Description = "F12キーでNW.js / Chromiumの開発者ツールコンソールを開けるようにします。" }
|
||||
];
|
||||
|
||||
/// <summary>SRPG Studio用スクリプト改造定義一覧</summary>
|
||||
public static readonly ModPluginDefinition[] DefaultSrpgPlugins =
|
||||
[
|
||||
@@ -936,14 +1003,18 @@ namespace GameLauncher.Engines.Tkool
|
||||
this._commonPluginOptions.Clear();
|
||||
this._specificPluginOptions.Clear();
|
||||
|
||||
if (this.EngineType is TkoolEngineType.Wolf or TkoolEngineType.Nwjs)
|
||||
if (this.EngineType is TkoolEngineType.Wolf or TkoolEngineType.Bakin or TkoolEngineType.Other)
|
||||
{
|
||||
this.OnPropertyChanged(nameof(this.HasSpecificPlugins));
|
||||
return;
|
||||
}
|
||||
|
||||
IEnumerable<ModPluginDefinition> targetDefs;
|
||||
if (this.EngineType == TkoolEngineType.Tyrano)
|
||||
if (this.IsNwjs)
|
||||
{
|
||||
targetDefs = TkoolGameItem.DefaultNwjsPlugins;
|
||||
}
|
||||
else if (this.EngineType == TkoolEngineType.Tyrano)
|
||||
{
|
||||
targetDefs = DefaultTyranoPlugins;
|
||||
}
|
||||
@@ -1032,6 +1103,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
TkoolEngineType.Wolf => "WOLF RPGエディター",
|
||||
TkoolEngineType.SrpgStudio => "SRPG Studio",
|
||||
TkoolEngineType.Nwjs => "NW.js",
|
||||
TkoolEngineType.Bakin => "RPG Developer Bakin",
|
||||
_ => "ツクール/ティラノ"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace GameLauncher.Engines.Tkool
|
||||
// ※ResourceLoaderFix はリソース読み込み不具合の必須救済プラグインのため、常に有効化・先頭配置
|
||||
var fixPlugin = this._availablePlugins.FirstOrDefault(p => string.Equals(p.Id, "ResourceLoaderFix", StringComparison.OrdinalIgnoreCase));
|
||||
var pluginsToEnable = this._availablePlugins
|
||||
.Where(p => string.Equals(p.Id, "ResourceLoaderFix", StringComparison.OrdinalIgnoreCase) || game.IsPluginEnabled(p.Id, defaultSettings, fallbackVal: true))
|
||||
.Where(p => string.Equals(p.Id, "ResourceLoaderFix", StringComparison.OrdinalIgnoreCase) || game.IsPluginEnabled(p.Id, defaultSettings, fallbackVal: p.DefaultEnabled))
|
||||
.ToList();
|
||||
|
||||
// ResourceLoaderFix を最優先(先頭)に配置して、他プラグイン実行前のリソース要求も確実に救済
|
||||
|
||||
@@ -0,0 +1,747 @@
|
||||
// Engines/Tkool/TkoolMzFixService.cs
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace GameLauncher.Engines.Tkool
|
||||
{
|
||||
/// <summary>
|
||||
/// RPGツクールMZ専用のPixi.js・Spineエラー修復およびDevTools有効化サービス。
|
||||
/// マップ移動時に発生する Pixi.js の "Cannot read property 'valid' of null" クラッシュ、
|
||||
/// および Spine の "Animation not found" クラッシュを防止し、開発者ツール(DevTools)の制限を解除します。
|
||||
/// </summary>
|
||||
public static class TkoolMzFixService
|
||||
{
|
||||
#region □定数(Private)
|
||||
|
||||
private const string BackupSuffix = ".bak";
|
||||
private const string SpineFixMarker = "/* GameLauncher_SpineFix */";
|
||||
|
||||
#endregion
|
||||
|
||||
#region □メソッド(Public)
|
||||
|
||||
/// <summary>
|
||||
/// 指定されたゲームディレクトリに対して、Pixi.js のエラー修復および DevTools 有効化を適用します。
|
||||
/// </summary>
|
||||
/// <param name="rootDir">ゲームのルートディレクトリ</param>
|
||||
/// <returns>処理成否およびメッセージ</returns>
|
||||
public static (bool Success, string Message) ApplyMzPixiFix(string rootDir)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rootDir) || !Directory.Exists(rootDir))
|
||||
{
|
||||
return (false, "ゲームディレクトリが存在しません。");
|
||||
}
|
||||
|
||||
int patchedCount = 0;
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// 1. package.json の --disable-devtools 除去
|
||||
var packageJsonPath = Path.Combine(rootDir, "package.json");
|
||||
if (File.Exists(packageJsonPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (PatchPackageJson(packageJsonPath))
|
||||
{
|
||||
patchedCount++;
|
||||
sb.Append("DevTools有効化, ");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append($"package.json修復失敗({ex.Message}), ");
|
||||
}
|
||||
}
|
||||
|
||||
// 2. js/libs/pixi.js の null安全パッチ適用
|
||||
var pixiJsPath = Path.Combine(rootDir, "js", "libs", "pixi.js");
|
||||
if (File.Exists(pixiJsPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (PatchPixiJs(pixiJsPath))
|
||||
{
|
||||
patchedCount++;
|
||||
sb.Append("pixi.js安全化, ");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append($"pixi.js修復失敗({ex.Message}), ");
|
||||
}
|
||||
}
|
||||
|
||||
// 3. js/libs/pixi-picture.js の null安全パッチ適用
|
||||
var pixiPicturePath = Path.Combine(rootDir, "js", "libs", "pixi-picture.js");
|
||||
if (File.Exists(pixiPicturePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (PatchPixiPictureJs(pixiPicturePath))
|
||||
{
|
||||
patchedCount++;
|
||||
sb.Append("pixi-picture.js安全化, ");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append($"pixi-picture.js修復失敗({ex.Message}), ");
|
||||
}
|
||||
}
|
||||
|
||||
if (patchedCount > 0)
|
||||
{
|
||||
var summary = sb.ToString().TrimEnd(' ', ',');
|
||||
return (true, $"ツクールMZ修復パッチを適用しました: [{summary}]");
|
||||
}
|
||||
|
||||
return (true, "ツクールMZ修復パッチは既に適用済みです。");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// バックアップファイルからオリジナル状態への復元を行います。
|
||||
/// </summary>
|
||||
/// <param name="rootDir">ゲームのルートディレクトリ</param>
|
||||
/// <returns>処理成否およびメッセージ</returns>
|
||||
public static (bool Success, string Message) RestoreMzPixiFix(string rootDir)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rootDir) || !Directory.Exists(rootDir))
|
||||
{
|
||||
return (false, "ゲームディレクトリが存在しません。");
|
||||
}
|
||||
|
||||
int restoredCount = 0;
|
||||
|
||||
// 1. package.json の復元
|
||||
var packageJsonPath = Path.Combine(rootDir, "package.json");
|
||||
var packageJsonBak = packageJsonPath + BackupSuffix;
|
||||
if (File.Exists(packageJsonBak))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(packageJsonBak, packageJsonPath, true);
|
||||
restoredCount++;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// 2. js/libs/pixi.js の復元
|
||||
var pixiJsPath = Path.Combine(rootDir, "js", "libs", "pixi.js");
|
||||
var pixiJsBak = pixiJsPath + BackupSuffix;
|
||||
if (File.Exists(pixiJsBak))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(pixiJsBak, pixiJsPath, true);
|
||||
restoredCount++;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// 3. js/libs/pixi-picture.js の復元
|
||||
var pixiPicturePath = Path.Combine(rootDir, "js", "libs", "pixi-picture.js");
|
||||
var pixiPictureBak = pixiPicturePath + BackupSuffix;
|
||||
if (File.Exists(pixiPictureBak))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(pixiPictureBak, pixiPicturePath, true);
|
||||
restoredCount++;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return (true, $"ツクールMZ修復パッチを元に戻しました(復元ファイル数: {restoredCount})");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定されたゲームディレクトリに対して、Spineアニメーション未定義エラー(Animation not found 等)の修復パッチを適用します。
|
||||
/// </summary>
|
||||
/// <param name="rootDir">ゲームのルートディレクトリ</param>
|
||||
/// <returns>処理成否およびメッセージ</returns>
|
||||
public static (bool Success, string Message) ApplyMzSpineFix(string rootDir)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rootDir) || !Directory.Exists(rootDir))
|
||||
{
|
||||
return (false, "ゲームディレクトリが存在しません。");
|
||||
}
|
||||
|
||||
bool hasTargetFile = false;
|
||||
int patchedCount = 0;
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// 1. js/libs/pixi-spine.js の未定義アニメーション安全化パッチ適用
|
||||
var pixiSpinePath = Path.Combine(rootDir, "js", "libs", "pixi-spine.js");
|
||||
if (File.Exists(pixiSpinePath))
|
||||
{
|
||||
hasTargetFile = true;
|
||||
try
|
||||
{
|
||||
if (PatchPixiSpineJs(pixiSpinePath))
|
||||
{
|
||||
patchedCount++;
|
||||
sb.Append("pixi-spine.js安全化, ");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append($"pixi-spine.js修復失敗({ex.Message}), ");
|
||||
}
|
||||
}
|
||||
|
||||
// 2. js/plugins/PictureSpine.js のスケルトン整合・null安全化パッチ適用
|
||||
var pictureSpinePath = Path.Combine(rootDir, "js", "plugins", "PictureSpine.js");
|
||||
if (File.Exists(pictureSpinePath))
|
||||
{
|
||||
hasTargetFile = true;
|
||||
try
|
||||
{
|
||||
if (PatchPictureSpineJs(pictureSpinePath))
|
||||
{
|
||||
patchedCount++;
|
||||
sb.Append("PictureSpine.js安全化, ");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append($"PictureSpine.js修復失敗({ex.Message}), ");
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasTargetFile)
|
||||
{
|
||||
return (true, string.Empty);
|
||||
}
|
||||
|
||||
if (patchedCount > 0)
|
||||
{
|
||||
var summary = sb.ToString().TrimEnd(' ', ',');
|
||||
return (true, $"ツクールMZ Spine修復パッチを適用しました: [{summary}]");
|
||||
}
|
||||
|
||||
return (true, "ツクールMZ Spine修復パッチは既に適用済みです。");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spine修復パッチのバックアップファイルからオリジナル状態への復元を行います。
|
||||
/// </summary>
|
||||
/// <param name="rootDir">ゲームのルートディレクトリ</param>
|
||||
/// <returns>処理成否およびメッセージ</returns>
|
||||
public static (bool Success, string Message) RestoreMzSpineFix(string rootDir)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rootDir) || !Directory.Exists(rootDir))
|
||||
{
|
||||
return (false, "ゲームディレクトリが存在しません。");
|
||||
}
|
||||
|
||||
int restoredCount = 0;
|
||||
|
||||
var pixiSpinePath = Path.Combine(rootDir, "js", "libs", "pixi-spine.js");
|
||||
var pixiSpineBak = pixiSpinePath + BackupSuffix;
|
||||
if (File.Exists(pixiSpineBak))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(pixiSpineBak, pixiSpinePath, true);
|
||||
restoredCount++;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
var pictureSpinePath = Path.Combine(rootDir, "js", "plugins", "PictureSpine.js");
|
||||
var pictureSpineBak = pictureSpinePath + BackupSuffix;
|
||||
if (File.Exists(pictureSpineBak))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(pictureSpineBak, pictureSpinePath, true);
|
||||
restoredCount++;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
if (restoredCount == 0)
|
||||
{
|
||||
return (true, string.Empty);
|
||||
}
|
||||
|
||||
return (true, $"ツクールMZ Spine修復パッチを元に戻しました(復元ファイル数: {restoredCount})");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region □メソッド(Private)
|
||||
|
||||
private static bool PatchPackageJson(string path)
|
||||
{
|
||||
string content = File.ReadAllText(path, Encoding.UTF8);
|
||||
if (!content.Contains("--disable-devtools"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var bakPath = path + BackupSuffix;
|
||||
if (!File.Exists(bakPath))
|
||||
{
|
||||
File.Copy(path, bakPath, true);
|
||||
}
|
||||
|
||||
string updated = content.Replace("--disable-devtools", string.Empty);
|
||||
updated = updated.Replace(" ", " ");
|
||||
File.WriteAllText(path, updated, new UTF8Encoding(true));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool PatchPixiJs(string path)
|
||||
{
|
||||
string content = File.ReadAllText(path, Encoding.UTF8);
|
||||
bool modified = false;
|
||||
|
||||
var bakPath = path + BackupSuffix;
|
||||
if (!File.Exists(bakPath))
|
||||
{
|
||||
File.Copy(path, bakPath, true);
|
||||
}
|
||||
|
||||
// A. AbstractBatchRenderer.prototype.render
|
||||
if (content.Contains("if (!element._texture.valid) {"))
|
||||
{
|
||||
content = content.Replace("if (!element._texture.valid) {", "if (!element || !element._texture || !element._texture.valid) {");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// B. SpriteMaskFilter.prototype.apply
|
||||
if (content.Contains("var maskSprite = this.maskSprite;\n\t var tex = maskSprite._texture;\n\t if (!tex.valid) {"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"var maskSprite = this.maskSprite;\n\t var tex = maskSprite._texture;\n\t if (!tex.valid) {",
|
||||
"var maskSprite = this.maskSprite;\n\t var tex = maskSprite ? maskSprite._texture : null;\n\t if (!tex || !tex.valid) {");
|
||||
modified = true;
|
||||
}
|
||||
else if (content.Contains("var maskSprite = this.maskSprite;\r\n\t var tex = maskSprite._texture;\r\n\t if (!tex.valid) {"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"var maskSprite = this.maskSprite;\r\n\t var tex = maskSprite._texture;\r\n\t if (!tex.valid) {",
|
||||
"var maskSprite = this.maskSprite;\r\n\t var tex = maskSprite ? maskSprite._texture : null;\r\n\t if (!tex || !tex.valid) {");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// C. Texture constructor
|
||||
if (content.Contains("if (!baseTexture.valid) {\n\t baseTexture.once('loaded', _this.onBaseTextureUpdated, _this);"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (!baseTexture.valid) {\n\t baseTexture.once('loaded', _this.onBaseTextureUpdated, _this);",
|
||||
"if (!baseTexture || !baseTexture.valid) {\n\t if (baseTexture) baseTexture.once('loaded', _this.onBaseTextureUpdated, _this);");
|
||||
modified = true;
|
||||
}
|
||||
else if (content.Contains("if (!baseTexture.valid) {\r\n\t baseTexture.once('loaded', _this.onBaseTextureUpdated, _this);"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (!baseTexture.valid) {\r\n\t baseTexture.once('loaded', _this.onBaseTextureUpdated, _this);",
|
||||
"if (!baseTexture || !baseTexture.valid) {\r\n\t if (baseTexture) baseTexture.once('loaded', _this.onBaseTextureUpdated, _this);");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// D. Texture.prototype.onBaseTextureUpdated
|
||||
if (content.Contains("if (!this.baseTexture.valid) {"))
|
||||
{
|
||||
content = content.Replace("if (!this.baseTexture.valid) {", "if (!this.baseTexture || !this.baseTexture.valid) {");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// E. Graphics
|
||||
if (content.Contains("if (fill && !fill.texture.baseTexture.valid)"))
|
||||
{
|
||||
content = content.Replace("if (fill && !fill.texture.baseTexture.valid)", "if (fill && (!fill.texture || !fill.texture.baseTexture || !fill.texture.baseTexture.valid))");
|
||||
modified = true;
|
||||
}
|
||||
if (content.Contains("if (line && !line.texture.baseTexture.valid)"))
|
||||
{
|
||||
content = content.Replace("if (line && !line.texture.baseTexture.valid)", "if (line && (!line.texture || !line.texture.baseTexture || !line.texture.baseTexture.valid))");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// F. Sprite.prototype texture setter
|
||||
if (content.Contains("if (value.baseTexture.valid) {\n\t this._onTextureUpdate();\n\t }\n\t else {\n\t value.once('update', this._onTextureUpdate, this);"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (value.baseTexture.valid) {\n\t this._onTextureUpdate();\n\t }\n\t else {\n\t value.once('update', this._onTextureUpdate, this);",
|
||||
"if (value.baseTexture && value.baseTexture.valid) {\n\t this._onTextureUpdate();\n\t }\n\t else if (value.baseTexture) {\n\t value.once('update', this._onTextureUpdate, this);");
|
||||
modified = true;
|
||||
}
|
||||
else if (content.Contains("if (value.baseTexture.valid) {\r\n\t this._onTextureUpdate();\r\n\t }\r\n\t else {\r\n\t value.once('update', this._onTextureUpdate, this);"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (value.baseTexture.valid) {\r\n\t this._onTextureUpdate();\r\n\t }\r\n\t else {\r\n\t value.once('update', this._onTextureUpdate, this);",
|
||||
"if (value.baseTexture && value.baseTexture.valid) {\r\n\t this._onTextureUpdate();\r\n\t }\r\n\t else if (value.baseTexture) {\r\n\t value.once('update', this._onTextureUpdate, this);");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// H. Texture constructor: baseTexture null safety (Cannot read property 'on' of null)
|
||||
if (content.Contains("if (baseTexture instanceof Texture) {\n\t baseTexture = baseTexture.baseTexture;\n\t }"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (baseTexture instanceof Texture) {\n\t baseTexture = baseTexture.baseTexture;\n\t }",
|
||||
"if (baseTexture instanceof Texture) {\n\t baseTexture = baseTexture.baseTexture;\n\t }\n\t if (!baseTexture) {\n\t baseTexture = new BaseTexture();\n\t }");
|
||||
modified = true;
|
||||
}
|
||||
else if (content.Contains("if (baseTexture instanceof Texture) {\r\n\t baseTexture = baseTexture.baseTexture;\r\n\t }"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (baseTexture instanceof Texture) {\r\n\t baseTexture = baseTexture.baseTexture;\r\n\t }",
|
||||
"if (baseTexture instanceof Texture) {\r\n\t baseTexture = baseTexture.baseTexture;\r\n\t }\r\n\t if (!baseTexture) {\r\n\t baseTexture = new BaseTexture();\r\n\t }");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// I. Texture constructor: noFrame on update safety
|
||||
if (content.Contains("if (_this.noFrame) {\n\t baseTexture.on('update', _this.onBaseTextureUpdated, _this);\n\t }"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (_this.noFrame) {\n\t baseTexture.on('update', _this.onBaseTextureUpdated, _this);\n\t }",
|
||||
"if (_this.noFrame && baseTexture) {\n\t baseTexture.on('update', _this.onBaseTextureUpdated, _this);\n\t }");
|
||||
modified = true;
|
||||
}
|
||||
else if (content.Contains("if (_this.noFrame) {\r\n\t baseTexture.on('update', _this.onBaseTextureUpdated, _this);\r\n\t }"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (_this.noFrame) {\r\n\t baseTexture.on('update', _this.onBaseTextureUpdated, _this);\r\n\t }",
|
||||
"if (_this.noFrame && baseTexture) {\r\n\t baseTexture.on('update', _this.onBaseTextureUpdated, _this);\r\n\t }");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// G. Mesh.prototype texture setter
|
||||
if (content.Contains("if (value.baseTexture.valid) {\n\t this.textureUpdated();\n\t }\n\t else {\n\t value.once('update', this.textureUpdated, this);"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (value.baseTexture.valid) {\n\t this.textureUpdated();\n\t }\n\t else {\n\t value.once('update', this.textureUpdated, this);",
|
||||
"if (value && value.baseTexture && value.baseTexture.valid) {\n\t this.textureUpdated();\n\t }\n\t else if (value && value.baseTexture) {\n\t value.once('update', this.textureUpdated, this);");
|
||||
modified = true;
|
||||
}
|
||||
else if (content.Contains("if (value.baseTexture.valid) {\r\n\t this.textureUpdated();\r\n\t }\r\n\t else {\r\n\t value.once('update', this.textureUpdated, this);"))
|
||||
{
|
||||
content = content.Replace(
|
||||
"if (value.baseTexture.valid) {\r\n\t this.textureUpdated();\r\n\t }\r\n\t else {\r\n\t value.once('update', this.textureUpdated, this);",
|
||||
"if (value && value.baseTexture && value.baseTexture.valid) {\r\n\t this.textureUpdated();\r\n\t }\r\n\t else if (value && value.baseTexture) {\r\n\t value.once('update', this.textureUpdated, this);");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified)
|
||||
{
|
||||
File.WriteAllText(path, content, new UTF8Encoding(true));
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
private static bool PatchPixiPictureJs(string path)
|
||||
{
|
||||
string content = File.ReadAllText(path, Encoding.UTF8);
|
||||
if (!content.Contains("if (!sprite.texture.valid) {"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var bakPath = path + BackupSuffix;
|
||||
if (!File.Exists(bakPath))
|
||||
{
|
||||
File.Copy(path, bakPath, true);
|
||||
}
|
||||
|
||||
string updated = content.Replace("if (!sprite.texture.valid) {", "if (!sprite || !sprite.texture.valid) {");
|
||||
File.WriteAllText(path, updated, new UTF8Encoding(true));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool PatchPixiSpineJs(string path)
|
||||
{
|
||||
string content = File.ReadAllText(path, Encoding.UTF8);
|
||||
if (content.Contains(SpineFixMarker))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string updated = content;
|
||||
bool modified = false;
|
||||
|
||||
const string setAnimReplacement =
|
||||
"var animation = this.data.skeletonData.findAnimation(animationName);\n" +
|
||||
" if (!animation) {\n" +
|
||||
" animation = typeof __glResolveSpineAnim === \"function\" ? __glResolveSpineAnim(this, trackIndex, animationName) : null;\n" +
|
||||
" if (!animation) {\n" +
|
||||
" if (typeof console !== \"undefined\" && console.warn) { console.warn(\"[GameLauncher SpineFix] Animation not found, using empty:\", animationName, \"track:\", trackIndex); }\n" +
|
||||
" return typeof this.setEmptyAnimation === \"function\" ? this.setEmptyAnimation(trackIndex, 0) : null;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" return this.setAnimationWith(trackIndex, animation, loop);";
|
||||
|
||||
var setAnimRegex = new Regex(
|
||||
@"(?:var|let|const)\s+animation\s*=\s*this\.data\.skeletonData\.findAnimation\(animationName\);\s*if\s*\(\s*(?:animation\s*==\s*null|!animation)\s*\)\s*\{?\s*throw\s+new\s+Error\([""']Animation not found:\s*[""']\s*\+\s*animationName\);\s*\}?\s*return\s+this\.setAnimationWith\(trackIndex,\s*animation,\s*loop\);",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
string afterSet = setAnimRegex.Replace(updated, _ => setAnimReplacement);
|
||||
if (!string.Equals(afterSet, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterSet;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
const string addAnimReplacement =
|
||||
"var animation = this.data.skeletonData.findAnimation(animationName);\n" +
|
||||
" if (!animation) {\n" +
|
||||
" animation = typeof __glResolveSpineAnim === \"function\" ? __glResolveSpineAnim(this, trackIndex, animationName) : null;\n" +
|
||||
" if (!animation) {\n" +
|
||||
" if (typeof console !== \"undefined\" && console.warn) { console.warn(\"[GameLauncher SpineFix] Animation not found, using empty:\", animationName, \"track:\", trackIndex); }\n" +
|
||||
" return typeof this.addEmptyAnimation === \"function\" ? this.addEmptyAnimation(trackIndex, 0, delay) : null;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" return this.addAnimationWith(trackIndex, animation, loop, delay);";
|
||||
|
||||
var addAnimRegex = new Regex(
|
||||
@"(?:var|let|const)\s+animation\s*=\s*this\.data\.skeletonData\.findAnimation\(animationName\);\s*if\s*\(\s*(?:animation\s*==\s*null|!animation)\s*\)\s*\{?\s*throw\s+new\s+Error\([""']Animation not found:\s*[""']\s*\+\s*animationName\);\s*\}?\s*return\s+this\.addAnimationWith\(trackIndex,\s*animation,\s*loop,\s*delay\);",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
string afterAdd = addAnimRegex.Replace(updated, _ => addAnimReplacement);
|
||||
if (!string.Equals(afterAdd, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterAdd;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
const string setMixReplacement =
|
||||
"var from = this.skeletonData.findAnimation(fromName);\n" +
|
||||
" if (!from) return;\n" +
|
||||
" var to = this.skeletonData.findAnimation(toName);\n" +
|
||||
" if (!to) return;\n" +
|
||||
" this.setMixWith(from, to, duration);";
|
||||
|
||||
var setMixRegex = new Regex(
|
||||
@"(?:var|let|const)\s+from\s*=\s*this\.skeletonData\.findAnimation\(fromName\);\s*if\s*\(\s*(?:from\s*==\s*null|!from)\s*\)\s*\{?\s*throw\s+new\s+Error\([""']Animation not found:\s*[""']\s*\+\s*fromName\);\s*\}?\s*(?:var|let|const)\s+to\s*=\s*this\.skeletonData\.findAnimation\(toName\);\s*if\s*\(\s*(?:to\s*==\s*null|!to)\s*\)\s*\{?\s*throw\s+new\s+Error\([""']Animation not found:\s*[""']\s*\+\s*toName\);\s*\}?\s*this\.setMixWith\(from,\s*to,\s*duration\);",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
string afterMix = setMixRegex.Replace(updated, _ => setMixReplacement);
|
||||
if (!string.Equals(afterMix, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterMix;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!modified)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var bakPath = path + BackupSuffix;
|
||||
if (!File.Exists(bakPath))
|
||||
{
|
||||
File.Copy(path, bakPath, true);
|
||||
}
|
||||
|
||||
const string helperBlock =
|
||||
SpineFixMarker + "\n" +
|
||||
"function __glResolveSpineAnim(state, trackIndex, animationName) {\n" +
|
||||
" try {\n" +
|
||||
" var sd = state && state.data && state.data.skeletonData;\n" +
|
||||
" var anims = sd && sd.animations;\n" +
|
||||
" if (!Array.isArray(anims) || anims.length === 0) return null;\n" +
|
||||
" var req = String(animationName == null ? \"\" : animationName);\n" +
|
||||
" var alt = req.indexOf(\"chimpo\") >= 0 ? req.replace(/chimpo/g, \"chinpo\") : (req.indexOf(\"chinpo\") >= 0 ? req.replace(/chinpo/g, \"chimpo\") : \"\");\n" +
|
||||
" var find = function (fn) {\n" +
|
||||
" for (var i = 0; i < anims.length; i++) {\n" +
|
||||
" if (anims[i] && fn(anims[i])) return anims[i];\n" +
|
||||
" }\n" +
|
||||
" return null;\n" +
|
||||
" };\n" +
|
||||
" var found = find(function (a) { return a.name === req || (alt && a.name === alt); })\n" +
|
||||
" || find(function (a) { return typeof a.name === \"string\" && (a.name.endsWith(\"/\" + req) || (alt && a.name.endsWith(\"/\" + alt))); });\n" +
|
||||
" if (found) return found;\n" +
|
||||
" var isMainTrack = Number(trackIndex) === 0 || /idle/i.test(req);\n" +
|
||||
" if (isMainTrack) {\n" +
|
||||
" found = find(function (a) { return /(?:^|\\/)0_idle$/i.test(a.name); })\n" +
|
||||
" || find(function (a) { return /(?:^|\\/)idle$/i.test(a.name); })\n" +
|
||||
" || find(function (a) { return /idle/i.test(a.name); })\n" +
|
||||
" || find(function (a) { return /^(?:0\\/|0_move\\/|0_)/i.test(a.name); });\n" +
|
||||
" if (found) return found;\n" +
|
||||
" }\n" +
|
||||
" if (Number(trackIndex) === 1 || /^1_face/i.test(req)) {\n" +
|
||||
" found = find(function (a) { return /(?:^|\\/)1_face_normal$/i.test(a.name); })\n" +
|
||||
" || find(function (a) { return /(?:^|\\/)1_face_/i.test(a.name); });\n" +
|
||||
" if (found) return found;\n" +
|
||||
" }\n" +
|
||||
" found = find(function (a) { return a.name === \"none\"; });\n" +
|
||||
" if (found) return found;\n" +
|
||||
" if (Number(trackIndex) === 0) return anims[0];\n" +
|
||||
" } catch (e) {}\n" +
|
||||
" return null;\n" +
|
||||
"}\n";
|
||||
|
||||
string newline = content.Contains("\r\n") ? "\r\n" : "\n";
|
||||
string normalizedHelper = helperBlock.Replace("\n", newline);
|
||||
updated = normalizedHelper + updated;
|
||||
|
||||
File.WriteAllText(path, updated, new UTF8Encoding(true));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool PatchPictureSpineJs(string path)
|
||||
{
|
||||
string content = File.ReadAllText(path, Encoding.UTF8);
|
||||
if (content.Contains(SpineFixMarker))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string updated = content;
|
||||
bool modified = false;
|
||||
|
||||
// 1. Game_Spine.setAnimation: velo_damage状態で通常立ち絵系アニメが指定された場合のスケルトン自動復旧
|
||||
var setAnimRegex = new Regex(
|
||||
@"setAnimation\s*\(\s*id\s*,\s*animations\s*,\s*\.\.\.args\s*\)\s*\{\s*\[id,\s*animations,\s*args\]\s*=\s*convars\(\s*\[id,\s*animations,\s*args\]\s*\);",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
const string setAnimReplacement =
|
||||
"setAnimation(id, animations, ...args) {\n" +
|
||||
" " + SpineFixMarker + "\n" +
|
||||
" [id, animations, args] = convars([id, animations, args]);\n" +
|
||||
" if (Number(id) === 0 && typeof this._skeleton === 'string' && /^velo_damage_\\d+$/.test(this._skeleton)) {\n" +
|
||||
" let _firstAnim = Array.isArray(animations) ? animations[0] : animations;\n" +
|
||||
" let _animBase = typeof _firstAnim === 'string' ? _firstAnim.split(/\\s*\\/\\s*/)[0].trim() : '';\n" +
|
||||
" if (/^0_(?:idle|low|yoin|shy|talk|bind)/i.test(_animBase)) {\n" +
|
||||
" let _targetSkel = (typeof $gameParty !== 'undefined' && $gameParty && $gameParty.members && $gameParty.members()[0] && $gameParty.members()[0].hp === 0) ? 'velo_hunou' : 'velo_normal';\n" +
|
||||
" if (typeof Game_Spine !== 'undefined' && Game_Spine.fullName && Game_Spine.fullName(_targetSkel)) {\n" +
|
||||
" this._skeleton = _targetSkel + '_' + Date.now();\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }";
|
||||
|
||||
string afterSetAnim = setAnimRegex.Replace(updated, _ => setAnimReplacement);
|
||||
if (!string.Equals(afterSetAnim, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterSetAnim;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// 1.5. Sprite_Spine.updateSkeleton: スケルトン切り替え破棄前に未発火のswitchイベントを完了させ、イベントループ停止を防止
|
||||
var updateSkelRegex = new Regex(
|
||||
@"updateSkeleton\s*\(\s*spine\s*\)\s*\{\s*if\s*\(\s*spine\s*\)\s*\{\s*if\s*\(\s*spine\.skeleton\s*!=\s*this\._skeleton\s*\)\s*\{\s*this\.init\(\s*\);",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
const string updateSkelReplacement =
|
||||
"updateSkeleton(spine) {\n" +
|
||||
" if (spine) {\n" +
|
||||
" if (spine.skeleton != this._skeleton) {\n" +
|
||||
" try {\n" +
|
||||
" if (this._data && this._data.state && Array.isArray(this._data.state.tracks) && typeof $gameSwitches !== 'undefined') {\n" +
|
||||
" for (let _glEntry of this._data.state.tracks) {\n" +
|
||||
" if (!_glEntry || !_glEntry.animation || !Array.isArray(_glEntry.animation.timelines)) continue;\n" +
|
||||
" for (let _glTl of _glEntry.animation.timelines) {\n" +
|
||||
" if (!_glTl || !Array.isArray(_glTl.events) || !_glTl.frames || typeof _glTl.frames.length !== 'number') continue;\n" +
|
||||
" for (let _glIdx = 0; _glIdx < _glTl.events.length; _glIdx++) {\n" +
|
||||
" if (_glTl.frames[_glIdx] < _glEntry.trackTime) continue;\n" +
|
||||
" let _glEv = _glTl.events[_glIdx];\n" +
|
||||
" let _glStr = _glEv && _glEv.stringValue;\n" +
|
||||
" if (!_glStr) continue;\n" +
|
||||
" for (let _glTok of String(_glStr).replace(/ +/, '').split(/,/)) {\n" +
|
||||
" if (_glTok.match(/^([!~]?)switch:(\\d+)$/i)) {\n" +
|
||||
" let _glType = RegExp.$1.replace('!', 'off').replace('~', 'reverse') || 'on';\n" +
|
||||
" let _glSwId = Number(RegExp.$2);\n" +
|
||||
" let _glVal = _glType == 'on' ? true : _glType == 'off' ? false : !$gameSwitches.value(_glSwId);\n" +
|
||||
" $gameSwitches.setValue(_glSwId, _glVal);\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" } catch (_glErr) {}\n" +
|
||||
" this.init();";
|
||||
|
||||
string afterUpdateSkel = updateSkelRegex.Replace(updated, _ => updateSkelReplacement);
|
||||
if (!string.Equals(afterUpdateSkel, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterUpdateSkel;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// 2. updateSkin: findSkin null安全化
|
||||
var skinRegex = new Regex(
|
||||
@"skin\.addSkin\(\s*this\._data\.skeleton\.data\.findSkin\(\s*name\s*\)\s*\);",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
const string skinReplacement =
|
||||
"let _glSkin = this._data.skeleton.data.findSkin(name);\n" +
|
||||
" if (_glSkin) skin.addSkin(_glSkin);";
|
||||
|
||||
string afterSkin = skinRegex.Replace(updated, _ => skinReplacement);
|
||||
if (!string.Equals(afterSkin, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterSkin;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// 3. updateAnimation: entry null安全化
|
||||
var entryRegex = new Regex(
|
||||
@"entry\.timeScale\s*=\s*animation\.timeScale;\s*entry\.alpha\s*=\s*animation\.alpha;\s*entry\.plainAlpha\s*=\s*animation\.alpha;\s*spine\.setPlayData\(\s*entry\s*\);",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
const string entryReplacement =
|
||||
"if (entry) {\n" +
|
||||
" entry.timeScale = animation.timeScale;\n" +
|
||||
" entry.alpha = animation.alpha;\n" +
|
||||
" entry.plainAlpha = animation.alpha;\n" +
|
||||
" spine.setPlayData(entry);\n" +
|
||||
" }";
|
||||
|
||||
string afterEntry = entryRegex.Replace(updated, _ => entryReplacement);
|
||||
if (!string.Equals(afterEntry, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterEntry;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// 4. restoreAnimation: animations.find(...).duration および entry の null安全化
|
||||
var restoreRegex = new Regex(
|
||||
@"data\.trackTime\s*%=\s*this\._data\.spineData\.animations\.find\(\s*animation\s*=>\s*animation\.name\s*==\s*data\.name\s*\)\.duration;",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
const string restoreReplacement =
|
||||
"let _glAnim = this._data.spineData.animations.find(animation => animation.name == data.name);\n" +
|
||||
" data.trackTime = (_glAnim && _glAnim.duration) ? (data.trackTime % _glAnim.duration) : 0;";
|
||||
|
||||
string afterRestore = restoreRegex.Replace(updated, _ => restoreReplacement);
|
||||
if (!string.Equals(afterRestore, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterRestore;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
var restoreEntryRegex = new Regex(
|
||||
@"(entry\s*=\s*this\._data\.state\.(?:setAnimation|addAnimation)\([^;]+\);)\s*(entry\.alpha\s*=)",
|
||||
RegexOptions.Singleline);
|
||||
|
||||
string afterRestoreEntry = restoreEntryRegex.Replace(updated, "$1\n if (!entry) break;\n $2");
|
||||
if (!string.Equals(afterRestoreEntry, updated, StringComparison.Ordinal))
|
||||
{
|
||||
updated = afterRestoreEntry;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!modified)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var bakPath = path + BackupSuffix;
|
||||
if (!File.Exists(bakPath))
|
||||
{
|
||||
File.Copy(path, bakPath, true);
|
||||
}
|
||||
|
||||
File.WriteAllText(path, updated, new UTF8Encoding(true));
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user