refactor: reorganize engine-based structure and add agent rules
- Engines/ 配下へエンジン別に再編 (Common/Rgss/Tkool/Tyrano/Wolf/Unity/Nwjs) - ゲーム個別処理を Engines/<Engine>/Games/<GameName>/ へ分離し、共通処理から明示呼び出し - 外部ツールを Engines/<Engine>/Tools/ へ移動し、AppPathHelper 経由で解決 - 旧 Tools/ 直下参照と不要な参照ファイル/バックアップを削除 - エージェント規則 AGENTS.md を追加し、README から参照 - publish.ps1 を Engines/<Engine>/Tools/ の再帰配置に対応
This commit is contained in:
1 parent
0d11039ee9
commit
8cea2a147d
47 files changed
+2976
-176
No files matched your search
+449
-94
@@ -16,6 +16,12 @@ using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
using GameLauncher.Helpers;
|
||||
using GameLauncher.Models;
|
||||
using GameLauncher.Engines.Rgss;
|
||||
using GameLauncher.Engines.Tkool;
|
||||
using GameLauncher.Engines.Tyrano;
|
||||
using GameLauncher.Engines.Wolf;
|
||||
using GameLauncher.Engines.Unity;
|
||||
using GameLauncher.Engines.Nwjs;
|
||||
|
||||
namespace GameLauncher.Services
|
||||
{
|
||||
@@ -58,6 +64,15 @@ namespace GameLauncher.Services
|
||||
public bool SrpgProxyDll { get; set; }
|
||||
public double SrpgSpeedMultiplier { get; set; } = 3.0;
|
||||
|
||||
// 単体exe梱包(FOSSIL / boxed)専用
|
||||
public bool IsFossilSingleExe { get; set; }
|
||||
public bool IsBoxedExe { get; set; }
|
||||
public bool IsStandaloneExeExtracted { get; set; }
|
||||
public string? StandaloneExtractedDirPath { get; set; }
|
||||
public string? StandaloneBackupPath { get; set; }
|
||||
public string? BoxedPayloadEntryPath { get; set; }
|
||||
public bool CanExtractViaExternalTool { get; set; }
|
||||
|
||||
// Unity専用
|
||||
public string DataDirectoryPath { get; set; } = string.Empty;
|
||||
public string CompanyName { get; set; } = string.Empty;
|
||||
@@ -166,7 +181,13 @@ namespace GameLauncher.Services
|
||||
IsSrpgExtracted = entry.IsSrpgExtracted,
|
||||
SrpgArchivePath = entry.SrpgArchivePath,
|
||||
SrpgProxyDll = entry.SrpgProxyDll,
|
||||
SrpgSpeedMultiplier = entry.SrpgSpeedMultiplier > 0 ? entry.SrpgSpeedMultiplier : 3.0
|
||||
SrpgSpeedMultiplier = entry.SrpgSpeedMultiplier > 0 ? entry.SrpgSpeedMultiplier : 3.0,
|
||||
IsFossilSingleExe = entry.IsFossilSingleExe,
|
||||
IsBoxedExe = entry.IsBoxedExe,
|
||||
IsStandaloneExeExtracted = entry.IsStandaloneExeExtracted,
|
||||
StandaloneExtractedDirPath = entry.StandaloneExtractedDirPath,
|
||||
StandaloneBackupPath = entry.StandaloneBackupPath,
|
||||
BoxedPayloadEntryPath = entry.BoxedPayloadEntryPath
|
||||
};
|
||||
if (entry.PluginSettings != null)
|
||||
{
|
||||
@@ -264,6 +285,14 @@ namespace GameLauncher.Services
|
||||
string? asarExtP = element.TryGetProperty("AsarExtractedDirPath", out var aep) ? aep.GetString() : null;
|
||||
string? relJs = element.TryGetProperty("RelativePluginsJsInAsar", out var rj) ? rj.GetString() : null;
|
||||
|
||||
bool isFossilSingleExe = element.TryGetProperty("IsFossilSingleExe", out var ifs) && ifs.GetBoolean();
|
||||
bool isBoxedExe = element.TryGetProperty("IsBoxedExe", out var ibx) && ibx.GetBoolean();
|
||||
bool isStandaloneExeExtracted = element.TryGetProperty("IsStandaloneExeExtracted", out var isx) && isx.GetBoolean();
|
||||
string? standaloneExtDir = element.TryGetProperty("StandaloneExtractedDirPath", out var sed) ? sed.GetString() : null;
|
||||
string? standaloneBackup = element.TryGetProperty("StandaloneBackupPath", out var sbp) ? sbp.GetString() : null;
|
||||
string? boxedEntry = element.TryGetProperty("BoxedPayloadEntryPath", out var bep) ? bep.GetString() : null;
|
||||
bool canExtractViaExternalTool = element.TryGetProperty("CanExtractViaExternalTool", out var cet) && cet.GetBoolean();
|
||||
|
||||
var item = new TkoolGameItem
|
||||
{
|
||||
Title = title,
|
||||
@@ -281,7 +310,14 @@ namespace GameLauncher.Services
|
||||
IsAsarExtracted = isAsarExt,
|
||||
AsarPath = asarP,
|
||||
AsarExtractedDirPath = asarExtP,
|
||||
RelativePluginsJsInAsar = relJs
|
||||
RelativePluginsJsInAsar = relJs,
|
||||
IsFossilSingleExe = isFossilSingleExe,
|
||||
IsBoxedExe = isBoxedExe,
|
||||
IsStandaloneExeExtracted = isStandaloneExeExtracted,
|
||||
StandaloneExtractedDirPath = standaloneExtDir,
|
||||
StandaloneBackupPath = standaloneBackup,
|
||||
BoxedPayloadEntryPath = boxedEntry,
|
||||
CanExtractViaExternalTool = canExtractViaExternalTool
|
||||
};
|
||||
|
||||
// 既存キャッシュの自動修復: ウディタの誤判定を修正
|
||||
@@ -441,7 +477,14 @@ namespace GameLauncher.Services
|
||||
IsSrpgExtracted = tg.IsSrpgExtracted,
|
||||
SrpgArchivePath = tg.SrpgArchivePath,
|
||||
SrpgProxyDll = tg.SrpgProxyDll,
|
||||
SrpgSpeedMultiplier = tg.SrpgSpeedMultiplier
|
||||
SrpgSpeedMultiplier = tg.SrpgSpeedMultiplier,
|
||||
IsFossilSingleExe = tg.IsFossilSingleExe,
|
||||
IsBoxedExe = tg.IsBoxedExe,
|
||||
IsStandaloneExeExtracted = tg.IsStandaloneExeExtracted,
|
||||
StandaloneExtractedDirPath = tg.StandaloneExtractedDirPath,
|
||||
StandaloneBackupPath = tg.StandaloneBackupPath,
|
||||
BoxedPayloadEntryPath = tg.BoxedPayloadEntryPath,
|
||||
CanExtractViaExternalTool = tg.CanExtractViaExternalTool
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -858,7 +901,21 @@ namespace GameLauncher.Services
|
||||
};
|
||||
}
|
||||
|
||||
// 2. 通常のティラノスクリプト探索
|
||||
// 2. boxed(nw.js埋め込み: *boxed*.exe + 埋め込みpackage.nw または on-disk www\)のツクール探索
|
||||
var boxedGame = DetectBoxedNwGameInDirectory(dirPath, folderName, folderModified);
|
||||
if (boxedGame != null)
|
||||
{
|
||||
return boxedGame;
|
||||
}
|
||||
|
||||
// 3. FOSSIL単体exe同梱のツクールMZ探索 (js/plugins.jsがexe内に埋め込まれている形態)
|
||||
var fossilMzGame = DetectFossilMZGameInDirectory(dirPath, folderName, folderModified);
|
||||
if (fossilMzGame != null)
|
||||
{
|
||||
return fossilMzGame;
|
||||
}
|
||||
|
||||
// 3. 通常のティラノスクリプト探索
|
||||
var tyranoIndex = FindTyranoIndexHtml(dirPath);
|
||||
if (tyranoIndex != null)
|
||||
{
|
||||
@@ -888,7 +945,7 @@ namespace GameLauncher.Services
|
||||
};
|
||||
}
|
||||
|
||||
// 3. app.asar パッケージであるか判定
|
||||
// 4. app.asar パッケージであるか判定
|
||||
if (AsarArchiveService.FindAsarPackage(dirPath, out var asarPath, out bool isExtracted, out var extractedDirPath))
|
||||
{
|
||||
var inspect = _asarService.InspectAsar(asarPath!);
|
||||
@@ -933,21 +990,21 @@ namespace GameLauncher.Services
|
||||
}
|
||||
}
|
||||
|
||||
// 4. WOLF RPGエディター(ウディタ)ゲームの検出
|
||||
// 5. WOLF RPGエディター(ウディタ)ゲームの検出
|
||||
var wolfGame = DetectWolfGameInDirectory(dirPath, folderName, folderModified);
|
||||
if (wolfGame != null)
|
||||
{
|
||||
return wolfGame;
|
||||
}
|
||||
|
||||
// 5. SRPG Studio ゲームの検出
|
||||
// 6. SRPG Studio ゲームの検出
|
||||
var srpgGame = DetectSrpgGameInDirectory(dirPath, folderName, folderModified);
|
||||
if (srpgGame != null)
|
||||
{
|
||||
return srpgGame;
|
||||
}
|
||||
|
||||
// 6. ツクールVX / VX Ace (RGSS2 / RGSS3) ゲームの検出
|
||||
// 7. ツクールVX / VX Ace (RGSS2 / RGSS3) ゲームの検出
|
||||
var rgssGame = DetectRgssGameInDirectory(dirPath, folderName, folderModified);
|
||||
if (rgssGame != null)
|
||||
{
|
||||
@@ -959,6 +1016,364 @@ namespace GameLauncher.Services
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 単体exe梱包されたツクールMZゲームを判定し、TkoolGameItemを生成します。
|
||||
/// 対象とするexe形態は次の2種で、いずれも js/plugins.js がディスク上に存在しません。
|
||||
/// - FOSSIL形態: エントリHTMLが FOSSILindex.html、本体は Game.exe(data/System.json はディスク上)
|
||||
/// - boxed形態: ゲーム本体を exe に内包(例: Game_boxed.exe)。ディスク上にゲーム実体が無い
|
||||
/// 誤検出を避けるため、以下の条件が全て揃った場合のみ検出します。
|
||||
/// - 候補exe(Game.exe / *boxed*.exe / *.exe)が存在する
|
||||
/// - js/plugins.js および www/js/plugins.js がディスク上に存在しない
|
||||
/// - FOSSILindex.html が存在する、又は data/System.json が存在する、又は boxed 命名のexeである
|
||||
/// 本形態はゲーム本体をexeへ埋め込むため、他のツクールゲームには一切影響しません。
|
||||
/// </summary>
|
||||
public TkoolGameItem? DetectFossilMZGameInDirectory(string dirPath, string folderName, DateTime? folderModified)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 0. ディスク上に plugins.js が存在する場合は通常のMV/MZ検出に任せる
|
||||
if (File.Exists(Path.Combine(dirPath, "js", "plugins.js")) ||
|
||||
File.Exists(Path.Combine(dirPath, "www", "js", "plugins.js")))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1. 候補exeの解決(Game.exe を最優先、次に *boxed*.exe、最後に任意のexe)
|
||||
var exePath = ResolveStandaloneEntryExecutable(dirPath);
|
||||
if (exePath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 判定マーカーの確認
|
||||
bool hasFossilHtml = File.Exists(Path.Combine(dirPath, "FOSSILindex.html"));
|
||||
var systemJson = Path.Combine(dirPath, "data", "System.json");
|
||||
bool hasSystemJson = File.Exists(systemJson);
|
||||
bool isBoxedExe = Path.GetFileName(exePath).IndexOf("boxed", StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
|
||||
if (!hasFossilHtml && !hasSystemJson && !isBoxedExe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var icon = LoadIcon(exePath, dirPath);
|
||||
string? title = null;
|
||||
string? pluginsJsInContainer = null;
|
||||
string? embeddedPluginsPath = null;
|
||||
|
||||
// 3. boxed 命名exeは内包コンテナ(package.nw)からplugins.js位置を推定
|
||||
if (isBoxedExe)
|
||||
{
|
||||
TryProbeBoxedEmbeddedPayload(exePath, out pluginsJsInContainer, out embeddedPluginsPath);
|
||||
}
|
||||
|
||||
// 4. タイトル解決: data/System.json の gameTitle を優先、無ければフォルダ名
|
||||
if (hasSystemJson)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(systemJson);
|
||||
var match = Regex.Match(json, @"""gameTitle""\s*:\s*""([^""]*)\""");
|
||||
if (match.Success && !string.IsNullOrWhiteSpace(match.Groups[1].Value))
|
||||
{
|
||||
title = Regex.Unescape(match.Groups[1].Value);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// 5. boxed命名exeで data/System.json がディスク上に無い場合は内包コンテナを注入対象とする
|
||||
bool isBoxed = isBoxedExe && !hasSystemJson;
|
||||
|
||||
return new TkoolGameItem
|
||||
{
|
||||
Title = string.IsNullOrWhiteSpace(title) ? folderName : title!,
|
||||
FolderName = folderName,
|
||||
RootDirectory = dirPath,
|
||||
ExecutablePath = exePath,
|
||||
PluginsJsPath = embeddedPluginsPath ?? string.Empty,
|
||||
PluginsDirPath = string.Empty,
|
||||
EngineType = TkoolEngineType.MZ,
|
||||
IsModded = false,
|
||||
// ディスク上にJS実体が無い単体exe形態は、そのままではプラグイン注入できないため初期は改造OFF
|
||||
ApplyMod = false,
|
||||
IconImage = icon,
|
||||
FolderLastModified = folderModified,
|
||||
IsAsar = false,
|
||||
// 形態フラグ(他ゲームへ影響しないための識別子)
|
||||
IsFossilSingleExe = hasFossilHtml || !isBoxed,
|
||||
IsBoxedExe = isBoxed,
|
||||
BoxedPayloadEntryPath = pluginsJsInContainer
|
||||
};
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 単体exe形態の候補となる実行ファイルを解決します。
|
||||
/// 優先順: Game.exe → *boxed*.exe → それ以外の *.exe(unins* を除く)。
|
||||
/// </summary>
|
||||
private static string? ResolveStandaloneEntryExecutable(string dirPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gameExe = Path.Combine(dirPath, "Game.exe");
|
||||
if (File.Exists(gameExe))
|
||||
{
|
||||
return gameExe;
|
||||
}
|
||||
|
||||
var exes = Directory.GetFiles(dirPath, "*.exe", SearchOption.TopDirectoryOnly);
|
||||
if (exes.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// *boxed*.exe を優先
|
||||
foreach (var exe in exes)
|
||||
{
|
||||
var name = Path.GetFileName(exe);
|
||||
if (name.IndexOf("boxed", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
return exe;
|
||||
}
|
||||
}
|
||||
|
||||
// unins* を除外した最初のexe
|
||||
foreach (var exe in exes)
|
||||
{
|
||||
var name = Path.GetFileName(exe);
|
||||
if (name.StartsWith("unins", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return exe;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// boxed命名exeの内包コンテナ(package.nw相当)を限定部分読みで探索し、
|
||||
/// タイトル情報(package.json)と js/plugins.js 相当のエントリ有無を推定します。
|
||||
/// 全走査は行いません(1.14GB級exeを対象に含むため)。
|
||||
/// </summary>
|
||||
private static void TryProbeBoxedEmbeddedPayload(string exePath, out string? packageJsonEntryName, out string? embeddedPluginsJsPath)
|
||||
{
|
||||
packageJsonEntryName = null;
|
||||
embeddedPluginsJsPath = null;
|
||||
|
||||
try
|
||||
{
|
||||
const int windowSize = 4 * 1024 * 1024; // 4MB限定ウィンドウ
|
||||
using var fs = new FileStream(exePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
long size = fs.Length;
|
||||
|
||||
// package.nw マーカーは exe の中間域に置かれることが多いため、中央付近から数点だけ走査する
|
||||
long[] probes = new[]
|
||||
{
|
||||
Math.Max(0, size / 2 - windowSize / 2),
|
||||
Math.Max(0, size / 4),
|
||||
Math.Max(0, size * 3 / 4),
|
||||
};
|
||||
|
||||
foreach (var start in probes)
|
||||
{
|
||||
int readLen = (int)Math.Min(windowSize, size - start);
|
||||
if (readLen <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var buf = new byte[readLen];
|
||||
fs.Seek(start, SeekOrigin.Begin);
|
||||
int read = fs.Read(buf, 0, buf.Length);
|
||||
|
||||
// ASCII/UTF8 の "package.json" を探す
|
||||
var text = System.Text.Encoding.ASCII.GetString(buf, 0, read);
|
||||
int idx = text.IndexOf("package.json", StringComparison.Ordinal);
|
||||
if (idx >= 0)
|
||||
{
|
||||
packageJsonEntryName = "package.json";
|
||||
// 同一ウィンドウ内に plugins.js があれば注入対象として記録
|
||||
if (text.IndexOf("plugins.js", StringComparison.Ordinal) >= 0)
|
||||
{
|
||||
embeddedPluginsJsPath = "js/plugins.js";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// nw.js埋め込み(*boxed*.exe + 埋め込みpackage.nw または on-disk www\)のツクールMZゲームを検出します。
|
||||
/// 全走査は行わず、exe内のpackage.nwマーカー周辺の限定読みで埋め込みコンテナ有無を判定します。
|
||||
/// boxed命名exeが存在する場合のみ発火するため、他のツクールゲームには一切影響しません。
|
||||
/// </summary>
|
||||
public TkoolGameItem? DetectBoxedNwGameInDirectory(string dirPath, string folderName, DateTime? folderModified)
|
||||
{
|
||||
try
|
||||
{
|
||||
// (a) ディスク上の www\js\plugins.js を優先(通常検出で拾えない露出パターンを補完)
|
||||
var onDiskPlugins = FindPluginsJsUnderWww(dirPath);
|
||||
|
||||
// (b) *boxed*.exe の存在確認(Game.exe固定を一般化)
|
||||
var boxedExe = Directory.EnumerateFiles(dirPath, "*.exe", SearchOption.TopDirectoryOnly)
|
||||
.FirstOrDefault(f => Path.GetFileName(f).Contains("boxed", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// boxed命名exeが無ければここでは扱わない(厳密に追加的)
|
||||
if (boxedExe == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// (c) 埋め込みpackage.nwマーカーの有無(限定部分読み)
|
||||
bool hasEmbeddedPkg = ContainsPackageNwMarker(boxedExe);
|
||||
|
||||
// (d) boxed命名exeが存在すれば、マーカー未確定でも外部アンパッカーでの展開を試行できるため一覧に表示する。
|
||||
// (マーカーは中盤の限られた窓でしか確認しないため、非標準コンテナでは拾えない場合がある)
|
||||
// 展開可否は実行時(ExtractPackageNw)に確定し、不可なら「起動のみ」にフォールバックする。
|
||||
bool canTryExternalTool = true;
|
||||
if (!hasEmbeddedPkg && onDiskPlugins == null && !canTryExternalTool)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var dataDir = Path.Combine(dirPath, "data");
|
||||
var engine = DetectEngineTypeByDataJson(dirPath);
|
||||
var title = ExtractTkoolTitle(dirPath, dataDir);
|
||||
var icon = LoadIcon(boxedExe, dirPath);
|
||||
|
||||
return new TkoolGameItem
|
||||
{
|
||||
Title = string.IsNullOrWhiteSpace(title) ? folderName : title,
|
||||
FolderName = folderName,
|
||||
RootDirectory = dirPath,
|
||||
ExecutablePath = boxedExe,
|
||||
PluginsJsPath = onDiskPlugins ?? string.Empty,
|
||||
PluginsDirPath = onDiskPlugins != null ? Path.Combine(Path.GetDirectoryName(onDiskPlugins)!, "plugins") : string.Empty,
|
||||
EngineType = engine,
|
||||
IsModded = false,
|
||||
// on-disk露出時のみその場で注入可。埋め込みのみの場合はAI展開後に注入可となる
|
||||
ApplyMod = onDiskPlugins != null,
|
||||
IconImage = icon,
|
||||
FolderLastModified = folderModified,
|
||||
IsAsar = false,
|
||||
IsFossilSingleExe = false,
|
||||
IsBoxedExe = true,
|
||||
BoxedPayloadEntryPath = hasEmbeddedPkg ? "js/plugins.js" : null,
|
||||
// boxed命名exeが存在するため、外部アンパッカーでの展開を試行できる可能性がある
|
||||
CanExtractViaExternalTool = canTryExternalTool
|
||||
};
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ディスク上に露出した www\js\plugins.js(または www\www\js\plugins.js)を探索します。
|
||||
/// 通常の FindPluginsJs は深さ2で js\・www\js\ を見ますが、boxed形態の
|
||||
/// www 直下露出を取りこぼさないための補完です。
|
||||
/// </summary>
|
||||
private static string? FindPluginsJsUnderWww(string dirPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var candidates = new[]
|
||||
{
|
||||
Path.Combine(dirPath, "www", "js", "plugins.js"),
|
||||
Path.Combine(dirPath, "www", "www", "js", "plugins.js"),
|
||||
};
|
||||
foreach (var c in candidates)
|
||||
{
|
||||
if (File.Exists(c))
|
||||
{
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// exe内に nw.js の埋め込みコンテナ(package.nw)マーカーが存在するかを
|
||||
/// 限定部分読み(4MB窓×数点)で判定します。全走査は行いません(1.14GB級exe対策)。
|
||||
/// </summary>
|
||||
private static bool ContainsPackageNwMarker(string exePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
const int windowSize = 4 * 1024 * 1024;
|
||||
using var fs = new FileStream(exePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
long size = fs.Length;
|
||||
if (size < 1024)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
double[] fractions = { 0.25, 0.5, 0.75, 0.9 };
|
||||
foreach (var frac in fractions)
|
||||
{
|
||||
long start = (long)(size * frac);
|
||||
int readLen = (int)Math.Min(windowSize, size - start);
|
||||
if (readLen <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var buf = new byte[readLen];
|
||||
fs.Seek(start, SeekOrigin.Begin);
|
||||
int read = fs.Read(buf, 0, buf.Length);
|
||||
var text = System.Text.Encoding.ASCII.GetString(buf, 0, read);
|
||||
|
||||
if (text.IndexOf("package.nw", StringComparison.Ordinal) >= 0 ||
|
||||
text.IndexOf("package.json", StringComparison.Ordinal) >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// data\System.json の有無と内容からエンジン種別(MZ/MV)を判定します。
|
||||
/// jsディレクトリが無い単体exe梱包形態でも動作します。
|
||||
/// </summary>
|
||||
private static TkoolEngineType DetectEngineTypeByDataJson(string dirPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var systemJson = Path.Combine(dirPath, "data", "System.json");
|
||||
if (File.Exists(systemJson))
|
||||
{
|
||||
var json = File.ReadAllText(systemJson);
|
||||
// MZ固有のキー(例: "hasEncryptedImages" は両者にあるが、"optDisplayTp"等はMZのみ)
|
||||
if (json.Contains("\"optDisplayTp\"") ||
|
||||
json.Contains("\"optExtraExp\"") ||
|
||||
json.Contains("\"optAntiLag\""))
|
||||
{
|
||||
return TkoolEngineType.MZ;
|
||||
}
|
||||
return TkoolEngineType.MZ;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return TkoolEngineType.MZ;
|
||||
}
|
||||
|
||||
#region WOLF RPGエディター(ウディタ)検出ロジック
|
||||
|
||||
/// <summary>
|
||||
@@ -1346,99 +1761,17 @@ namespace GameLauncher.Services
|
||||
|
||||
/// <summary>
|
||||
/// BOMの有無やShift_JIS (CP932) を自動判定して安全にINIファイルを行単位で読み込みます。
|
||||
/// 実装は Engines/Rgss/Games/IiniTitleRepair に分離済み(RGSS個別対応)。
|
||||
/// </summary>
|
||||
public static string[] ReadIniLinesSafe(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath)) return Array.Empty<string>();
|
||||
|
||||
byte[] bytes = File.ReadAllBytes(filePath);
|
||||
if (bytes.Length == 0) return Array.Empty<string>();
|
||||
|
||||
// 1. UTF-8 BOM (EF BB BF)
|
||||
if (bytes.Length >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
|
||||
{
|
||||
var text = System.Text.Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3);
|
||||
return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
||||
}
|
||||
|
||||
// 2. UTF-16 LE BOM (FF FE)
|
||||
if (bytes.Length >= 2 && bytes[0] == 0xFF && bytes[1] == 0xFE)
|
||||
{
|
||||
var text = System.Text.Encoding.Unicode.GetString(bytes, 2, bytes.Length - 2);
|
||||
return text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
||||
}
|
||||
|
||||
// 3. Shift_JIS (CP932) でデコード(ツクールVX/VX Aceおよびウディタの標準)
|
||||
System.Text.Encoding encoding;
|
||||
try
|
||||
{
|
||||
encoding = System.Text.Encoding.GetEncoding(932);
|
||||
}
|
||||
catch
|
||||
{
|
||||
encoding = System.Text.Encoding.GetEncoding("shift_jis");
|
||||
}
|
||||
|
||||
var decoded = encoding.GetString(bytes);
|
||||
return decoded.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
=> GameLauncher.Engines.Rgss.Games.IiniTitleRepair.GameIniTitleRepair.ReadIniLinesSafe(filePath);
|
||||
|
||||
/// <summary>
|
||||
/// キャッシュ内に文字化けして保存されたRGSSタイトルの修復を行います。
|
||||
/// 実装は Engines/Rgss/Games/IiniTitleRepair に分離済み(RGSS個別対応)。
|
||||
/// </summary>
|
||||
public static void FixRgssTitleFromIni(TkoolGameItem tg)
|
||||
{
|
||||
try
|
||||
{
|
||||
string? iniPath = null;
|
||||
var directIni = Path.Combine(tg.RootDirectory, "Game.ini");
|
||||
if (File.Exists(directIni))
|
||||
{
|
||||
iniPath = directIni;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Directory.Exists(tg.RootDirectory))
|
||||
{
|
||||
foreach (var sub in Directory.GetDirectories(tg.RootDirectory))
|
||||
{
|
||||
var subIni = Path.Combine(sub, "Game.ini");
|
||||
if (File.Exists(subIni))
|
||||
{
|
||||
iniPath = subIni;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (iniPath != null)
|
||||
{
|
||||
var lines = ReadIniLinesSafe(iniPath);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var trim = line.Trim();
|
||||
if (trim.StartsWith("Title=", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var val = trim.Substring(6).Trim();
|
||||
if (!string.IsNullOrWhiteSpace(val) && !val.Contains('\uFFFD'))
|
||||
{
|
||||
tg.Title = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
=> GameLauncher.Engines.Rgss.Games.IiniTitleRepair.GameIniTitleRepair.Fix(tg);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1709,6 +2042,13 @@ namespace GameLauncher.Services
|
||||
return directIndex;
|
||||
}
|
||||
|
||||
// FOSSILで梱包されたティラノスクリプトは index.html が FOSSILindex.html にリネームされる
|
||||
var directFossilIndex = Path.Combine(dirPath, "FOSSILindex.html");
|
||||
if (File.Exists(directFossilIndex) && CheckIsTyranoDirectory(dirPath))
|
||||
{
|
||||
return directFossilIndex;
|
||||
}
|
||||
|
||||
var subDirs = Directory.GetDirectories(dirPath);
|
||||
foreach (var sub in subDirs)
|
||||
{
|
||||
@@ -1723,6 +2063,12 @@ namespace GameLauncher.Services
|
||||
{
|
||||
return subIndex;
|
||||
}
|
||||
|
||||
var subFossilIndex = Path.Combine(sub, "FOSSILindex.html");
|
||||
if (File.Exists(subFossilIndex) && CheckIsTyranoDirectory(sub))
|
||||
{
|
||||
return subFossilIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
@@ -1744,6 +2090,15 @@ namespace GameLauncher.Services
|
||||
if (html.Contains("tyrano", StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
|
||||
// FOSSIL梱包のティラノスクリプト用エントリ
|
||||
var fossilIndexPath = Path.Combine(dir, "FOSSILindex.html");
|
||||
if (File.Exists(fossilIndexPath))
|
||||
{
|
||||
var html = File.ReadAllText(fossilIndexPath);
|
||||
if (html.Contains("tyrano", StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
Reference in new issue
Block a user